Skip to content

Commit

Permalink
chore(smoketest): split database services into a separate compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Nov 20, 2023
1 parent 08e2ee8 commit 6bcb8fd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 70 deletions.
75 changes: 75 additions & 0 deletions app/smoketest/compose/db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: "3"

services:
db:
image: docker.io/library/postgres:16-bullseye
networks:
- backend
- db-admin
hostname: db
expose:
- 5432
ports:
- "5432:5432"
environment:
POSTGRES_DB: privacypal
POSTGRES_USER: privacypal
POSTGRES_PASSWORD: password
volumes:
- postgres:/var/lib/pgsql/data
restart: unless-stopped
healthcheck:
test: pg_isready -U privacypal -d privacypal || exit 1
interval: 10s
retries: 3
start_period: 10s
timeout: 5s

db-init:
image: ghcr.io/cosc-499-w2023/privacypal-init-db:0.1.0-dev
depends_on:
db:
condition: service_healthy
build: ../../web/db
networks:
- db-admin
environment:
DATABASE_URL: postgresql://privacypal:password@db:5432/privacypal
PRIVACYPAL_AUTH_MANAGER: ${PRIVACYPAL_AUTH_MANAGER:-basic}
PRIVACYPAL_USER_PROPERTY_PATH: /opt/privacypal/user.properties.csv
volumes:
- ../../web/db/sample/user.properties.csv:/opt/privacypal/user.properties.csv:z

db-viewer:
image: docker.io/dpage/pgadmin4:7
depends_on:
db:
condition: service_healthy
hostname: db-viewer
ports:
- "8989:8989"
networks:
- db-admin
environment:
PGADMIN_DEFAULT_EMAIL: admin@privacypal.io
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_LISTEN_PORT: 8989
volumes:
- pgadmin:/var/lib/pgadmin
- ./include/servers.json:/pgadmin4/servers.json:z
restart: always
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8989 || exit 1
interval: 10s
retries: 3
start_period: 10s
timeout: 5s

networks:
db-admin:

volumes:
postgres:
driver: local
pgadmin:
driver: local
67 changes: 1 addition & 66 deletions app/smoketest/compose/privacypal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
PRIVACYPAL_OUTPUT_VIDEO_DIR: /opt/privacypal/output-videos
NEXTAUTH_SECRET: a-very-secure-one
NEXTAUTH_URL: http://localhost:8080
DATABASE_URL: postgresql://privacypal:a_secure_password@db:5432/privacypal
DATABASE_URL: postgresql://privacypal:password@db:5432/privacypal
volumes:
- output_videos:/opt/privacypal/output-videos
- input_videos:/opt/privacypal/input-videos
Expand Down Expand Up @@ -58,76 +58,11 @@ services:
- input_videos:/opt/privacypal/input-videos
restart: unless-stopped

db:
image: docker.io/library/postgres:16-bullseye
networks:
- backend
- db-admin
hostname: db
expose:
- 5432
ports:
- "5432:5432"
environment:
POSTGRES_DB: privacypal
POSTGRES_USER: privacypal
POSTGRES_PASSWORD: a_secure_password
volumes:
- postgres:/var/lib/pgsql/data
restart: unless-stopped
healthcheck:
test: pg_isready -U privacypal -d privacypal || exit 1
interval: 10s
retries: 3
start_period: 10s
timeout: 5s

db-init:
image: ghcr.io/cosc-499-w2023/privacypal-init-db:0.1.0-dev
depends_on:
db:
condition: service_healthy
build: ../../web/db
networks:
- db-admin
environment:
DATABASE_URL: postgresql://privacypal:a_secure_password@db:5432/privacypal

db-viewer:
image: docker.io/dpage/pgadmin4:7
depends_on:
db:
condition: service_healthy
hostname: db-viewer
ports:
- "8989:8989"
networks:
- db-admin
environment:
PGADMIN_DEFAULT_EMAIL: admin@privacypal.io
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_LISTEN_PORT: 8989
volumes:
- pgadmin:/var/lib/pgadmin
- ./include/servers.json:/pgadmin4/servers.json:z
restart: always
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8989 || exit 1
interval: 10s
retries: 3
start_period: 10s
timeout: 5s

networks:
backend:
db-admin:

volumes:
output_videos:
driver: local
input_videos:
driver: local
postgres:
driver: local
pgadmin:
driver: local
19 changes: 16 additions & 3 deletions app/smoketest/compose/smoketest.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#!/bin/bash

set -ex

COMPOSE_TOOL=${COMPOSE_TOOL:-docker-compose}

FILES=(
privacypal.yaml
db.yaml
)

CMDS=()

for file in "${FILES[@]}"; do
CMDS+=( -f "${file}" )
done

cleanup() {
DOWN_FLAGS=('--remove-orphans')
local DOWN_FLAGS=('--remove-orphans')
if [ "${KEEP_VOLUMES}" != "true" ]; then
DOWN_FLAGS+=('--volumes')
fi
${COMPOSE_TOOL} \
-f privacypal.yaml \
"${CMDS[@]}" \
down "${DOWN_FLAGS[@]}"
}

Expand All @@ -17,5 +30,5 @@ trap cleanup EXIT
cleanup

${COMPOSE_TOOL} \
-f privacypal.yaml \
"${CMDS[@]}" \
up
2 changes: 1 addition & 1 deletion app/web/db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SHELL := /usr/bin/env bash -o pipefail
POSTGRES_IMAGE ?= docker.io/library/postgres:16-bullseye
DATABASE ?= privacypal
DATABASE_USER ?= privacypal
DATABASE_PASSWORD ?= a_secure_password
DATABASE_PASSWORD ?= password
DATABASE_HOSTNAME ?= localhost
DATABASE_PORT ?= 5432

Expand Down

0 comments on commit 6bcb8fd

Please sign in to comment.