-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
119 lines (111 loc) · 3.08 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
image: node:20-alpine
stages:
- build
# - publish
- review
- staging
- production
- cleanup
variables:
DOCKER_IMAGE_NAME: "$HARBOR_URL/ceitec-biodata/dareg-api"
CLUSTER_DOMAIN: "dyn.cloud.e-infra.cz"
DEPLOYMENT_TLD: dareg.${CLUSTER_DOMAIN}
DEPLOYMENT_TLD_FIX: "dareg.biodata.ceitec.cz"
K8S_AGENT_NAME: agent-dareg
K8S_NAMESPACE: ceitec-dareg-ns
build_image:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
before_script:
- echo "{\"auths\":{\"${HARBOR_URL}\":{\"auth\":\"$(printf "%s:%s" "${HUB_REGISTRY_USER}" "${HARBOR_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${DOCKER_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}"
.deploy: &deploy
image:
name: zhangsean/kubectl
entrypoint: ['']
before_script:
- kubectl config use-context $(kubectl config get-contexts -o=name | grep ${K8S_AGENT_NAME})
script:
- mkdir -p $CI_PROJECT_DIR/manifests/prepared/$APP_COMPONENT || true
- cd $CI_PROJECT_DIR/manifests
- for f in $APP_COMPONENT/*.yaml; do envsubst < $f > prepared/$f; done
- ls -la prepared/$APP_COMPONENT || true
- cat prepared/$APP_COMPONENT/*.yaml || true
- kubectl apply -f prepared/$APP_COMPONENT --recursive -n ${K8S_NAMESPACE}
artifacts:
name: deployments-$CI_COMMIT_REF_SLUG
paths:
- $CI_PROJECT_DIR/manifests/prepared/$APP_COMPONENT
expire_in: 1 week
review:
<<: *deploy
stage: review
variables:
APP_COMPONENT: server
APP: dev
APP_VERSION: $CI_COMMIT_SHORT_SHA
APP_HOST: api.devel.${DEPLOYMENT_TLD}
APP_HOST_FIX: api.devel.${DEPLOYMENT_TLD_FIX}
environment:
name: dev
url: https://api.devel.${DEPLOYMENT_TLD}
on_stop: stop-review
when: manual
only:
- branches
except:
- master
staging:
<<: *deploy
stage: staging
variables:
APP_COMPONENT: server
APP: staging
APP_VERSION: $CI_COMMIT_SHORT_SHA
APP_HOST: api.stage.${DEPLOYMENT_TLD}
APP_HOST_FIX: api.stage.${DEPLOYMENT_TLD_FIX}
environment:
name: staging
url: https://api.stage.${DEPLOYMENT_TLD_FIX}
only:
- master
production:
<<: *deploy
stage: production
variables:
APP_COMPONENT: server
APP: production
APP_VERSION: $CI_COMMIT_TAG
APP_HOST: "api.${DEPLOYMENT_TLD}"
APP_HOST_FIX: api.${DEPLOYMENT_TLD_FIX}
when: manual
environment:
name: production
url: "https://api.${DEPLOYMENT_TLD_FIX}"
only:
- tags
except:
- branches
stop-review:
<<: *deploy
stage: cleanup
script:
- echo "All cluster resources within the namespace ${K8S_NAMESPACE} with label 'deployment-id=$APP' will be removed" || true
- kubectl delete deployments,services,ingresses,configmaps,secrets -n ${K8S_NAMESPACE} -l deployment-id=$APP
variables:
APP: dev
GIT_STRATEGY: none
environment:
name: dev
action: stop
rules:
- if: $CI_COMMIT_BRANCH
when: manual
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never