Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: 2.1

executors:
terraenv_build_release:
docker:
- image: pjsonigra/centos7-git-ghr-python36
working_directory: ~/repo

commands:
terraenv_build_release:
steps:
- checkout
- run:
name: 'Install Packages'
command: |
pip3.6 install -r requirements.txt
- run:
name: 'Create Build'
command: |
pyinstaller terraenv.py --onefile
chmod +x dist/terraenv
tar cfz terraenv_linux_x64.tar.gz dist
- run:
name: 'Publish Build'
command: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
ghr $LATEST_TAG terraenv_linux_x64.tar.gz

jobs:
terraenv_build_release:
executor: terraenv_build_release
steps:
- terraenv_build_release

workflows:
terraenv_build_release:
jobs:
- terraenv_build_release:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
60 changes: 8 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ on:
push:
tags:
- '*'
jobs:
jobs:
create_release:
runs-on: ubuntu-latest
steps:
steps:
- name: Create Release
id: create_release
uses: actions/[email protected]
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 }}
release_name: Release ${{ 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
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements.txt
- name: Build App
run: |
make build
Expand All @@ -64,7 +64,7 @@ jobs:
id: extract_upload_url

- name: Upload Release Asset - OSx
id: upload-release-asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -73,47 +73,3 @@ jobs:
asset_path: terraenv_osx_x64.tar.gz
asset_name: terraenv_osx_x64.tar.gz
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: Package App
run: |
make package
- 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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.extract_upload_url.outputs.upload_url }}
asset_path: terraenv_linux_x64.tar.gz
asset_name: terraenv_linux_x64.tar.gz
asset_content_type: application/octet-stream
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM centos:7

RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm && \
yum update -y && \
yum install -y python36u python36u-libs python36u-devel python36u-pip git

ADD https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz .
RUN tar xvzf ghr_v0.13.0_linux_amd64.tar.gz && cd ghr_v0.13.0_linux_amd64 && \
chmod +x ghr && mv ghr /usr/local/bin
36 changes: 21 additions & 15 deletions commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ def download_program(program, version):
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 !!")

Expand All @@ -58,35 +58,41 @@ def download_program(program, version):


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')


if not os.access('/usr/local/bin', os.W_OK):
print("Error: User doesn't have write permission of /usr/local/bin directory.\
\n\nRun below command to grant permission and rerun 'terraenv install' command.\
\nsudo chown -R $(whoami) /usr/local/bin\n")
sys.exit(1)

try:
os.remove("/usr/local/bin/" + program )

except FileNotFoundError:
pass
os.symlink(dest_path, "/usr/local/bin/" + program )

os.symlink(dest_path, "/usr/local/bin/" + program )