Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions containers/test-db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Real-Time Reporting Test Database

A test database has been created to remove the requirement of running liquibase prior to test execution.

## Building a new test-db image locally
The [create_bak_files.sh](./create_bak_files.sh) script has been provided that automates the process of creating `.bak` files from a fresh database following the application of liquibase migration scripts. The script uses defaults for the database and liquibase container names that may not work on your system. A `DATABASE_CONTAINER_NAME` and `LIQUIBASE_CONTAINER_NAME` environment variable can be provided to override the defaults.

The [build_image.sh](./build_image.sh) script will utilize the newly created `.bak` files and build a ready to run database image. The script provides a default `IMAGE_NAME` that matches what is published in GHCR.

## Publishing a new test-db image in GHCR
The [publish-test-db-image.yaml](../../.github/workflows/publish-test-db-image.yaml) Github workflow handles publishing a new `test-db` image. The workflow allows manual dispatch and selection of a target branch to build from. This will allow you to build an image from your branch.

## Creating a pull request that depends on test-db changes
In order to create a pull request that modifies liquibase and have those changes be available for the Github test runner:
1. Create a new `test-db` locally using the provided scripts
2. Verify all tests are passing
3. Push the branch with your changes to Github
4. Publish a new `test-db` image by manually triggering the workflow. Be sure to target your branch
5. Once the `test-db` build is completed, create a PR
8 changes: 8 additions & 0 deletions containers/test-db/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
IMAGE_NAME="${IMAGE_NAME:-ghcr.io/cdcgov/nedss-datareporting-mssql:6.0.18.1}"
SQLCMDPASSWORD="${SQLCMDPASSWORD:-PizzaIsGood33!}"

# Build image from backups
echo "building new test-db image..."
docker build $SCRIPT_DIR/ --platform linux/amd64 --build-arg DATABASE_PASSWORD="$SQLCMDPASSWORD" -t "$IMAGE_NAME"
8 changes: 0 additions & 8 deletions containers/test-db/create_bak_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ DATABASE_CONTAINER_NAME="${DATABASE_CONTAINER_NAME:-rtr-nbs-mssql-1}"
LIQUIBASE_CONTAINER_NAME="${LIQUIBASE_CONTAINER_NAME:-rtr-liquibase-1}"
SQLCMDUSER="${SQLCMDUSER:-sa}"
SQLCMDPASSWORD="${SQLCMDPASSWORD:-PizzaIsGood33!}"
IMAGE_NAME="${IMAGE_NAME:-ghcr.io/cdcgov/nedss-datareporting-mssql:6.0.18.1}"
BUILD_IMAGE="${BUILD_IMAGE:-false}"

# Create clean backups by starting a fresh nedssdb and applying liquibase migrations
echo "starting database and applying liquibase migrations..."
Expand Down Expand Up @@ -94,9 +92,3 @@ docker cp $DATABASE_CONTAINER_NAME:/var/opt/mssql/backups/RDB_MODERN.bak $SCRIPT
# Stop containers
echo "database backups completed and saved to $SCRIPT_DIR/backups/. Stopping docker containers"
docker compose down

# Build image from backups
if [ $BUILD_IMAGE == true ]; then
echo "building new test-db image..."
docker build $SCRIPT_DIR/ --platform linux/amd64 --build-arg DATABASE_PASSWORD="$SQLCMDPASSWORD" -t "$IMAGE_NAME"
fi