-
Notifications
You must be signed in to change notification settings - Fork 14
/
.gitlab-ci.yml
95 lines (85 loc) · 2.58 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
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
stages:
- build
- autopilot
docker_image:
stage: build
variables:
DOCKER_DRIVER: overlay2
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --pull -t $IMAGE_TAG . --build-arg=GTAG_MANAGER_ID=$GTAG_MANAGER_ID
- docker push $IMAGE_TAG
tags:
- docker
.autopilot-tag:
image: alpine:3.20
stage: autopilot
variables:
GIT_STRATEGY: none
before_script:
- apk update && apk add git openssh curl glab kustomize
- glab config set -g check_update false
- git config --global user.email "ci@civo.com"
- git config --global user.name "CI Bot"
- git clone $AUTOPILOT src
- cd src
- git checkout main
- git pull
- git clean -fdx
tags:
- docker
autopilot-staging:
extends: .autopilot-tag
variables:
BRANCH: staging-docs-$CI_COMMIT_SHORT_SHA
script: |
cd docs/overlays/staging
git checkout -b $BRANCH
kustomize edit set image $CI_REGISTRY_IMAGE=$IMAGE_TAG
# Do we have any changes?
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
git add -A
git commit -m "staging/docs to $CI_COMMIT_SHORT_SHA"
git push -u origin $BRANCH
sleep 5
glab mr create -a @me -f -y
sleep 5
glab mr approve
sleep 5
glab mr merge -y -d
else
echo "no changes for staging"
fi
autopilot-prod:
extends: .autopilot-tag
needs: ["autopilot-staging"]
variables:
BRANCH: prod-docs-$CI_COMMIT_SHORT_SHA
script: |
cd docs/overlays/prod
git checkout -b $BRANCH
kustomize edit set image $CI_REGISTRY_IMAGE=$IMAGE_TAG
# Do we have any changes?
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
git add -A
git commit -m "prod/docs to $CI_COMMIT_SHORT_SHA"
git push -u origin $BRANCH
sleep 5
glab mr create -a @me -f -y
sleep 5
# Close all other MRs
CURRENT_MR=$(glab mr list --assignee=@me | grep $BRANCH | awk '{print $1}' | tr -d '!')
for mr in $(glab mr list --assignee=@me | grep -v $BRANCH | grep prod-docs | awk '{print $1}' | tr -d '()')
do
glab mr note $mr -m "Automatically closing in favour of newer MR !${CURRENT_MR}"
done
for mr in $(glab mr list --assignee=@me | grep -v $BRANCH | grep prod-docs | awk '{print $8}' | tr -d '()')
do
echo Closing branch $mr
git push origin --delete $mr
done
else
echo "no changes for prod"
fi