-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
179 lines (166 loc) · 4.33 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
177
178
179
image: node:20-alpine
stages:
- build
- publish
- review
- staging
- production
- cleanup
variables:
DOCKER_IMAGE_NAME: "$HARBOR_URL/ceitec-biodata/dareg-ui"
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
cache:
key:
files:
- package.json
paths:
- $CI_PROJECT_DIR/.npm/
- $CI_PROJECT_DIR/node_modules
# unit test:
# stage: test
# before_script:
# - npm ci --cache .npm --prefer-offline
# script:
# - npm run test
# needs: ["eslint"]
# eslint:
# stage: lint
# before_script:
# - npm ci --cache .npm --prefer-offline
# script:
# - npm run lint
build_app:
stage: build
before_script:
- npm i --cache .npm --prefer-offline --force
script:
- unset CI #This will need to be fixed + add test beforehand
- npm run build
artifacts:
paths:
- $CI_PROJECT_DIR/build/
expire_in: 2 hours
except:
- tags
# needs: ["unit test"]
build_image:
stage: publish
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
# - docker login -u $HUB_REGISTRY_USER -p $HARBOR_PASSWORD $HARBOR_URL
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${DOCKER_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}"
# - docker build --tag $DOCKER_IMAGE_NAME:$CI_COMMIT_SHORT_SHA --tag latest --tag $CI_COMMIT_REF_SLUG -f $CI_PROJECT_DIR/Dockerfile .
# - docker push --all-tags $DOCKER_IMAGE_NAME
except:
- tags
.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: web
# APP: review-$CI_COMMIT_REF_SLUG
# APP_ID: review-$CI_COMMIT_REF_SLUG
# APP_HOST: $CI_COMMIT_REF_SLUG.${DEPLOYMENT_TLD}
# APP_HOST_FIX: test.${DEPLOYMENT_TLD_FIX}
# environment:
# name: review/$CI_COMMIT_REF_SLUG
# url: https://$CI_COMMIT_REF_SLUG.${DEPLOYMENT_TLD}
# on_stop: stop-review
# only:
# - branches
# except:
# - master
dev:
<<: *deploy
stage: review
variables:
APP_COMPONENT: web
APP_ID: dev
APP: dev
APP_HOST: devel.${DEPLOYMENT_TLD}
APP_HOST_FIX: devel.${DEPLOYMENT_TLD_FIX}
environment:
name: staging
url: https://devel.${DEPLOYMENT_TLD_FIX}
when: manual
only:
- branches
except:
- master
staging:
<<: *deploy
stage: staging
variables:
APP_COMPONENT: web
APP_ID: staging
APP: staging
APP_HOST: stage.${DEPLOYMENT_TLD}
APP_HOST_FIX: stage.${DEPLOYMENT_TLD_FIX}
environment:
name: staging
url: https://stage.${DEPLOYMENT_TLD_FIX}
only:
- master
production:
<<: *deploy
stage: production
variables:
APP_COMPONENT: web
APP_ID: production
APP: production
APP_HOST: ${DEPLOYMENT_TLD}
APP_HOST_FIX: ${DEPLOYMENT_TLD_FIX}
when: manual
environment:
name: production
url: https://${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
when: manual
variables:
APP: dev
GIT_STRATEGY: none
environment:
name: dev
action: stop
only:
- branches
except:
- master