Skip to content

Commit c89e89d

Browse files
committed
feat: add auto-deploy.gitlab-ci.yml & rm unnecessary code in auto-deploy
Signed-off-by: Siddharth Tiwari <[email protected]>
1 parent 9d5f143 commit c89e89d

File tree

2 files changed

+222
-10
lines changed

2 files changed

+222
-10
lines changed

auto-deploy

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ function ensure_namespace() {
113113
kubectl get namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
114114
}
115115

116-
function initialize_tiller() {
117-
echo "Deprecated: Helm 3 does not have Tiller."
118-
}
119-
120116
function write_environment_values_file() {
121117

122118
export GITLAB_CI=${GITLAB_CI:-false}
@@ -450,10 +446,6 @@ function deploy_name() {
450446
echo $name
451447
}
452448

453-
function check_old_postgres_exist() {
454-
echo "false"
455-
}
456-
457449
# shellcheck disable=SC2086 # double quote to prevent globbing
458450
# shellcheck disable=SC2153 # incorrectly thinks replicas vs REPLICAS is a misspelling
459451
function get_replicas() {
@@ -492,7 +484,6 @@ case $option in
492484
check_kube_domain) check_kube_domain ;;
493485
download_chart) download_chart ;;
494486
ensure_namespace) ensure_namespace ;;
495-
initialize_tiller) initialize_tiller ;;
496487
create_secret) create_secret ;;
497488
persist_environment_url) persist_environment_url ;;
498489
auto_database_url) auto_database_url ;;
@@ -503,6 +494,5 @@ delete) delete "${@:2}" ;;
503494
create_application_secret) create_application_secret "${@:2}" ;;
504495
deploy_name) deploy_name "${@:2}" ;;
505496
get_replicas) get_replicas "${@:2}" ;;
506-
check_old_postgres_exist) check_old_postgres_exist ;;
507497
*) exit 1 ;;
508498
esac

