Skip to content

Commit 2562622

Browse files
authored
Merge pull request #2 from piyushsonigra/separate-build-and-handle-permission-error
separate linux build with circleci, add dockerfile and handle permission error
2 parents 2e726da + 700635f commit 2562622

File tree

4 files changed

+81
-67
lines changed

4 files changed

+81
-67
lines changed

.circleci/config.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: 2.1
2+
3+
executors:
4+
terraenv_build_release:
5+
docker:
6+
- image: pjsonigra/centos7-git-ghr-python36
7+
working_directory: ~/repo
8+
9+
commands:
10+
terraenv_build_release:
11+
steps:
12+
- checkout
13+
- run:
14+
name: 'Install Packages'
15+
command: |
16+
pip3.6 install -r requirements.txt
17+
- run:
18+
name: 'Create Build'
19+
command: |
20+
pyinstaller terraenv.py --onefile
21+
chmod +x dist/terraenv
22+
tar cfz terraenv_linux_x64.tar.gz dist
23+
- run:
24+
name: 'Publish Build'
25+
command: |
26+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
27+
ghr $LATEST_TAG terraenv_linux_x64.tar.gz
28+
29+
jobs:
30+
terraenv_build_release:
31+
executor: terraenv_build_release
32+
steps:
33+
- terraenv_build_release
34+
35+
workflows:
36+
terraenv_build_release:
37+
jobs:
38+
- terraenv_build_release:
39+
filters:
40+
branches:
41+
ignore: /.*/
42+
tags:
43+
only: /^v[0-9]+(\.[0-9]+)*$/

.github/workflows/main.yml

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@ on:
44
push:
55
tags:
66
- '*'
7-
jobs:
7+
jobs:
88
create_release:
99
runs-on: ubuntu-latest
10-
steps:
10+
steps:
1111
- name: Create Release
1212
id: create_release
1313
uses: actions/[email protected]
1414
env:
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
1616
with:
1717
tag_name: ${{ github.ref }}
18-
release_name: Release v${{ github.ref }}
18+
release_name: Release ${{ github.ref }}
1919
draft: false
2020
prerelease: false
21-
21+
2222
- name: Save Upload URL
2323
shell: bash
2424
run: |
2525
echo "${{ steps.create_release.outputs.upload_url }}" > upload-url.txt
26-
26+
2727
- name: Upload
2828
uses: actions/upload-artifact@v1
2929
with:
3030
name: uploadurl
3131
path: upload-url.txt
32-
32+
3333
build_release_osx:
3434
needs: create_release
3535
runs-on: macOS-latest
@@ -46,7 +46,7 @@ jobs:
4646
- name: Install dependencies
4747
run: |
4848
python -m pip install --upgrade pip
49-
pip install -r requirements.txt
49+
pip install -r requirements.txt
5050
- name: Build App
5151
run: |
5252
make build
@@ -64,7 +64,7 @@ jobs:
6464
id: extract_upload_url
6565

