-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
160 lines (146 loc) · 4.64 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
stages:
- build
- deploy
- cleanup
default:
image: harbor.strasbourg.cloud/tools/werf-runner:v1.2.83
.base_werf: &base_werf
- source "$(trdl use werf 1.2 stable)"
- type werf
- mkdir -p ~/.docker && echo ${DOCKER_AUTH_CONFIG} >> ~/.docker/config.json
.base_build: &base_build
stage: build
variables:
WERF_REPO: "$REGISTRY_URL/$REGISTRY_REPOSITORY"
WERF_TAG: ${CI_COMMIT_SHA}
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
script:
- *base_werf
- werf build
- werf bundle publish --repo="$REGISTRY_URL/$REGISTRY_REPOSITORY"
.base_deploy: &base_deploy
stage: deploy
script:
- *base_werf
- werf converge --kube-config="${!KUBECONFIG_NAME}" --require-built-images --repo="$REGISTRY_URL/$REGISTRY_REPOSITORY" --set "env_url=$(echo ${CI_ENVIRONMENT_URL} | cut -d / -f 3)" --set "sslmode=${SSLMODE}" --set-docker-config-json-value=true
- sleep 30
.base_cleanup: &base_cleanup
stage: cleanup
script:
- *base_werf
- werf dismiss --kube-config="${!KUBECONFIG_NAME}" --with-namespace
- werf cleanup --kube-config="${!KUBECONFIG_NAME}" --repo="$REGISTRY_URL/$REGISTRY_REPOSITORY"
Build Review:
<<: *base_build
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "staging"'
Build Homologation:
<<: *base_build
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
Build Prod:
stage: build
variables:
WERF_IMAGES_REPO: "$REGISTRY_URL/$REGISTRY_REPOSITORY"
WERF_TAG: ${CI_COMMIT_TAG}
script:
- *base_werf
- werf build
- werf bundle publish --repo="$REGISTRY_URL/$REGISTRY_REPOSITORY"
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_BRANCH == "main"'
Deploy to Review:
<<: *base_deploy
environment:
name: review-${CI_MERGE_REQUEST_IID}
url: https://$CI_PROJECT_NAME-review-${CI_MERGE_REQUEST_IID}.$BASE_DOMAIN
on_stop: Stop Review
auto_stop_in: 1 day
variables:
WERF_REPO: "$REGISTRY_URL/$REGISTRY_REPOSITORY"
WERF_TAG: ${CI_COMMIT_SHA}
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
WERF_ENV: review-${CI_MERGE_REQUEST_IID}
KUBECONFIG_NAME: KUBECONFIG_HOMOLOGATION
ENV_URL: $CI_PROJECT_NAME-$WERF_ENV.$BASE_DOMAIN
SSLMODE: $SSL_MODE_REVIEW
artifacts:
paths:
- werf.yaml
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "staging"'
Stop Review:
<<: *base_cleanup
variables:
WERF_ENV: review-${CI_MERGE_REQUEST_IID}
KUBECONFIG_NAME: KUBECONFIG_HOMOLOGATION
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
environment:
name: review-${CI_MERGE_REQUEST_IID}
action: stop
dependencies:
- Deploy to Review
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "staging"'
when: manual
Deploy to Homologation:
<<: *base_deploy
environment:
name: staging
url: https://$CI_PROJECT_NAME-staging.$BASE_DOMAIN
on_stop: Stop Homologation
variables:
WERF_ENV: staging
ENV_URL: $CI_PROJECT_NAME-$WERF_ENV.$BASE_DOMAIN
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
KUBECONFIG_NAME: KUBECONFIG_HOMOLOGATION
SSLMODE: $SSL_MODE_HOMOLOGATION
artifacts:
paths:
- werf.yaml
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
Stop Homologation:
<<: *base_cleanup
variables:
WERF_ENV: staging
KUBECONFIG_NAME: KUBECONFIG_HOMOLOGATION
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
environment:
name: staging
action: stop
dependencies:
- Deploy to Homologation
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
when: manual
Create Tag:
stage: build
image: harbor.strasbourg.cloud/tools/curl:7.82.0
# see : curlimages/curl:7.82.0
script:
- CURRENT_DATE=$(date '+%Y-%m-%d-%H-%M')
- echo "$CURRENT_DATE"
- 'curl -X POST --header "PRIVATE-TOKEN: $ACCESS_TOKEN" "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/repository/tags?tag_name=$CURRENT_DATE&ref=main"'
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
Deploy to Production:
<<: *base_deploy
environment:
name: production
url: https://$PRODUCTION_URL
variables:
WERF_ENV: production
ENV_URL: $PRODUCTION_URL
WERF_BUILDAH_MODE: 'auto'
WERF_BUILDAH_STORAGE_DRIVER: 'overlay'
KUBECONFIG_NAME: KUBECONFIG_PRODUCTION
SSLMODE: $SSL_MODE_PRODUCTION
rules:
- if: '$CI_COMMIT_TAG'
when: manual