Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b9d30f3
test: add test for separate_server option
mschoettle Jan 26, 2026
31fbfb1
test: add test for separate_server option
mschoettle Jan 26, 2026
c07c728
test: add test for separate_server option
mschoettle Jan 26, 2026
e3b6c30
test: add test for separate_server option
mschoettle Jan 26, 2026
b87d948
test: add test for separate_server option
mschoettle Jan 26, 2026
e785d09
test: add test for separate_server option
mschoettle Jan 26, 2026
fa2be5d
test: add test for separate_server option
mschoettle Jan 26, 2026
83e4f5d
test: add test for separate_server option
mschoettle Jan 26, 2026
a3caddd
test: add test for separate_server option
mschoettle Jan 26, 2026
1d4bed7
test: add test for separate_server option
mschoettle Jan 26, 2026
3317c21
test: add test for separate_server option
mschoettle Jan 26, 2026
ccc3ca6
test: add test for separate_server option
mschoettle Jan 26, 2026
274dfa2
test: add test for separate_server option
mschoettle Jan 26, 2026
47810cd
test: add test for separate_server option
mschoettle Jan 26, 2026
beaf2f3
test: add test for separate_server option
mschoettle Jan 26, 2026
32c12c4
test: add test for separate_server option
mschoettle Jan 26, 2026
8aa71a5
test: add test for separate_server option
mschoettle Jan 26, 2026
7fdac54
test: add test for separate_server option
mschoettle Jan 26, 2026
b22419e
test: add test for separate_server option
mschoettle Jan 26, 2026
c83089c
add host.docker.internal during test
mschoettle Jan 27, 2026
60e0fb6
unset default value of use_custom_certs when the user should decide
mschoettle Jan 27, 2026
5330f7e
ensure that warnings show up
mschoettle Jan 27, 2026
5c61e4b
add check to ensure that compose config shows no errors or warnings
mschoettle Jan 27, 2026
5813780
disable DB TLS for test
mschoettle Jan 27, 2026
997ab5d
remove test code
mschoettle Jan 27, 2026
c806a66
replace false with 0
mschoettle Jan 27, 2026
aac022f
add clean up DB script
mschoettle Jan 27, 2026
fa9c0d5
move cleanup script to scripts directory
mschoettle Jan 27, 2026
9a4bc1c
switch to mysql command
mschoettle Jan 27, 2026
cf163e1
run cleanup script in a container
mschoettle Jan 27, 2026
f050362
add missing environment env variable
mschoettle Jan 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DB_ROOT_PASSWORD="{{ db_root_password }}"
DB_USE_TLS={{ db_use_tls | int }}
{% if use_custom_certs -%}
DB_CERTS=/certs/db-certs.crt
{%- else -%}
DB_CERTS=/etc/ssl/certs/ca-certificates.crt
{%- endif %}

SOURCE_SYSTEM_HOST=
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
version: "0.9.26"
- name: Test template using copier-template-tester
run: |
docker container ps
uv run --with copier --with copier-templates-extensions --with bcrypt --with copier-template-tester ctt
- name: Show running containers
run: |
Expand Down
8 changes: 4 additions & 4 deletions compose.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
{% if db_host_type == "container" -%}
depends_on:
- db
{%- elif db_host_type == "same_server" -%}
{%- elif db_host_type == "same_server" or is_test -%}
extra_hosts:
- "host.docker.internal:host-gateway"
{%- endif %}
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
{% if db_host_type == "container" -%}
depends_on:
- db
{%- elif db_host_type == "same_server" -%}
{%- elif db_host_type == "same_server" or is_test -%}
extra_hosts:
- "host.docker.internal:host-gateway"
{%- endif %}
Expand Down Expand Up @@ -135,7 +135,7 @@ services:
{% if db_host_type == "container" -%}
depends_on:
- db
{%- elif db_host_type == "same_server" -%}
{%- elif db_host_type == "same_server" or is_test -%}
extra_hosts:
- "host.docker.internal:host-gateway"
{%- endif %}
Expand Down Expand Up @@ -170,7 +170,7 @@ services:
{% if db_host_type == "container" -%}
depends_on:
- db
{%- elif db_host_type == "same_server" -%}
{%- elif db_host_type == "same_server" or is_test -%}
extra_hosts:
- "host.docker.internal:host-gateway"
{%- endif %}
Expand Down
17 changes: 16 additions & 1 deletion copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ db_use_adminer:
use_custom_certs:
type: bool
help: Do you need to use a custom CA file to verify HTTPS and DB connections?
default: false
default: |-
{% if certificate_type == 'file' or db_use_tls -%}
{{ UNSET }}
{%- else -%}
false
{%- endif %}
when: "{{ certificate_type == 'file' or db_use_tls }}"