6666
- name: Upload Release Asset - OSx
67-
id: upload-release-asset
67+
id: upload-release-asset
6868
uses: actions/[email protected]
6969
env:
7070
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -73,47 +73,3 @@ jobs:
7373
asset_path: terraenv_osx_x64.tar.gz
7474
asset_name: terraenv_osx_x64.tar.gz
7575
asset_content_type: application/octet-stream
76-
77-
build_release_linux:
78-
needs: create_release
79-
runs-on: ubuntu-latest
80-
strategy:
81-
max-parallel: 4
82-
matrix:
83-
python-version: [3.7]
84-
steps:
85-
- uses: actions/checkout@v1
86-
- name: Set up Python ${{ matrix.python-version }}
87-
uses: actions/setup-python@v1
88-
with:
89-
python-version: ${{ matrix.python-version }}
90-
- name: Install dependencies
91-
run: |
92-
python -m pip install --upgrade pip
93-
pip install -r requirements.txt
94-
- name: Build App
95-
run: |
96-
make build
97-
- name: Package App
98-
run: |
99-
make package
100-
- name: Download Upload URL
101-
uses: actions/download-artifact@v1
102-
with:
103-
name: uploadurl
104-
- name: Extract Upload URL
105-
shell: bash
106-
run: |
107-
echo "##[set-output name=upload_url;] $(cat uploadurl/upload-url.txt)"
108-
id: extract_upload_url
109-
110-
- name: Upload Release Asset - Linux
111-
id: upload-release-asset
112-
uses: actions/[email protected]
113-
env:
114-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115-
with:
116-
upload_url: ${{ steps.extract_upload_url.outputs.upload_url }}
117-
asset_path: terraenv_linux_x64.tar.gz
118-
asset_name: terraenv_linux_x64.tar.gz
119-
asset_content_type: application/octet-stream

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM centos:7
2+
3+
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm && \
4+
yum update -y && \
5+
yum install -y python36u python36u-libs python36u-devel python36u-pip git
6+
7+
ADD https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz .
8+
RUN tar xvzf ghr_v0.13.0_linux_amd64.tar.gz && cd ghr_v0.13.0_linux_amd64 && \
9+
chmod +x ghr && mv ghr /usr/local/bin

commands/install.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ def download_program(program, version):
2020
if program == "terraform":
2121
url = "https://releases.hashicorp.com" + "/terraform/" + version + \
2222
"/terraform_" + version + "_" + operating_sys + "_amd64.zip"
23-
23+
2424
elif program == "terragrunt":
2525
url = "https://github.com/gruntwork-io/terragrunt/releases/download/v" + \
2626
version + "/terragrunt_" + operating_sys + "_amd64"
27-
27+
2828
if not os.path.exists(DOWNLOAD_PATH + program + "_" + version):
2929

3030
print("Downloading", program, version, "from", url)
3131

3232
binary = requests.get(url)
33-
33+
3434
if binary.status_code == 404:
3535
raise Exception("Invalid version, got 404 error !")
36-
36+
3737
dest_path = DOWNLOAD_PATH + program + "_" + version
3838

3939
open(dest_path, 'wb').write(binary.content)
4040

4141
if program == "terraform":
42-
42+
4343
with ZipFile(dest_path, 'r') as zip:
4444
zip.extract('terraform', path=DOWNLOAD_PATH)
4545

4646
if os.path.exists(DOWNLOAD_PATH + '/' + program) and os.path.exists(dest_path):
4747
os.remove(dest_path)
4848
os.rename(DOWNLOAD_PATH + '/' + program, dest_path)
49-
49+
5050
else:
5151
raise Exception("Issue extracting terraform !!")
5252

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

5959

6060
def install(args):
61-
61+
6262
program = args.program
6363
version = args.version
6464

6565
if not version and os.path.exists(VERSION_FILE):
6666
load_dotenv(dotenv_path=VERSION_FILE)
6767
version = (os.getenv(program.upper()))
68-
68+
6969
if not version:
7070
print ("Please define version or add that to .terraenv file")
7171
sys.exit(1)
7272

7373

7474
dest_path = DOWNLOAD_PATH + program + "_" + version
75-
75+
7676
if program == "terraform":
7777
download_program(program, version)
78-
78+
7979
elif program == "terragrunt":
8080
download_program(program, version)
81-
81+
8282
else:
8383
raise Exception(
8484
'Invalid Arguement !! It should be either terraform / terragrunt')
85-
85+
86+
if not os.access('/usr/local/bin', os.W_OK):
87+
print("Error: User doesn't have write permission of /usr/local/bin directory.\
88+
\n\nRun below command to grant permission and rerun 'terraenv install' command.\
89+
\nsudo chown -R $(whoami) /usr/local/bin\n")
90+
sys.exit(1)
91+
8692
try:
8793
os.remove("/usr/local/bin/" + program )
88-
94+
8995
except FileNotFoundError:
9096
pass
91-
92-
os.symlink(dest_path, "/usr/local/bin/" + program )
97+
98+
os.symlink(dest_path, "/usr/local/bin/" + program )

0 commit comments

Comments
 (0)