-
Notifications
You must be signed in to change notification settings - Fork 2
95 lines (84 loc) · 3.06 KB
/
cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: CI and CD
on:
push:
branches: [main]
pull_request:
jobs:
# ==============
# CI task
# ==============
quality-check:
name: Quality Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# If you wish to fail your job when the Quality Gate is red, uncomment the
# following lines. This would typically be used to fail a deployment.
- uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build-and-push-docker-image:
name: Build Docker image and push to repositories
runs-on: ubuntu-latest
needs: quality-check
steps:
- uses: actions/checkout@v3
- name: Setup SHA
run: echo "GITHUB_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ghcr.io/aorjoa-training/devops-go-example:${{ env.GITHUB_SHA }}
- name: Integration test inside Docker-compose cleanup
run: docker-compose -f docker-compose.test.yml down
- name: Integration test inside Docker-compose
run: docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from it_tests
- name: Login ghcr.io
uses: docker/login-action@v1.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
- name: Push to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: .
tags: |
ghcr.io/aorjoa-training/devops-go-example:${{ env.GITHUB_SHA }}
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
# ==============
# CD task
# ==============
gitops-versioning:
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- name: checkout
uses: actions/checkout@v2
with:
repository: aorjoa-training/devops-argocd
persist-credentials: false
fetch-depth: 0
- name: change image tag
run: |
git --version
git config user.name "aorjoa"
git config user.email "root@aorjoa.link"
sed -i -E "s/ghcr.io\/aorjoa-training\/devops-go-example.*$/ghcr.io\/aorjoa-training\/devops-go-example:${GITHUB_SHA}/" kube-gitops/deployment.yml
git add kube-gitops/deployment.yml
git commit -m "🤖 change docker image version to ${GITHUB_SHA}"
- name: push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: aorjoa-training/devops-argocd
branch: main