-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.yml
More file actions
160 lines (153 loc) · 5.38 KB
/
Copy pathdeploy.yml
File metadata and controls
160 lines (153 loc) · 5.38 KB
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
# Usage: This template is intended to be included in other GitLab CI/CD configuration files.
# It defines deployment jobs that can be used in a CI/CD pipeline.
# Integration example in importing gitlab-ci.yml:
#
# stages:
# - build
# - reset
# - test
# - (docker.build)
# - deploy.dev
# - test.dev
# - deploy.test
# - test.test
# - release
# - deploy.live
# - test.live
#
# include:
# - remote: 'https://raw.githubusercontent.com/xima-media/gitlab-templates/<release>/deploy.yml'
# inputs:
# ci_server_url: https://gitlab.com/
# test_environment_url: https://test.example.org
# live_environment_url: https://www.example.org/
spec:
inputs:
ci_server_url:
type: string
description: "URL of the CI server for post development deployments."
# deployment job variables
test_deploy_enabled:
type: boolean
default: true
description: "Whether to run the test deployment job and related jobs."
test_host_branch:
type: string
default: $TEST_HOST_BRANCH
description: "Branch to deploy to test environment."
test_host_selector:
type: string
default: "stage=test"
description: "Host selector for test deployment job."
regex: ^[a-zA-Z0-9_=]+$
test_environment_url:
type: string
description: "URL of the test environment."
live_deploy_enabled:
type: boolean
default: true
description: "Whether to run the live deployment and related jobs."
live_host_selector:
type: string
default: "stage=live"
description: "Host selector for live deployment job."
regex: ^[a-zA-Z0-9_=]+$
live_environment_url:
type: string
description: "URL of the live environment."
# release job variables
release_auto:
type: boolean
default: true
description: "Whether to run the release job automatically."
release_ref:
type: string
default: $CI_COMMIT_SHA
description: "Git reference for the release job. Defaults to the commit SHA."
release_tag_name:
type: string
description: "Tag name for the release job. Semver format required, e.g. 'v2.0.${CI_PIPELINE_IID}'"
default: "v2.0.${CI_PIPELINE_IID}"
---
deploy-test:
environment:
name: TEST
url: $[[ inputs.test_environment_url ]]
deployment_tier: testing
stage: deploy.test
extends: .deploy-prepare
dependencies:
- build-php
- build-node
rules:
- if: '"$[[ inputs.test_deploy_enabled ]]" != "true"'
when: never
- if: '$CI_SERVER_URL != "$[[ inputs.ci_server_url | expand_vars ]]"'
when: never
# Run normal deployment job if not running in the context of a reset job.
- if: '$RESET_JOB != "true" && $CI_COMMIT_BRANCH == "$[[ inputs.test_host_branch | expand_vars ]]"'
# Run deployment job after environment has been reset to apply necessary database updates and similar tasks.
- if: '$RESET_JOB == "true" && $CI_COMMIT_BRANCH == "$[[ inputs.test_host_branch | expand_vars ]]" && $RESET_DOWNLOAD_TARGET_SELECTOR == "$[[ inputs.test_host_selector | expand_vars ]]"'
script:
- vendor/bin/dep deploy:unlock $[[ inputs.test_host_selector ]] --branch=$CI_COMMIT_BRANCH -vvv
- vendor/bin/dep deploy-fast $[[ inputs.test_host_selector ]] --branch=$CI_COMMIT_BRANCH -vvv
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
dependencies: []
rules:
- if: $RESET_JOB == "true"
when: never
- if: '$CI_COMMIT_BRANCH == "main" && $CI_SERVER_URL == $XIMA_CI_SERVER_URL && "$[[ inputs.release_auto ]]" == "true"'
- if: '$CI_COMMIT_BRANCH == "main" && $CI_SERVER_URL == $XIMA_CI_SERVER_URL && "$[[ inputs.release_auto ]]" == "false"'
when: manual
script:
- 'echo "Creating release $[[ inputs.release_tag_name ]] for ref $[[ inputs.release_ref ]]"'
- OLD_COMMIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"
- DIFF="$(git range-diff $OLD_COMMIT_TAG...$CI_COMMIT_TAG)"
- echo "Diff since last release tag ($OLD_COMMIT_TAG):" > description.txt
- echo '```diff' >> description.txt
- echo "$DIFF" >> description.txt
- echo '```' >> description.txt
- cat description.txt
release:
tag_name: $[[ inputs.release_tag_name ]]
description: 'description.txt'
ref: $[[ inputs.release_ref ]]
deploy-live:
environment:
name: LIVE
url: $[[ inputs.live_environment_url ]]
deployment_tier: production
stage: deploy.live
extends: .deploy-prepare
dependencies:
- build-php
- build-node
rules:
- if: '"$[[ inputs.live_deploy_enabled ]]" != "true"'
when: never
- if: '$CI_SERVER_URL != "$[[ inputs.ci_server_url | expand_vars ]]"'
when: never
- if: $RESET_JOB == "true"
when: never
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
script:
- vendor/bin/dep deploy:unlock $[[ inputs.live_host_selector ]]
- vendor/bin/dep deploy $[[ inputs.live_host_selector ]] -vvv
deploy-live-warmup:
needs:
- job: build-php
- job: deploy-live
stage: deploy.live
extends: .deploy-prepare
rules:
- if: '"$[[ inputs.live_deploy_enabled ]]" != "true"'
when: never
- if: '$CI_SERVER_URL != "$[[ inputs.ci_server_url | expand_vars ]]"'
when: never
- if: $RESET_JOB == "true"
when: never
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
script:
- vendor/bin/dep deploy:cache:warmup $[[ inputs.live_host_selector ]] -vvv