-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
107 lines (97 loc) · 3.85 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
103
104
105
106
107
# FIXME: Ideally, rely on the CI from:
# include:
# - project: 'helm/charts/cern'
# ref: master
# file: '.gitlab-ci.yml'
variables:
HELM_VERSION: v3.10.3
REGISTRY: registry.cern.ch
REGISTRY_CHART_REPO: eos
stages:
#- gen-docs
- build
- deploy
before_script:
- mkdir -p .repo
#gen-docs:
# stage: gen-docs
# image: gitlab-registry.cern.ch/cloud/ciadm
# script:
# - bin/helm-docs-diff
build:
stage: build
image: gitlab-registry.cern.ch/cloud/ciadm
script:
- curl -o helm.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz; mkdir -p helm; tar zxvf helm.tar.gz -C helm; /usr/bin/cp helm/linux-amd64/helm /usr/local/bin; rm -rf helm*
- for chart in $(ls -d */Chart.yaml | xargs dirname); do helm dep update ${chart}; helm lint ${chart}; helm package ${chart}; done
except:
- tags
version-check:
stage: build
image: gitlab-registry.cern.ch/cloud/ciadm
script:
- |
CHART=$(git diff-tree --name-only --no-commit-id HEAD origin/master)
for base in $(find . -maxdepth 1 -type f | sed 's|./||' | xargs); do
CHART=$(echo ${CHART} | sed "s|${base}||")
done
if [ "$(echo ${CHART} | wc -w)" = 0 ]; then
echo "Changes do not affect charts. skipping"
exit 0;
elif [ "$(echo ${CHART} | wc -w)" != 1 ]; then
echo "ERROR: You can only merge changes on one chart. Please fix before merging again."
exit 1;
else
VDIFF="$(echo "$(git diff origin/master -- $CHART/Chart.yaml)" | grep "\-version:" || true)"
if [ "${VDIFF}" == "" ]; then
echo "${CHART} is a new chart, not checking version bump"
exit 0;
fi
OLD_CHART_VERSION="$(echo "${VDIFF}" | awk '{print $2}')"
# Check and accept if it's a new chart
if [ "${OLD_CHART_VERSION}" == "" ]; then
echo "${CHART} is a new chart, not checking version bump"
exit 0;
fi
NEW_CHART_VERSION="$(echo "$(git diff origin/master -- $CHART/Chart.yaml)" | grep "+version:" | awk '{print $2}')"
fi
- |
if [ ${NEW_CHART_VERSION} = "" ] || \
[ $(expr ${NEW_CHART_VERSION} \<= ${OLD_CHART_VERSION}) -eq 1 ]; then
echo "ERROR: Chart version must be higher than existent. Please fix before merging again."
exit 1
fi
only:
- master
deploy:
stage: deploy
image: gitlab-registry.cern.ch/cloud/ciadm
before_script:
- curl -o helm.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz; mkdir -p helm; tar zxvf helm.tar.gz -C helm; /usr/bin/cp helm/linux-amd64/helm /usr/local/bin; rm -rf helm*
script:
- |
set -x
CHART=$(echo $CI_COMMIT_TAG | awk -F '@' '{print $1}')
TAG_VERSION=$(echo $CI_COMMIT_TAG | awk -F '@' '{print $2}')
test -f ${CHART}/Chart.yaml
if [ $? -ne 0 ]; then
echo "ERROR: Chart.yaml does not exist for chart ${CHART}"
exit 1
fi
YAML_VERSION=$(cat ${CHART}/Chart.yaml | grep ^version | awk '{print $2}')
if [[ "$TAG_VERSION" == "$YAML_VERSION" ]]; then
echo "INFO: Logging to ${REGISTRY} as ${HELM_REPO_USERNAME}"
echo ${HELM_REPO_PASSWORD} | helm registry login ${REGISTRY} -u ${HELM_REPO_USERNAME} --password-stdin
echo "INFO: Linting and packaging ${CHART}"
helm dependency update ${CHART}
helm lint ${CHART}
helm package ${CHART}
REGISTRY_CHART_URL="${REGISTRY}/${REGISTRY_CHART_REPO}/charts"
echo "INFO: Will push ${CHART} (version ${TAG_VERSION}) to ${REGISTRY_CHART_URL}"
helm push ${CHART}-${TAG_VERSION}.tgz oci://${REGISTRY_CHART_URL}
else
echo "ERROR: Chart version ($YAML_VERSION) differs from tag version ($TAG_VERSION)"
exit 1
fi
only:
- tags