auto-deploy.gitlab-ci.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
.auto-deploy:
2+
image: "ghcr.io/opencloudengineer/lambda:v0.2.0"
3+
dependencies: []
4+
review:
5+
extends: .auto-deploy
6+
stage: review
7+
script:
8+
- auto-deploy check_kube_domain
9+
- auto-deploy download_chart
10+
- auto-deploy ensure_namespace
11+
- auto-deploy create_secret
12+
- auto-deploy deploy
13+
- auto-deploy persist_environment_url
14+
environment:
15+
name: review/$CI_COMMIT_REF_NAME
16+
url: http://$CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN
17+
on_stop: stop_review
18+
artifacts:
19+
paths: [environment_url.txt, tiller.log]
20+
when: always
21+
rules:
22+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
23+
when: never
24+
- if: '$CI_COMMIT_BRANCH == "master"'
25+
when: never
26+
- if: '$REVIEW_DISABLED'
27+
when: never
28+
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
29+
stop_review:
30+
extends: .auto-deploy
31+
stage: cleanup
32+
variables:
33+
GIT_STRATEGY: none
34+
script:
35+
- auto-deploy delete
36+
environment:
37+
name: review/$CI_COMMIT_REF_NAME
38+
action: stop
39+
allow_failure: true
40+
rules:
41+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
42+
when: never
43+
- if: '$CI_COMMIT_BRANCH == "master"'
44+
when: never
45+
- if: '$REVIEW_DISABLED'
46+
when: never
47+
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
48+
when: manual
49+
# Staging deploys are disabled by default since
50+
# continuous deployment to production is enabled by default
51+
# If you prefer to automatically deploy to staging and
52+
# only manually promote to production, enable this job by setting
53+
# STAGING_ENABLED.
54+
staging:
55+
extends: .auto-deploy
56+
stage: staging
57+
script:
58+
- auto-deploy check_kube_domain
59+
- auto-deploy download_chart
60+
- auto-deploy ensure_namespace
61+
- auto-deploy create_secret
62+
- auto-deploy deploy
63+
environment:
64+
name: staging
65+
url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN
66+
rules:
67+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
68+
when: never
69+
- if: '$CI_COMMIT_BRANCH != "master"'
70+
when: never
71+
- if: '$STAGING_ENABLED'
72+
# Canaries are disabled by default, but if you want them,
73+
# and know what the downsides are, you can enable this by setting
74+
# CANARY_ENABLED.
75+
canary:
76+
extends: .auto-deploy
77+
stage: canary
78+
allow_failure: true
79+
script:
80+
- auto-deploy check_kube_domain
81+
- auto-deploy download_chart
82+
- auto-deploy ensure_namespace
83+
- auto-deploy create_secret
84+
- auto-deploy deploy canary
85+
environment:
86+
name: production
87+
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
88+
rules:
89+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
90+
when: never
91+
- if: '$CI_COMMIT_BRANCH != "master"'
92+
when: never
93+
- if: '$CANARY_ENABLED'
94+
when: manual
95+
.production: &production_template
96+
extends: .auto-deploy
97+
stage: production
98+
script:
99+
- auto-deploy check_kube_domain
100+
- auto-deploy download_chart
101+
- auto-deploy ensure_namespace
102+
- auto-deploy create_secret
103+
- auto-deploy deploy
104+
- auto-deploy delete canary
105+
- auto-deploy delete rollout
106+
- auto-deploy persist_environment_url
107+
environment:
108+
name: production
109+
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
110+
artifacts:
111+
paths: [environment_url.txt, tiller.log]
112+
when: always
113+
production:
114+
!!merge <<: *production_template
115+
rules:
116+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
117+
when: never
118+
- if: '$STAGING_ENABLED'
119+
when: never
120+
- if: '$CANARY_ENABLED'
121+
when: never
122+
- if: '$INCREMENTAL_ROLLOUT_ENABLED'
123+
when: never
124+
- if: '$INCREMENTAL_ROLLOUT_MODE'
125+
when: never
126+
- if: '$CI_COMMIT_BRANCH == "master"'
127+
production_manual:
128+
!!merge <<: *production_template
129+
allow_failure: false
130+
rules:
131+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
132+
when: never
133+
- if: '$INCREMENTAL_ROLLOUT_ENABLED'
134+
when: never
135+
- if: '$INCREMENTAL_ROLLOUT_MODE'
136+
when: never
137+
- if: '$CI_COMMIT_BRANCH == "master" && $STAGING_ENABLED'
138+
when: manual
139+
- if: '$CI_COMMIT_BRANCH == "master" && $CANARY_ENABLED'
140+
when: manual
141+
# This job implements incremental rollout on for every push to `master`.
142+
.rollout: &rollout_template
143+
extends: .auto-deploy
144+
script:
145+
- auto-deploy check_kube_domain
146+
- auto-deploy download_chart
147+
- auto-deploy ensure_namespace
148+
- auto-deploy create_secret
149+
- auto-deploy deploy rollout $ROLLOUT_PERCENTAGE
150+
- auto-deploy scale stable $((100-ROLLOUT_PERCENTAGE))
151+
- auto-deploy delete canary
152+
- auto-deploy persist_environment_url
153+
environment:
154+
name: production
155+
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
156+
artifacts:
157+
paths: [environment_url.txt, tiller.log]
158+
when: always
159+
.manual_rollout_template: &manual_rollout_template
160+
!!merge <<: *rollout_template
161+
stage: production
162+
resource_group: production
163+
allow_failure: true
164+
rules:
165+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
166+
when: never
167+
- if: '$INCREMENTAL_ROLLOUT_MODE == "timed"'
168+
when: never
169+
- if: '$CI_COMMIT_BRANCH != "master"'
170+
when: never
171+
# $INCREMENTAL_ROLLOUT_ENABLED is for compatibility with pre-GitLab 11.4 syntax
172+
- if: '$INCREMENTAL_ROLLOUT_MODE == "manual" || $INCREMENTAL_ROLLOUT_ENABLED'
173+
when: manual
174+
.timed_rollout_template: &timed_rollout_template
175+
!!merge <<: *rollout_template
176+
rules:
177+
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == ""'
178+
when: never
179+
- if: '$INCREMENTAL_ROLLOUT_MODE == "manual"'
180+
when: never
181+
- if: '$CI_COMMIT_BRANCH != "master"'
182+
when: never
183+
- if: '$INCREMENTAL_ROLLOUT_MODE == "timed"'
184+
when: delayed
185+
start_in: 5 minutes
186+
timed rollout 10%:
187+
!!merge <<: *timed_rollout_template
188+
stage: incremental rollout 10%
189+
variables:
190+
ROLLOUT_PERCENTAGE: 10
191+
timed rollout 25%:
192+
!!merge <<: *timed_rollout_template
193+
stage: incremental rollout 25%
194+
variables:
195+
ROLLOUT_PERCENTAGE: 25
196+
timed rollout 50%:
197+
!!merge <<: *timed_rollout_template
198+
stage: incremental rollout 50%
199+
variables:
200+
ROLLOUT_PERCENTAGE: 50
201+
timed rollout 100%:
202+
!!merge <<: *timed_rollout_template
203+
!!merge <<: *production_template
204+
stage: incremental rollout 100%
205+
variables:
206+
ROLLOUT_PERCENTAGE: 100
207+
rollout 10%:
208+
!!merge <<: *manual_rollout_template
209+
variables:
210+
ROLLOUT_PERCENTAGE: 10
211+
rollout 25%:
212+
!!merge <<: *manual_rollout_template
213+
variables:
214+
ROLLOUT_PERCENTAGE: 25
215+
rollout 50%:
216+
!!merge <<: *manual_rollout_template
217+
variables:
218+
ROLLOUT_PERCENTAGE: 50
219+
rollout 100%:
220+
!!merge <<: *manual_rollout_template
221+
!!merge <<: *production_template
222+
allow_failure: false

0 commit comments

Comments
 (0)