Skip to content

Commit 221dfdb

Browse files
authored
Merge pull request #43 from ispeakc0de/fix-release-pipeline
(chore): Fix the build, push, and release pipeline
2 parents 31e6ace + cadbb9d commit 221dfdb

File tree

3 files changed

+140
-118
lines changed

3 files changed

+140
-118
lines changed

.github/workflows/build.yml

+57-76
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,90 @@
11
---
2-
name: litmus-ansible-ci
2+
name: Build
33
on:
44
pull_request:
5-
branches:
6-
- master
7-
push:
8-
branches:
9-
- master
10-
tags-ignore:
11-
- '**'
5+
branches: [master]
6+
types: [opened, synchronize, reopened]
127

138
env:
149
DOCKER_REPO: litmuschaos
1510
DOCKER_IMAGE: ansible-runner
1611
DOCKER_TAG: ci
1712

18-
defaults:
19-
run:
20-
shell: bash
21-
2213
jobs:
23-
24-
build:
14+
pre-checks:
2515
runs-on: ubuntu-latest
2616
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v2
17+
- uses: actions/checkout@v2
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
2920

30-
- name: Build Image
31-
env:
32-
SAVE_PATH: ${{ github.workspace }}
33-
run: |
34-
make build
35-
make save
36-
chmod +x ${{ github.workspace }}/image.tar
21+
- name: checking dependencies are installed
22+
run: make deps
3723

38-
- name: Upload artifact
39-
uses: actions/upload-artifact@v2
24+
- name: Running ansible syntax-checks
25+
run: make syntax-checks
26+
27+
- name: Running ansible lint-checks
28+
run: make lint-checks
29+
30+
gitleaks-scan:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v3
4034
with:
41-
name: myimage
42-
path: |
43-
${{ github.workspace }}/image.tar
44-
${{ github.workspace }}/tag.txt
35+
fetch-depth: 0
36+
- name: Run GitLeaks
37+
run: |
38+
wget https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz && \
39+
tar -zxvf gitleaks_8.18.2_linux_x64.tar.gz && \
40+
sudo mv gitleaks /usr/local/bin && gitleaks detect --source . -v
41+
4542
46-
image-checks:
43+
build:
44+
needs: pre-checks
4745
runs-on: ubuntu-latest
48-
needs: build
4946
steps:
50-
- name: Checkout
51-
uses: actions/checkout@v2
47+
- uses: actions/checkout@v2
48+
with:
49+
ref: ${{ github.event.pull_request.head.sha }}
5250

53-
- name: Download artifact
54-
uses: actions/download-artifact@v2
51+
- name: Set up QEMU
52+
uses: docker/setup-qemu-action@v1
5553
with:
56-
name: myimage
57-
path: ${{ github.workspace }}
58-
59-
- name: Load Docker image
60-
run: |
61-
docker load --input ${{ github.workspace }}/image.tar
54+
platforms: all
6255

63-
- name: checking dependencies are installed
64-
run: make deps
65-
66-
- name: Running ansible syntax-checks
67-
run: make syntax-checks
56+
- name: Set up Docker Buildx
57+
id: buildx
58+
uses: docker/setup-buildx-action@v1
59+
with:
60+
version: latest
6861

69-
- name: Running ansible lint-checks
70-
run: make lint-checks
62+
- name: Build and push
63+
uses: docker/build-push-action@v2
64+
with:
65+
push: false
66+
file: build/ansible-runner/Dockerfile
67+
platforms: linux/amd64
68+
tags: litmuschaos/ansible-runner:ci
7169

70+
trivy:
71+
needs: pre-checks
72+
runs-on: ubuntu-latest
73+
steps:
7274
- uses: actions/checkout@v2
7375
with:
74-
ref: ${{ github.event.pull_request.head.sha }}
76+
ref: ${{ github.event.pull_request.head.sha }}
77+
78+
- name: Build an image from Dockerfile
79+
run: |
80+
docker build -f build/ansible-runner/Dockerfile -t docker.io/litmuschaos/ansible-runner:${{ github.sha }} . --build-arg TARGETARCH=amd64
7581
7682
- name: Run Trivy vulnerability scanner
7783
uses: aquasecurity/trivy-action@master
7884
with:
79-
image-ref: 'litmuschaos/ansible-runner:ci'
85+
image-ref: 'docker.io/litmuschaos/ansible-runner:${{ github.sha }}'
8086
format: 'table'
8187
exit-code: '1'
8288
ignore-unfixed: true
8389
vuln-type: 'os,library'
84-
severity: 'CRITICAL,HIGH'
85-
86-
push:
87-
runs-on: ubuntu-latest
88-
needs: [build,image-checks]
89-
if: github.event_name == 'push'
90-
steps:
91-
- name: Checkout
92-
uses: actions/checkout@v2
93-
94-
- name: Download artifact
95-
uses: actions/download-artifact@v2
96-
with:
97-
name: myimage
98-
path: ${{ github.workspace }}
99-
100-
- name: Load Docker image
101-
run: |
102-
docker load --input ${{ github.workspace }}/image.tar
103-
104-
- name: Push Image
105-
env:
106-
DNAME: ${{ secrets.DNAME }}
107-
DPASS: ${{ secrets.DPASS }}
108-
run: |
109-
make push
90+
severity: 'CRITICAL,HIGH'

