File tree Expand file tree Collapse file tree 6 files changed +75
-6
lines changed
Expand file tree Collapse file tree 6 files changed +75
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ DB_ROOT_PASSWORD="{{ db_root_password }}"
2222DB_USE_TLS={{ db_use_tls | int }}
2323{% if use_custom_certs -%}
2424DB_CERTS=/certs/db-certs.crt
25+ {% - else -%}
26+ DB_CERTS=/etc/ssl/certs/ca-certificates.crt
2527{% - endif %}
2628
2729SOURCE_SYSTEM_HOST=
Original file line number Diff line number Diff line change 5050 version : " 0.9.26"
5151 - name : Test template using copier-template-tester
5252 run : |
53- docker container ps
5453 uv run --with copier --with copier-templates-extensions --with bcrypt --with copier-template-tester ctt
5554 - name : Show running containers
5655 run : |
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ services:
5757 {% if db_host_type == "container" -%}
5858 depends_on:
5959 - db
60- {% - elif db_host_type == "same_server" -%}
60+ {% - elif db_host_type == "same_server" or is_test -%}
6161 extra_hosts:
6262 - "host.docker.internal:host-gateway"
6363 {% - endif %}
@@ -98,7 +98,7 @@ services:
9898 {% if db_host_type == "container" -%}
9999 depends_on:
100100 - db
101- {% - elif db_host_type == "same_server" -%}
101+ {% - elif db_host_type == "same_server" or is_test -%}
102102 extra_hosts:
103103 - "host.docker.internal:host-gateway"
104104 {% - endif %}
@@ -135,7 +135,7 @@ services:
135135 {% if db_host_type == "container" -%}
136136 depends_on:
137137 - db
138- {% - elif db_host_type == "same_server" -%}
138+ {% - elif db_host_type == "same_server" or is_test -%}
139139 extra_hosts:
140140 - "host.docker.internal:host-gateway"
141141 {% - endif %}
@@ -170,7 +170,7 @@ services:
170170 {% if db_host_type == "container" -%}
171171 depends_on:
172172 - db
173- {% - elif db_host_type == "same_server" -%}
173+ {% - elif db_host_type == "same_server" or is_test -%}
174174 extra_hosts:
175175 - "host.docker.internal:host-gateway"
176176 {% - endif %}
Original file line number Diff line number Diff line change @@ -162,7 +162,12 @@ db_use_adminer:
162162use_custom_certs :
163163 type : bool
164164 help : Do you need to use a custom CA file to verify HTTPS and DB connections?
165- default : false
165+ default : |-
166+ {% if certificate_type == 'file' or db_use_tls -%}
167+ {{ UNSET }}
168+ {%- else -%}
169+ false
170+ {%- endif %}
166171 when : " {{ certificate_type == 'file' or db_use_tls }}"
167172
168173use_ofelia :
@@ -257,6 +262,15 @@ _message_after_copy: |
257262
258263_tasks :
259264 # validation
265+ - " echo Checking that the compose file has no warnings"
266+ - command : |
267+ if docker compose config --quiet 2>&1 | grep --quiet level=; then
268+ echo compose config has errors or warnings
269+ docker compose config --quiet 2>&1
270+ exit 1
271+ else
272+ echo compose config has no errors or warnings
273+ fi
260274 - " echo Checking that required files are provided"
261275 - command : |
262276 echo Firebase admin key missing at {{ extra_files + '/firebase-admin-key.json' }}
@@ -382,4 +396,5 @@ _exclude:
382396 - " zizmor.yml"
383397 # - "README.md"
384398 - extensions
399+ - " {% if not is_test %}scripts/cleanup_db.sh{% endif %}"
385400 - " {% if not is_test %}tests{% endif %}"
Original file line number Diff line number Diff line change @@ -45,3 +45,22 @@ db_host_type = "same_server"
4545db_port = 3307
4646db_root_user = " root"
4747db_root_password = " root-password"
48+ _extra_tasks = [
49+ # need to clean up on existing DB server
50+ " ENVIRONMENT='{{ environment }}' DB_ROOT_USER='{{ db_root_user }}' DB_ROOT_PASSWORD='{{ db_root_password }}' DB_HOST='{{ db_host }}' DB_PORT='{{ db_port }}' DB_USER='{{ db_user }}' DB_NAME=admin ./scripts/cleanup_db.sh" ,
51+ " docker compose down" ,
52+ ]
53+
54+ # DB on a different server requires a db_host
55+ [output ." .ctt/db_different_server" ]
56+ db_host_type = " separate_server"
57+ # use the service container to pretend it is a separate server
58+ # very tricky to test in CI with a dedicated hostname
59+ db_host = " host.docker.internal"
60+ db_port = 3307
61+ db_root_user = " root"
62+ db_root_password = " root-password"
63+ # force no TLS during test, requires certificate otherwise
64+ # TODO: add test case with TLS enabled
65+ db_use_tls = 0
66+ use_custom_certs = false
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -euo pipefail
3+
4+ # renovate: datasource=docker depName=alpine
5+ ALPINE_VERSION=" 3.23.2"
6+
7+ echo " Running container for mysql-client..."
8+ docker run --rm --interactive \
9+ --env DB_ROOT_USER=${DB_ROOT_USER} \
10+ --env DB_ROOT_PASSWORD=${DB_ROOT_PASSWORD} \
11+ --env DB_HOST=${DB_HOST} \
12+ --env DB_USER=${DB_USER} \
13+ --env DB_NAME=${DB_NAME} \
14+ --network opal-${ENVIRONMENT} \
15+ --add-host " host.docker.internal:host-gateway" \
16+ alpine:${ALPINE_VERSION} sh -s << EOF
17+ set -euo pipefail
18+ apk add --no-cache mysql-client
19+ echo "Connecting to DB server on ${DB_HOST} :${DB_PORT} ..."
20+ echo "Dropping databases..."
21+ MYSQL_PWD=${DB_ROOT_PASSWORD} mariadb --protocol tcp --skip-ssl --user ${DB_ROOT_USER} --host ${DB_HOST} --port ${DB_PORT} <<'EOIF'
22+ DROP DATABASE IF EXISTS \` $DB_NAME \` ;
23+ DROP DATABASE IF EXISTS \` OpalDB\` ;
24+ DROP DATABASE IF EXISTS \` QuestionnaireDB\` ;
25+ EOIF
26+ echo "Successfully dropped databases"
27+ echo "Dropping DB user ${DB_USER} ..."
28+ MYSQL_PWD=${DB_ROOT_PASSWORD} mariadb --protocol tcp --skip-ssl --user ${DB_ROOT_USER} --host ${DB_HOST} --port ${DB_PORT} <<'EOIF'
29+ DROP USER IF EXISTS '$DB_USER '@'%';
30+ FLUSH PRIVILEGES;
31+ EOIF
32+ echo "Successfully dropped DB user ${DB_USER} "
33+ EOF
34+ echo " Done!"
You can’t perform that action at this time.
0 commit comments