use_ofelia:
Expand Down Expand Up @@ -257,6 +262,15 @@ _message_after_copy: |

_tasks:
# validation
- "echo Checking that the compose file has no warnings"
- command: |
if docker compose config --quiet 2>&1 | grep --quiet level=; then
echo compose config has errors or warnings
docker compose config --quiet 2>&1
exit 1
else
echo compose config has no errors or warnings
fi
- "echo Checking that required files are provided"
- command: |
echo Firebase admin key missing at {{ extra_files + '/firebase-admin-key.json' }}
Expand Down Expand Up @@ -382,4 +396,5 @@ _exclude:
- "zizmor.yml"
# - "README.md"
- extensions
- "{% if not is_test %}scripts/cleanup_db.sh{% endif %}"
- "{% if not is_test %}tests{% endif %}"
19 changes: 19 additions & 0 deletions ctt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ db_host_type = "same_server"
db_port = 3307
db_root_user = "root"
db_root_password = "root-password"
_extra_tasks = [
# need to clean up on existing DB server
"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",
"docker compose down",
]

# DB on a different server requires a db_host
[output.".ctt/db_different_server"]
db_host_type = "separate_server"
# use the service container to pretend it is a separate server
# very tricky to test in CI with a dedicated hostname
db_host = "host.docker.internal"
db_port = 3307
db_root_user = "root"
db_root_password = "root-password"
# force no TLS during test, requires certificate otherwise
# TODO: add test case with TLS enabled
db_use_tls = 0
use_custom_certs = false
34 changes: 34 additions & 0 deletions scripts/cleanup_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -euo pipefail

# renovate: datasource=docker depName=alpine
ALPINE_VERSION="3.23.2"

echo "Running container for mysql-client..."
docker run --rm --interactive \
--env DB_ROOT_USER=${DB_ROOT_USER} \
--env DB_ROOT_PASSWORD=${DB_ROOT_PASSWORD} \
--env DB_HOST=${DB_HOST} \
--env DB_USER=${DB_USER} \
--env DB_NAME=${DB_NAME} \
--network opal-${ENVIRONMENT} \
--add-host "host.docker.internal:host-gateway" \
alpine:${ALPINE_VERSION} sh -s << EOF
set -euo pipefail
apk add --no-cache mysql-client
echo "Connecting to DB server on ${DB_HOST}:${DB_PORT}..."
echo "Dropping databases..."
MYSQL_PWD=${DB_ROOT_PASSWORD} mariadb --protocol tcp --skip-ssl --user ${DB_ROOT_USER} --host ${DB_HOST} --port ${DB_PORT} <<'EOIF'
DROP DATABASE IF EXISTS \`$DB_NAME\`;
DROP DATABASE IF EXISTS \`OpalDB\`;
DROP DATABASE IF EXISTS \`QuestionnaireDB\`;
EOIF
echo "Successfully dropped databases"
echo "Dropping DB user ${DB_USER}..."
MYSQL_PWD=${DB_ROOT_PASSWORD} mariadb --protocol tcp --skip-ssl --user ${DB_ROOT_USER} --host ${DB_HOST} --port ${DB_PORT} <<'EOIF'
DROP USER IF EXISTS '$DB_USER'@'%';
FLUSH PRIVILEGES;
EOIF
echo "Successfully dropped DB user ${DB_USER}"
EOF
echo "Done!"
Loading