.github/workflows/push.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
name: Push
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags-ignore:
8+
- '**'
9+
10+
env:
11+
DOCKER_REPO: litmuschaos
12+
DOCKER_IMAGE: ansible-runner
13+
DOCKER_TAG: ci
14+
15+
jobs:
16+
pre-checks:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: checking dependencies are installed
22+
run: make deps
23+
24+
- name: Running ansible syntax-checks
25+
run: make syntax-checks
26+
27+
- name: Running ansible lint-checks
28+
run: make lint-checks
29+
30+
push:
31+
needs: pre-checks
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
36+
- name: Set up QEMU
37+
uses: docker/setup-qemu-action@v1
38+
with:
39+
platforms: all
40+
41+
- name: Set up Docker Buildx
42+
id: buildx
43+
uses: docker/setup-buildx-action@v1
44+
with:
45+
version: latest
46+
47+
- name: Login to Docker Hub
48+
uses: docker/login-action@v1
49+
with:
50+
username: ${{ secrets.DNAME }}
51+
password: ${{ secrets.DPASS }}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v2
55+
with:
56+
push: true
57+
file: build/ansible-runner/Dockerfile
58+
platforms: linux/amd64
59+
tags: litmuschaos/ansible-runner:ci

.github/workflows/release-build.yml

+24-42
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ env:
1212

1313
defaults:
1414
run:
15-
shell: bash
15+
shell: bash
1616

1717
jobs:
18-
release-build:
18+
push:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v2
21+
- uses: actions/checkout@v2
2322

2423
- name: Set Tag
2524
run: |
@@ -32,46 +31,29 @@ jobs:
3231
echo "RELEASE TAG: ${RELEASE_TAG}"
3332
echo "${RELEASE_TAG}" > ${{ github.workspace }}/tag.txt
3433
35-
- name: Build Image
36-
env:
37-
DOCKER_TAG: ${RELEASE_TAG}
38-
SAVE_PATH: ${{ github.workspace }}
39-
run: |
40-
make build
41-
make save
42-
chmod +x ${{ github.workspace }}/image.tar
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v1
36+
with:
37+
platforms: all
4338

44-
- name: Upload artifact
45-
uses: actions/upload-artifact@v2
39+
- name: Set up Docker Buildx
40+
id: buildx
41+
uses: docker/setup-buildx-action@v1
4642
with:
47-
name: myimage
48-
path: |
49-
${{ github.workspace }}/image.tar
50-
${{ github.workspace }}/tag.txt
51-
52-
release-push:
53-
runs-on: ubuntu-latest
54-
needs: [release-build]
55-
steps:
56-
- name: Checkout
57-
uses: actions/checkout@v2
58-
59-
- name: Download artifact
60-
uses: actions/download-artifact@v2
43+
version: latest
44+
45+
- name: Login to Docker Hub
46+
uses: docker/login-action@v1
6147
with:
62-
name: myimage
63-
path: ${{ github.workspace }}
64-
65-
- name: Load Docker image
66-
run: |
67-
docker load --input ${{ github.workspace }}/image.tar
68-
RELEASE_TAG=`cat ${{ github.workspace }}/tag.txt`
69-
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
48+
username: ${{ secrets.DNAME }}
49+
password: ${{ secrets.DPASS }}
7050

71-
- name: Push Image
51+
- name: Build and push
52+
uses: docker/build-push-action@v2
7253
env:
73-
DOCKER_TAG: ${RELEASE_TAG}
74-
DNAME: ${{ secrets.DNAME }}
75-
DPASS: ${{ secrets.DPASS }}
76-
run: |
77-
make push
54+
RELEASE_TAG: ${{ env.RELEASE_TAG }}
55+
with:
56+
push: true
57+
file: build/ansible-runner/Dockerfile
58+
platforms: linux/amd64
59+
tags: litmuschaos/ansible-runner:${{ env.RELEASE_TAG }},litmuschaos/ansible-runner:latest

0 commit comments

Comments
 (0)