forked from govCMS/scaffold-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci-main.yml
172 lines (147 loc) · 5.18 KB
/
.gitlab-ci-main.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
---
image: gitlab-registry-production.govcms.amazee.io/govcms/govcms-ci${GOVCMS_CI_IMAGE_VERSION}
services:
- name: gitlab-registry-production.govcms.amazee.io/govcms/govcms-ci/dind:latest
command: ["--tls=false"]
stages:
- static
- preflight
- integration
- deploy
variables:
extends: .variables
DOCKER_HOST: "tcp://localhost:2375"
##
# Test setups.
#
# Minimal setup without docker, tooling available by default is https://github.com/govCMS/govcms-ci.
.static_template: &static_template
before_script:
- composer install
stage: static
# Minimal setup to execute drush against a working Drupal.
.bootstrap_template: &bootstrap_template
before_script:
- |
docker network prune -f && docker network create amazeeio-network
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
# Some local overrides are prefixed with '###' and we remove them here.
sed -i -e "/###/d" docker-compose.yml
docker-compose up -d mariadb
docker-compose up -d cli
docker-compose ps
# Re-run composer to account for the fact the /app just got mounted over.
docker-compose exec -T cli bash -c 'composer install --no-interaction --no-suggest'
echo "Running govcms-deploy."
docker-compose exec -T cli ./vendor/bin/govcms-deploy
stage: preflight
# Setup the full working project for integration tests like Behat.
.full_template: &full_template
artifacts:
expire_in: "7 days"
paths:
- tests/behat/screenshots
stage: integration
before_script:
- |
docker network prune -f && docker network create amazeeio-network
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
# Some local overrides are prefixed with '###' and we remove them here.
sed -i -e "/###/d" docker-compose.yml
docker-compose up -d mariadb
docker-compose up -d
docker-compose ps
# Re-run composer to account for the fact the /app just got mounted over.
docker-compose exec -T cli bash -c 'composer install --no-interaction --no-suggest'
DATABASE_IMAGE="$CI_REGISTRY_IMAGE/mariadb-drupal-data"
# A hack to make the manifest check work.
sed -i "s/^}$/,\"experimental\":\ \"enabled\"}/" ~/.docker/config.json
EXIT_CODE=0 && docker manifest inspect "$DATABASE_IMAGE" > /dev/null || EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
echo "$DATABASE_IMAGE not found, installing GovCMS"
docker-compose exec -T cli bash -c 'drush sql-drop'
if [[ -f "./custom/database-quickstart.sql.gz" ]]; then
echo "Installing from a database dump."
gunzip ./custom/database-quickstart.sql.gz
docker-compose exec -T cli bash -c 'drush sql-cli --yes' < ./custom/database-quickstart.sql
else
echo "Installing the default govcms profile."
docker-compose exec -T cli bash -c 'drush si govcms -y'
fi
else
echo "Using found database image: $DATABASE_IMAGE"
fi
echo "Running govcms-deploy."
docker-compose exec -T cli ./vendor/bin/govcms-deploy
docker-compose exec -T cli bash -c 'drush status'
##
# Job definitions.
#
# NOTICE: By default, this job must always run because it's a platform
# compliance check. It should be "allow_failure: false" and
# it should not use "extends:". PaaS users can override (docs link).
vet:
<<: *static_template
stage: static
script:
- composer validate
- ./vendor/bin/govcms-vet
when: on_success
allow_failure: false
lint:
<<: *static_template
extends: .job-lint
# Run all lines together so that they all run even if any fail.
script:
- |
set +exuo pipefail # Linting...
./vendor/bin/govcms-lint web/modules/custom
./vendor/bin/govcms-lint web/themes/custom
unit:
<<: *static_template
extends: .job-unit
script:
- ./vendor/bin/govcms-unit --testsuite=unit
# Pre-flight (like a smoke test for general deployability).
preflight:
<<: *bootstrap_template
extends: .job-preflight
stage: preflight
script:
- docker-compose exec -T cli bash -c 'drush cim -y'
- docker-compose exec -T cli bash -c 'drush st'
- docker-compose exec -T cli bash -c 'drush updatedb:status'
# Integration.
behat:
<<: *full_template
extends: .job-behat
script:
- docker-compose exec -T test ./vendor/bin/govcms-behat
functional:
<<: *full_template
extends: .job-functional
script:
- docker-compose exec -T test /app/vendor/bin/phpunit --testsuite=functional -c /app/tests/phpunit
audit:
<<: *full_template
extends: .job-audit
script:
- docker-compose exec -T test ./vendor/bin/govcms-audit
# MRs only.
audit_on_merge:
<<: *full_template
extends: .job-audit-on-merge
script:
- docker-compose exec -T test ./vendor/bin/govcms-audit
only:
- merge_requests
stage: deploy
# Deploy / summary.
deploy:
variables:
GOVCMS_DASHBOARD: "https://dashboard.govcms.gov.au/projects"
script:
- echo "Deployment triggered, please see $GOVCMS_DASHBOARD/$CI_PROJECT_NAME/$CI_PROJECT_NAME-$(echo $CI_COMMIT_REF_NAME | sed -e 's/[^[:alnum:]-]/-/g')"
stage: deploy