-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
93 lines (87 loc) · 3.75 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
# NOTE: This file is a template, and might need editing before it works on your project.
### For more information on configuration, see reference(s):
### - https://docs.gitlab.com/ee/ci/yaml/
image: docker.nexus.heb.tools/busybox:latest
variables:
# Please edit to your GitLab project
CI_REGISTRY: "harbor.heb.com"
CI_REGISTRY_PROJECT: "kon.chai-apps"
CI_REGISTRY_IMAGE: "gameOfLifeFrontend"
# Use these variables to decide on which environment to deploy via CICD on deploy step
DEPLOY_ENVTYPE: "nonprod"
DEPLOY_ENV: "dev"
#KUSTOMIZE_PATH: ""
#CONFIG_REPO: ""
stages:
- build
- deploy
build_only:
stage: build
retry: 2
tags:
- KON_OWNER:CHAI-APPS
- KON_ENVTYPE:NONPROD
image:
# must be pinned to v0.16.0. Otherwise, authentication will not work.
name: gcr.io/kaniko-project/executor:debug-v0.16.0
entrypoint: [""]
script:
- CMD="/kaniko/executor --no-push --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY/$CI_REGISTRY_PROJECT/$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}}"
- echo "$CMD" && eval "$CMD"
build_and_push:
stage: build
retry: 2
tags:
- KON_OWNER:CHAI-APPS
- KON_ENVTYPE:NONPROD
image:
# must be pinned to v0.16.0. Otherwise, authentication will not work.
name: gcr.io/kaniko-project/executor:debug-v0.16.0
entrypoint: [""]
before_script:
# Authenticate to Harbor registry using credentials embedded on the team's Gitlab runners
- . /home/gitlab-runner/docker-login
script:
# Push docker image with tag equal to CI_COMMIT_TAG if present or CI_COMMIT_SHORT_SHA if not
- CMD="/kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY/$CI_REGISTRY_PROJECT/$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}}"
- echo "$CMD" && eval "$CMD"
allow_failure: false
# Limit this step to the Branch set as default on the repository
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
commit:
stage: deploy
tags:
- KON_OWNER:CHAI-APPS
- KON_ENVTYPE:NONPROD
image:
name: docker.nexus.heb.tools/buildpack-deps:scm
before_script:
- curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
- mv kustomize /usr/local/bin/
- . /home/gitlab-runner/git-ops
script:
# Strip config repo url to reuse
- |
config_repo="${CONFIG_REPO:-${CI_REPOSITORY_URL%*.git}-deploy}"
config_repo="${config_repo#*gitlab.com[/:]*}"
config_repo="${config_repo%*.git}"
- 'CLONE_CMD="git clone [email protected]:${config_repo}.git" && echo $CLONE_CMD && eval $CLONE_CMD'
# This controls which environment/Kustomization file will be updated with the new image
- "KUSTOMIZE_PATH=${KUSTOMIZE_PATH:-${DEPLOY_ENVTYPE}/${DEPLOY_ENV}/_bases}"
- "CI_IMAGE_TAG=${CI_IMAGE_TAG:-${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}}}"
- "cd ${config_repo##*/}/${KUSTOMIZE_PATH}"
- 'git checkout -b "ci_local_branch"'
- 'git config --global user.email "$GITLAB_USER_EMAIL"'
- 'git config --global user.name "$GITLAB_USER_NAME"'
- 'kustomize edit set image $CI_REGISTRY/$CI_REGISTRY_PROJECT/$CI_REGISTRY_IMAGE:${CI_IMAGE_TAG}'
- 'git add Kustomization'
- 'COMMIT_MSG="feat($DEPLOY_ENV): automated deploy ${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}} ($CI_JOB_URL)"'
- 'git commit -m "${COMMIT_MSG}"'
- 'git push origin ci_local_branch:${KUSTOMIZE_PATH//\//-}_${CI_IMAGE_TAG} -f -o merge_request.create -o merge_request.title="${COMMIT_MSG}"'
allow_failure: false
# Limit this step to the Branch set as default on the repository
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
# Comment if desired to perform updates to deployment repo automatically
when: manual