-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aarat Nathwani
committed
Nov 14, 2019
1 parent
c0d51ee
commit 01fe4ed
Showing
13 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: Build & Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
jobs: | ||
create_release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1.0.0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release v${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Save Upload URL | ||
shell: bash | ||
run: | | ||
echo "${{ steps.create_release.outputs.upload_url }}" > upload-url.txt | ||
- name: Upload | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: uploadurl | ||
path: upload-url.txt | ||
|
||
build_release_osx: | ||
needs: create_release | ||
runs-on: macOS-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.7] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Build App | ||
run: | | ||
make build | ||
- name: Download Upload URL | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: uploadurl | ||
- name: Extract Upload URL | ||
shell: bash | ||
run: | | ||
echo "##[set-output name=upload_url;] $(cat uploadurl/upload-url.txt)" | ||
id: extract_upload_url | ||
|
||
- name: Upload Release Asset - OSx | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1.0.1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.extract_upload_url.outputs.upload_url }} | ||
asset_path: dist/terraenv | ||
asset_name: terraenv_osx | ||
asset_content_type: application/octet-stream | ||
|
||
build_release_linux: | ||
needs: create_release | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.7] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Build App | ||
run: | | ||
make build | ||
- name: Download Upload URL | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: uploadurl | ||
- name: Extract Upload URL | ||
shell: bash | ||
run: | | ||
echo "##[set-output name=upload_url;] $(cat uploadurl/upload-url.txt)" | ||
id: extract_upload_url | ||
|
||
- name: Upload Release Asset - Linux | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1.0.1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.extract_upload_url.outputs.upload_url }} | ||
asset_path: dist/terraenv | ||
asset_name: terraenv_linux | ||
asset_content_type: application/octet-stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.DS_Store | ||
virtualenv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class TerraEnv < Formula | ||
TERRAENV_VERSION = "0.1.0".freeze | ||
|
||
desc "Installs TerraEnv from github" | ||
homepage "https://vaultproject.io/downloads.html" | ||
url "https://releases.hashicorp.com/vault/#{TERRAENV_VERSION}/vault_#{TERRAENV_VERSION}_darwin_amd64.zip" | ||
version TERRAENV_VERSION | ||
sha256 '0dcc8f5ad55be2a1d485a165f97d7f01a20f95950e32d25a2818ff62328f2f52' | ||
|
||
def install | ||
bin.install 'TerraEnv' | ||
end | ||
|
||
test do | ||
system "#{bin}/terraenv" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build: | ||
@PYTHONOPTIMIZE=1 pyinstaller terraenv.py --onefile --clean --osx-bundle-identifier com.aarat.os.terraenv --nowindowed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# terraenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .list import list_local, list_remote | ||
from .install import install | ||
from .uninstall import uninstall | ||
from .use import use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os.path | ||
import os | ||
from dotenv import load_dotenv | ||
import sys | ||
import platform | ||
import requests | ||
from zipfile import ZipFile | ||
from config import DOWNLOAD_PATH, VERSION_FILE | ||
|
||
""" Download Required Terraform / Terragrunt Versions """ | ||
|
||
|
||
def download_program(program, version): | ||
|
||
operating_sys = sys.platform | ||
|
||
# Upsert download path | ||
not os.path.exists(DOWNLOAD_PATH) and os.mkdir(DOWNLOAD_PATH) | ||
|
||
if program == "terraform": | ||
url = "https://releases.hashicorp.com" + "/terraform/" + version + \ | ||
"/terraform_" + version + "_" + operating_sys + "_amd64.zip" | ||
|
||
elif program == "terragrunt": | ||
url = "https://github.com/gruntwork-io/terragrunt/releases/download/v" + \ | ||
version + "/terragrunt_" + operating_sys + "_amd64" | ||
|
||
if not os.path.exists(DOWNLOAD_PATH + program + "_" + version): | ||
|
||
print("Downloading", program, version, "from", url) | ||
|
||
binary = requests.get(url) | ||
|
||
if binary.status_code == 404: | ||
raise Exception("Invalid version, got 404 error !") | ||
|
||
dest_path = DOWNLOAD_PATH + program + "_" + version | ||
|
||
open(dest_path, 'wb').write(binary.content) | ||
|
||
if program == "terraform": | ||
|
||
with ZipFile(dest_path, 'r') as zip: | ||
zip.extract('terraform', path=DOWNLOAD_PATH) | ||
|
||
if os.path.exists(DOWNLOAD_PATH + '/' + program) and os.path.exists(dest_path): | ||
os.remove(dest_path) | ||
os.rename(DOWNLOAD_PATH + '/' + program, dest_path) | ||
|
||
else: | ||
raise Exception("Issue extracting terraform !!") | ||
|
||
os.chmod(dest_path, 0o755) | ||
else: | ||
print (program, version, "already downloaded") | ||
|
||
""" Installs Required Terraform / Terragrunt Versions """ | ||
|
||
|
||
def install(args): | ||
|
||
program = args.program | ||
version = args.version | ||
|
||
if not version and os.path.exists(VERSION_FILE): | ||
load_dotenv(dotenv_path=VERSION_FILE) | ||
version = (os.getenv(program.upper())) | ||
|
||
if not version: | ||
print ("Please define version or add that to .terraenv file") | ||
sys.exit(1) | ||
|
||
|
||
dest_path = DOWNLOAD_PATH + program + "_" + version | ||
|
||
if program == "terraform": | ||
download_program(program, version) | ||
|
||
elif program == "terragrunt": | ||
download_program(program, version) | ||
|
||
else: | ||
raise Exception( | ||
'Invalid Arguement !! It should be either terraform / terragrunt') | ||
|
||
try: | ||
os.remove("/usr/local/bin/" + program ) | ||
|
||
except FileNotFoundError: | ||
pass | ||
|
||
os.symlink(dest_path, "/usr/local/bin/" + program ) |
Oops, something went wrong.