forked from danskernesdigitalebibliotek/dpl-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
283 lines (253 loc) · 11.9 KB
/
Taskfile.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# This is a go-task file for various developer tasks
# e.g. building docker images and setting up local development.
# You can read about the Task files here: https://taskfile.dev.
version: '3'
dotenv: [".task.env"]
vars:
# Docker image registry.
# Eg.
# - ghcr.io/danskernesdigitalebibliotek
# - docker.io/someregistry
RELEASE_IMAGE_REGISTRY: '{{.RELEASE_IMAGE_REGISTRY | default "ghcr.io/danskernesdigitalebibliotek"}}'
# Get total amount of commits on the main branch. Used as build number.
COMMIT_COUNT:
sh: git rev-list --count origin/main
# The version number we want to tag the source build with.
# It can be specified by adding RELEASE_TAG=XX when running command.
# Otherwise it will default to the COMMIT_COUNT variable.
RELEASE_IMAGE_TAG: '{{.RELEASE_IMAGE_TAG | default .COMMIT_COUNT }}'
# Constructing docker image name.
DOCKER_IMAGE_PREFIX: "{{ .RELEASE_IMAGE_REGISTRY }}/{{ .DOCKER_IMAGE_NAMESPACE }}"
# Constructing docker image name.
RELEASE_IMAGE_NAME: '{{.RELEASE_IMAGE_NAME | default "dpl-cms-source"}}'
RELEASE_FULL_NAME: '{{.RELEASE_IMAGE_REGISTRY}}/{{.RELEASE_IMAGE_NAME}}:{{.RELEASE_IMAGE_TAG}}'
# Where is the docker file(s) we use for our builds residing?
LAGOON_DIR: "lagoon"
DOCKER_COMPOSE_FILES_DEFAULT: '-f docker-compose.yml'
DOCKER_COMPOSE_FILES: '{{.DOCKER_COMPOSE_FILES | default .DOCKER_COMPOSE_FILES_DEFAULT }}'
DOCKER_COMPOSE_FILES_CI: '{{.DOCKER_COMPOSE_FILES}} -f docker-compose.ci.yml'
# Sql dump files directory
DIR_RESTORE_DATABASE: 'restore/database'
# Directory with lagoon backup files.
DIR_RESTORE_FILES: 'restore/files'
# Ports and host names:
# Using ports exposed on localhost is important.
# Host names or ports exposed by Dory or other similar projects
# introduce multiple layers of proxies and cause problems.
#
# Cypress.
CYPRESS_BASE_PORT:
sh: docker compose port varnish 8080 | cut -d ":" -f2
CYPRESS_HOST_LOCAL: 'http://localhost:{{ .CYPRESS_BASE_PORT }}'
# Wiremock.
WIREMOCK_HTTP_PORT:
sh: docker compose port wiremock 80 | cut -d ":" -f2
WIREMOCK_HTTPS_PORT:
sh: docker compose port wiremock 443 | cut -d ":" -f2
WIREMOCK_HOST_DOCKER: http://wiremock
WIREMOCK_HOST_LOCAL: 'http://localhost:{{ .WIREMOCK_HTTP_PORT }}'
WIREMOCK_HOST_LOCAL_HTTPS: 'https://localhost:{{ .WIREMOCK_HTTPS_PORT }}'
tasks:
ghcr:login:
summary: Login into Github Container Registry
cmds:
- echo {{ .CR_PAT }} | docker login {{ .RELEASE_IMAGE_REGISTRY }} -u username-not-used --password-stdin
preconditions:
- sh: "[ ! -z {{.CR_PAT}} ]"
msg: "Env variable CR_PAT is not set or empty."
dev:cli:
summary: Performs command inside container. Expects parameter(s).
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES }} run --rm cli sh -c "{{.CLI_ARGS}}"
dev:start:
summary: Run docker compose
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES }} up -d {{if eq .CI "true"}}--quiet-pull{{end}}
vars:
CI:
sh: '[[ -z "${CI}" ]] && echo "false" || echo "true"'
dev:stop:
summary: Stop docker compose environment
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES }} stop
dev:down:
summary: Stop and remove docker compose environment
cmds:
# DNS proxies such as Dory may hang on to the network for a bit which
# causes the process to fail. Wait and retry if that is the case
- docker compose {{ .DOCKER_COMPOSE_FILES }} down --volumes --remove-orphans || (sleep 3 && docker-compose down)
dev:reset:
desc: Create local development setup in a clean state
cmds:
# Stop potential running environment.
- task dev:down
# Create a .env file with recommended defaults.
- cp -n .env.example .env || true
# Build site.
- task dev:cli -- composer install
# Always reinstall packages tracking develop builds. The content of such
# packages may change without composer package version changes so ensure
# we have the latest version.
- task dev:cli -- composer reinstall danskernesdigitalebibliotek/dpl-design-system danskernesdigitalebibliotek/dpl-react --no-cache
# Build dev scripts
- task dev:cli -- $(cd dev-scripts/dpl-react; composer install)
# Start local environment.
- task dev:start
# Install site.
- task dev:cli -- drush site-install --existing-config -y
# Practice shows that the cache needs to be cleared to avoid configuration
# errors even after a site install.
- task dev:cache:clear:drupal
# Import translations.
- task dev:cli -- drush locale-check
- task dev:cli -- drush locale-update
# Clear all caches to ensure we have a pristine setup.
- task dev:cache:clear:all
# Ensure site is reachable and warm any caches
- task dev:cli -- curl --silent --show-error --fail --output /dev/null http://varnish:8080/
# Show a one-time login to the local site.
- task dev:cli -- drush user-login
dev:phpunit:
desc: Run PHPUnit tests with code coverage
cmds:
- docker compose run -e XDEBUG_ENABLE=true -e XDEBUG_MODE=coverage,debug cli vendor/bin/phpunit --coverage-text
dev:restore:database:
desc: 'Restore database from db dump file. Only one sql should be present the "{{ .DIR_RESTORE_DATABASE }}" directory.'
cmds:
- docker-compose exec -T {{ .MYSQL_CONTAINER }} mysql < {{ .SQL_FILE }}
- task dev:cache:clear:all
preconditions:
- sh: "[ {{ .SQL_FILES_COUNT }} -gt 0 ]"
msg: "There are no sql files in {{ .DIR_RESTORE_DATABASE }}/. Cannot continue."
- sh: "[ {{ .SQL_FILES_COUNT }} -eq 1 ]"
msg: "There are {{ .SQL_FILES_COUNT }} valid files in {{ .DIR_RESTORE_DATABASE }}/:\n{{ .DIR_RESTORE_DATABASE_CONTENT }}\n...there should be just one."
vars:
SQL_FILES_COUNT:
sh: ls {{ .DIR_RESTORE_DATABASE }}/*.sql | wc -l 2> /dev/null | xargs
SQL_FILE:
sh: ls -t "{{ .DIR_RESTORE_DATABASE }}"/*.sql
DIR_RESTORE_DATABASE_CONTENT:
sh: ls {{ .DIR_RESTORE_DATABASE }}
MYSQL_CONTAINER: 'mariadb'
dev:restore:files:
desc: 'Restore files by overwriting existing with the ones from the Lagoon backup package'
cmds:
- docker-compose exec cli sh dev-scripts/cli-restore-lagoon-files.sh {{ .DIR_RESTORE_FILES }}
- task dev:cache:clear:all
dev:cache:clear:all:
summary: Clears all cache
cmds:
- task dev:cache:clear:drupal
- task dev:cache:clear:external
dev:cache:clear:drupal:
summary: Runs Drupal cache rebuild
cmds:
- task dev:cli -- drush cache:rebuild -y
dev:cache:clear:external:
summary: Purges the varnish cache
cmds:
- task dev:cli -- drush cache:rebuild-external -y
dev:dpl-react:get-asset-url:
summary: Outputs the url to the build in Github
cmds:
- cmd: task dev:cli -- dev-scripts/dpl-react/bin/console construct-assets-url {{ .BRANCH }}
preconditions:
- sh: "[ ! -z {{.BRANCH}} ]"
msg: "Env variable BRANCH is not set or empty."
dev:dpl-react:overwrite:
desc: Downloads assets from Github and overwrites existing dpl-react library
cmds:
- cmd: echo {{ .ASSET_URL }}
- cmd: task dev:cli -- dev-scripts/dpl-react/bin/console download-and-overwrite-library {{ .ASSET_URL }}
vars:
ASSET_URL:
sh: task dev:dpl-react:get-asset-url
dev:codegen:fbs:
desc: Generate FBS client package from OpenAPI specification
cmds:
- cmd: |
docker run --rm -v ${PWD}:/local -v ${PWD}/openapi-generator.config.fbs.yaml:/openapi-generator.config.fbs.yaml \
openapitools/openapi-generator-cli:v5.2.1 generate \
-i https://raw.githubusercontent.com/danskernesdigitalebibliotek/dpl-react/main/src/core/fbs/fbs-adapter.yaml \
-g php -o /local/packages/fbs-client -c /openapi-generator.config.fbs.yaml
ci:reset:
desc: Create CI setup in a clean state
cmds:
- task dev:reset
env:
DOCKER_COMPOSE_FILES: "{{ .DOCKER_COMPOSE_FILES_CI }}"
ci:cypress:
desc: Run Cypress functional tests
deps: [ci:wiremock:create-mappings]
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome yarn install --frozen-lockfile
- task dev:cli -- drush user:password $CYPRESS_DRUPAL_USERNAME $CYPRESS_DRUPAL_PASSWORD
# We make sure to run the tests that require mappings first.
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm -e CYPRESS_DRUPAL_USERNAME=$CYPRESS_DRUPAL_USERNAME -e CYPRESS_DRUPAL_PASSWORD=$CYPRESS_DRUPAL_PASSWORD cypress --spec "cypress/e2e/withMappings/*.ts"
# All tests that delete mappings and make their own run afterwards.
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm -e CYPRESS_DRUPAL_USERNAME=$CYPRESS_DRUPAL_USERNAME -e CYPRESS_DRUPAL_PASSWORD=$CYPRESS_DRUPAL_PASSWORD cypress --spec "cypress/e2e/*.ts"
env:
CYPRESS_DRUPAL_USERNAME: admin
CYPRESS_DRUPAL_PASSWORD: admin
ci:cypress:local:
desc: Run Cypress functional tests locally
deps: [ci:wiremock:create-mappings]
cmds:
- yarn install --frozen-lockfile
- task dev:cli -- drush user:password $CYPRESS_DRUPAL_USERNAME $CYPRESS_DRUPAL_PASSWORD
- http_proxy={{ .WIREMOCK_HOST_LOCAL }} https_proxy={{ .WIREMOCK_HOST_LOCAL_HTTPS }} npx cypress open
env:
CYPRESS_BASE_URL: http://localhost:{{ .CYPRESS_BASE_PORT }}
CYPRESS_WIREMOCK_URL: '{{ .WIREMOCK_HOST_LOCAL }}'
CYPRESS_DRUPAL_USERNAME: admin
CYPRESS_DRUPAL_PASSWORD: admin
# Enable this to help with debugging with network and proxy requests.
# https://docs.cypress.io/guides/references/troubleshooting#Print-DEBUG-logs
# DEBUG: cypress:network:*,cypress:server:request,-cypress:network:cors
ci:pa11y:
desc: Run Pa11y to test accessiblity
deps: [ci:wiremock:create-mappings]
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm -e HTTP_PROXY={{ .WIREMOCK_HOST_DOCKER }} node-chrome yarn pa11y:ci
ci:wiremock:browser:
desc: Watch the site with a wiremock http proxy. ⚠️ Depends on Chrome installed on OS ⚠️
deps: [ci:wiremock:create-mappings]
cmds:
- echo '⚠️ Please make sure that Chrome is installed in your OS.'
- yarn wiremock:browser
env:
HTTP_PROXY: '{{ .WIREMOCK_HOST_LOCAL }}'
ci:wiremock:create-mappings:
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome yarn install --frozen-lockfile
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm -e HTTP_PROXY={{ .WIREMOCK_HOST_DOCKER }} node-chrome yarn wiremock:create-mappings
ci:lighthouse:
desc: Run Lighthouse to test performance
deps: [ci:wiremock:create-mappings]
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm -e HTTP_PROXY={{ .WIREMOCK_HOST_DOCKER }} node-chrome npx lhci autorun
ci:openapi:validate:
desc: Validate the Drupal OpenAPI specification
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome yarn install --frozen-lockfile
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome npx swagger-cli validate http://varnish:8080/openapi/rest?_format=json
ci:openapi:download:
desc: Download the Drupal OpenAPI specification from the running local site to the local filesystem
cmds:
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome yarn install --frozen-lockfile
- docker compose {{ .DOCKER_COMPOSE_FILES_CI }} run --rm node-chrome curl http://varnish:8080/openapi/rest?_format=json | npx jsome -r > openapi.json
source:build:
summary: Build core source image.
cmds:
- docker build -f {{ .LAGOON_DIR }}/cli.dockerfile --tag dpl-cms-cli:0.0.0 .
- docker build -f {{ .LAGOON_DIR }}/source.dockerfile --tag {{ .RELEASE_FULL_NAME }} .
source:push:
summary: Push core source image to container registry.
deps: [ghcr:login]
cmds:
- docker push {{ .RELEASE_FULL_NAME }}
source:deploy:
desc: Build and push core source docker image.
cmds:
- task: source:build
- task: source:push