-
Notifications
You must be signed in to change notification settings - Fork 10
/
.gitlab-ci.yml
41 lines (35 loc) · 1.47 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
stages:
- imagebuild
before_script:
- export APP_REVISION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME##*/}-r$CI_PIPELINE_ID}"
imagebuild:
stage: imagebuild
variables:
KUBECONFIG_YAML: $KUBECONFIG_DEV
script:
- |
# build
set -x
yarn config set registry https://registry.npm.taobao.org --global
yarn add npx
yarn install
TERM=xterm yarn run build
# docker build
IMAGES="$(jq -r '. | map(.server + "/" + .pathPrefix + "/" + env.CI_PROJECT_NAME + ":" + env.APP_REVISION) | join(" ")'<<<"$REGISTRIES")"
echo $IMAGES
eval docker build --network=host -t "$IMAGES" . || exit 1
# docker push
export DOCKER_CONFIG_JSON="$(jq 'reduce .[].auth.auths as $item ({}; . + $item) | {auths: .}'<<<"$REGISTRIES")"
echo $DOCKER_CONFIG_JSON
while read IMAGE; do
docker push "$IMAGE" || exit 1
done < <(jq -r '.[] | .server + "/" + .pathPrefix + "/" + env.CI_PROJECT_NAME + ":" + env.APP_REVISION'<<<"$REGISTRIES")
# docker rmi
docker images | grep "$APP_REVISION" | grep "$CI_PROJECT_NAME" | awk '{print $3}' | head -n 1 | xargs -t docker rmi -f
# patch image in dev cluster
# harbor.musiconline-dev.service.163.org/cloudnative/library/horizon-web:develop-r889445
newImage='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"'${IMAGES}'"}]'
kubectl patch deploy horizon-web -n horizon --type='json' -p="$newImage"
only:
- develop
- tags