-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
102 lines (94 loc) · 3.46 KB
/
.gitlab-ci.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
96
97
98
99
100
101
102
stages:
- Test
- Release
- Update Chart
##############################################################################
## Variables ##
##############################################################################
variables:
# AWS_WEB_IDENTITY_TOKEN_FILE: /tmp/web-identity-token
CD_CHART_REPO: challenge-charts
CD_GIT_REPOSITORY: git@gitlab.com:cs302-2023/g3-team8/project/k8s/challenge-charts.git
CD_MANIFEST_FILE: values.yaml
APP_NAME: gitops-argocd-deploy
CHART_FOLDER: helm
##############################################################################
## Setup and Enable SSH ##
##############################################################################
.enable_ssh: &enable_ssh |-
apk add --no-cache git
mkdir -p /root/.ssh
echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
ssh-keyscan -H gitlab.com > /root/.ssh/known_hosts
chmod 600 /root/.ssh/id_rsa
##############################################################################
## Build Image ##
##############################################################################
lint:
image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine
stage: Test
script:
# Use default .golangci.yml file from the image if one is not present in the project root.
- "[ -e .golangci.yml ] || cp /golangci/.golangci.yml ."
# Write the code coverage report to gl-code-quality-report.json
# and print linting issues to stdout in the format: path/to/file:line description
# remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected
- golangci-lint run --issues-exit-code 0 --print-issued-lines=false --out-format code-climate:gl-code-quality-report.json,line-number
artifacts:
reports:
codequality: gl-code-quality-report.json
paths:
- gl-code-quality-report.json
# when: manual
unit-test:
stage: Test
image: docker:24.0.2
services:
- docker:24.0.2-dind
script:
- docker build -f docker/Dockerfile.test -t challenge-service:test .
- docker run --name challenge-service-test-container challenge-service:test go test -v ./... > test-results.txt
- ls
artifacts:
when: always
paths:
- test-results.txt
release-image:
stage: Release
image: docker:24.0.2
services:
- docker:24.0.2-dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build --compress -t $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:$CI_COMMIT_SHORT_SHA -f ./docker/Dockerfile .
- docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:$CI_COMMIT_SHORT_SHA
# when: manual
update_chart_manifest:
stage: Update Chart
image: docker:24.0.2
services:
- docker:24.0.2-dind
only:
- main
needs:
- release-image
variables:
GIT_STRATEGY: none
retry: 2
before_script:
- *enable_ssh
script:
# Configure Git
- git config --global user.name $APP_NAME
- git config --global user.email $APP_NAME"@gitlab.com"
- git clone --single-branch --branch main $CD_GIT_REPOSITORY
- cd $CD_CHART_REPO
- cd $CHART_FOLDER
# HELM Update
- >
tag=$(cat values.yaml | grep tag: | awk '{print $2}')
- sed -i "s/$tag/$CI_COMMIT_SHORT_SHA/" values.yaml
- cat $CD_MANIFEST_FILE
- cd ..
- git commit -am "🔥 update image tag" && git push origin main