-
Notifications
You must be signed in to change notification settings - Fork 19
/
.gitlab-ci-check-docker-deploy.yml
98 lines (94 loc) · 3.03 KB
/
.gitlab-ci-check-docker-deploy.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
# .gitlab-ci-check-docker-deploy.yml
#
# This gitlab-ci template modifies a manifest file in an infrastructure
# repository to trigger de deploy of the newly build Docker image.
#
# It depends on .gitlab-ci-check-docker-build.yml, so both need to be
# included for the process to work.
#
#
# Add it to the project in hand through Gitlab's include functionality
#
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-docker-deploy.yml'
#
# Requires .gitlab-ci-check-docker-build.yml to be included and related
# variables to be set.
#
# Requires TARGET_MANIFEST_FILE to be set in the calling Pipeline. It
# can be one or more, separated by commas.
#
# The job will modify for the manifest file(s) in sre-repo, master branch,
# by default. It can overridden with INFRA_REPOSITORY and INFRA_BRANCH
# variables accordingly
#
# variables:
# TARGET_MANIFEST_FILE: <path to yaml file>,<path to other yaml file>
# INFRA_REPOSITORY: <[email protected]:mendersoftware/other-repo.git> (optional)
# INFRA_BRANCH: <other-branch> (optional)
#
# By default, it only runs on master branch, override rules tag to modify
# behavior, for example with a regex:
#
# rules:
# - if: '$CI_COMMIT_BRANCH =~ /^(master|staging|production|feature-.+|[0-9]+\.[0-9]+\.x)$/'
#
stages:
- build
- publish
- sync
include:
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-docker-build.yml'
variables:
INFRA_REPOSITORY: "[email protected]:mendersoftware/sre-tools.git"
INFRA_BRANCH: "master"
DEBIAN_FRONTEND: noninteractive
sync:image:
tags:
- mender-qa-worker-generic-light
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
dependencies:
- publish:image
stage: sync
image: debian:buster
before_script:
- apt update && apt install -yyq git
# Prepare SSH key
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan github.com >> ~/.ssh/known_hosts
# Configure git
- git config --global user.email "[email protected]"
- git config --global user.name "Mender Test Bot"
script:
# Prepare temporary workspace
- cd $(mktemp -d)
- git clone --depth 1 ${INFRA_REPOSITORY} .
- git fetch origin ${INFRA_BRANCH}:local-sync
- git checkout local-sync
# Find and edit spec file(s)
- for file in $(echo $TARGET_MANIFEST_FILE | tr ',' '\n'); do
- if [ ! -f "$file" ]; then
- echo "Cannot find spec file $file for container $CI_PROJECT_NAME"
- exit 1
- fi
- 'sed -i -E "s#image:\s+[-_./@:a-zA-Z0-9]+#image: $PUBLISH_IMAGE_DIGEST#g" $file'
- git add $file
- done
# Commit
- git commit -sm "[Mender CI/CD] Sync $CI_PROJECT_NAME" -m "Update $CI_PROJECT_NAME with tag $PUBLISH_IMAGE_DIGEST"
- git show
# Push (5 retries)
- for retry in $(seq 5); do
- if git push origin local-sync:${INFRA_BRANCH}; then
- exit 0
- fi
- git fetch origin ${INFRA_BRANCH}
- git rebase origin/${INFRA_BRANCH}
- done
- exit 1