-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
176 lines (164 loc) · 4.37 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
variables:
GIT_SUBMODULE_STRATEGY: recursive
ARCHES: amd64 arm64
ARCH_DEFAULT: amd64
REGISTRIES: $CI_REGISTRY
IMAGE_NODE: node:12.10.0-alpine
stages:
- lint
- build-container
- post-build
- deploy
- pages
.kaniko-build-pre-script: &kaniko-build-pre-script |
set -x
mkdir -p /kaniko/.docker
cat << EOF > /kaniko/.docker/config.json
{
"auths": {
"$CI_REGISTRY": {
"username": "$CI_REGISTRY_USER",
"password": "$CI_REGISTRY_PASSWORD"
}
}
}
EOF
.kaniko-build-taggable-name: &kaniko-build-taggable-name |
export APP_VERSION="$(date --date=${CI_COMMIT_TIMESTAMP%T*} +%Y.%m.%d.%H%M)"
export KANIKO_RELEASE_DESTINATIONS="--destination $CI_REGISTRY_IMAGE:latest-$ARCH --destination $CI_REGISTRY_IMAGE:$APP_VERSION-$ARCH"
export PROJECT_PATH=$(echo $CI_PROJECT_PATH | tr '[:upper:]' '[:lower:]')
.kaniko-build: &kaniko-build |
/kaniko/executor \
--snapshotMode=redo \
--context $CI_PROJECT_DIR \
--dockerfile $CI_PROJECT_DIR/Dockerfile \
--build-arg ARCH="$ARCH" \
$KANIKO_DESTINATIONS \
$KANIKO_RELEASE_DESTINATIONS
.build-container: &build-container
stage: build-container
image:
name: gcr.io/kaniko-project/executor:debug-v1.3.0
entrypoint: [""]
retry: 2
only:
- master
- tags
before_script:
- *kaniko-build-pre-script
- *kaniko-build-taggable-name
script:
- *kaniko-build
only:
variables:
- $KUBECONFIG_FROM_ENV
build-container-amd64:
<<: *build-container
variables:
ARCH: "amd64"
build-container-arm64:
<<: *build-container
variables:
ARCH: "arm64"
tag-container-image:
stage: post-build
image: docker:20.10.6
before_script:
- *kaniko-build-pre-script
- *kaniko-build-taggable-name
script:
- |
set -x
cp -rf /kaniko/.docker $HOME/.docker
if [[ -z "$CI_COMMIT_TAG" ]]; then
APP_BUILD_VERSION=
fi
for tag in $APP_VERSION latest$BRANCH_NAME; do
for reg in $REGISTRIES; do
export IMAGE_TAG_WITH_ARCH=""
for arch in $ARCHES; do
IMAGE="$reg/$PROJECT_PATH:$tag-$arch"
export IMAGE_TAG_WITH_ARCH="$IMAGE_TAG_WITH_ARCH $IMAGE"
done
docker manifest create $reg/$PROJECT_PATH:$tag $IMAGE_TAG_WITH_ARCH
for arch in $ARCHES; do
# TODO tidy up
EXTRA_ARGS=""
if [ "$arch" = "arm64" ]; then
EXTRA_ARGS="--variant v8"
fi
docker manifest annotate $reg/$PROJECT_PATH:$tag $reg/$PROJECT_PATH:$tag-$arch --os linux --arch $arch $EXTRA_ARGS
done
docker manifest push $reg/$PROJECT_PATH:$tag
done
done
only:
variables:
- $KUBECONFIG_FROM_ENV
deploy:
stage: deploy
image:
name: alpine:3.12
entrypoint: [""]
variables:
KUBECTL_VERSION: v1.20.2
KUBECTL_HASH: 2583b1c9fbfc5443a722fb04cf0cc83df18e45880a2cf1f6b52d9f595c5beb88
MANIFEST_FOLDER: $CI_PROJECT_DIR/manifests
before_script:
- *kaniko-build-taggable-name
- apk add --no-cache curl gettext
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl
- echo "$KUBECTL_HASH kubectl" | sha256sum -c -
- chmod +x kubectl
- mv kubectl /usr/local/bin/kubectl
- mkdir -p $HOME/.kube
- echo ${KUBECONFIG_FROM_ENV} | base64 -d > $HOME/.kube/config
- cd $MANIFEST_FOLDER
script:
- |
for MANIFEST in $MANIFEST_FOLDER/*; do
if cat $MANIFEST | grep -q ci-sa:noapply=true; then
continue
fi
envsubst < $MANIFEST | kubectl apply -f -
done
only:
refs:
- master
- tags
variables:
- $KUBECONFIG_FROM_ENV
lint_frontend:
stage: lint
image: node:12.10.0-alpine
allow_failure: true
before_script:
- npm i
script:
- npm run lint
spell_check:
stage: lint
image: golang:1.13.10-alpine3.11
allow_failure: true
before_script:
- apk add --no-cache git
- go get -u github.com/client9/misspell/cmd/misspell
script:
- misspell -error src docs migrations pubic template k8s-manifests README*
pages:
image: $IMAGE_NODE
stage: pages
script:
- npm i
- npm run build
- rm -r public
- mv dist/ public/
artifacts:
paths:
- public
only:
refs:
- master
except:
variables:
- $KUBECONFIG_FROM_ENV