-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI workflow for testing db migrations (#2326)
* Add workflows/db.yml and wip script for testing db migrations Signed-off-by: wslulciuc <willy@datakin.com> * Add --args to ./docker/up.sh Signed-off-by: wslulciuc <willy@datakin.com> * Add db-data volume Signed-off-by: wslulciuc <willy@datakin.com> * Add .github/workflows/db.sh Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add .github/workflows/db.sh Signed-off-by: wslulciuc <willy@datakin.com> * db.sh -> db-migration.sh Signed-off-by: wslulciuc <willy@datakin.com> * Use git sha1 for tag on `--build` Signed-off-by: wslulciuc <willy@datakin.com> * Use `seed_api` for docker service name and build on `--build` Signed-off-by: wslulciuc <willy@datakin.com> * Remove cd into root dir in docker/prune.sh Signed-off-by: wslulciuc <willy@datakin.com> * Cleanup docker/volumes.sh Signed-off-by: wslulciuc <willy@datakin.com> * Fix log error formatting Signed-off-by: wslulciuc <willy@datakin.com> * Add db-backup volume Signed-off-by: wslulciuc <willy@datakin.com> * Add `--no-web` and `--no-volumes` flags Signed-off-by: wslulciuc <willy@datakin.com> * Add `docker-compose.web-dev.yml` to support `--no-web` flag Signed-off-by: wslulciuc <willy@datakin.com> * Add `log_db_migration()` to `db-migration.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Add comments and cleanup logic in `docker/up.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Use `sudo` to run `db-migration.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Fix logic for `--no-web` and `--no-volumes` Signed-off-by: wslulciuc <willy@datakin.com> * continued: Fix logic for `--no-web` and `--no-volumes` Signed-off-by: wslulciuc <willy@datakin.com> * Remove `-it` flags from log_db_migration() Signed-off-by: wslulciuc <willy@datakin.com> * Set image in docker-compose.web-dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * Use dev compose file in build mode when seeding http api server Signed-off-by: wslulciuc <willy@datakin.com> * Set default value for `--build` Signed-off-by: wslulciuc <willy@datakin.com> * Append args Signed-off-by: wslulciuc <willy@datakin.com> * Cleanup image tags in dev mode Signed-off-by: wslulciuc <willy@datakin.com> * More debugging... Signed-off-by: wslulciuc <willy@datakin.com> * Set `DOCKER_BUILDKIT` and reorder appending compose files Signed-off-by: wslulciuc <willy@datakin.com> * Add migrate-db CI job Signed-off-by: wslulciuc <willy@datakin.com> * Cleanup debugging Signed-off-by: wslulciuc <willy@datakin.com> * Fix path to db-migration.sh Signed-off-by: wslulciuc <willy@datakin.com> * Remove deps for build-api CI job Signed-off-by: wslulciuc <willy@datakin.com> * continued: Remove deps for build-api CI job Signed-off-by: wslulciuc <willy@datakin.com> * Limit output from db-migration.sh Signed-off-by: wslulciuc <willy@datakin.com> * Print entire flyway_schema_history row Signed-off-by: wslulciuc <willy@datakin.com> * Install docker compose in migrate-db CI job Signed-off-by: wslulciuc <willy@datakin.com> * Ensure migrate-db CI jobs fails on migration issues Signed-off-by: wslulciuc <willy@datakin.com> * Order db migrations by installed_on Signed-off-by: wslulciuc <willy@datakin.com> * Update comments Signed-off-by: wslulciuc <willy@datakin.com> * Update chart docs to use docker-compose.db.yml Signed-off-by: wslulciuc <willy@datakin.com> * Rename db migration backup container Signed-off-by: wslulciuc <willy@datakin.com> * Add additional constants and comments to `db-migration.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Apply minor formatting Signed-off-by: wslulciuc <willy@datakin.com> * continued: Apply minor formatting Signed-off-by: wslulciuc <willy@datakin.com> * continued: Apply minor formatting Signed-off-by: wslulciuc <willy@datakin.com> * continued: Apply minor formatting Signed-off-by: wslulciuc <willy@datakin.com> * continued: Apply minor formatting Signed-off-by: wslulciuc <willy@datakin.com> * Always printout docker container logs for debugging Signed-off-by: wslulciuc <willy@datakin.com> * Replace `latest` with `0.29.0` in `db-migration.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Log simple log on migration error Signed-off-by: wslulciuc <willy@datakin.com> * Simplify script output for readability Signed-off-by: wslulciuc <willy@datakin.com> * continued: Simplify script output for readability Signed-off-by: wslulciuc <willy@datakin.com> * Add docs to `db-migration.sh` Signed-off-by: wslulciuc <willy@datakin.com> Signed-off-by: wslulciuc <willy@datakin.com>
- Loading branch information
Showing
13 changed files
with
256 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2018-2022 contributors to the Marquez project | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# A script used in CI to test database migrations by: | ||
# (1) Applying db migrations on latest Marquez release | ||
# (2) Take a backup of db from Step 1 | ||
# (3) Applying db migrations on latest Marquez build using backup | ||
# | ||
# Usage: $ ./db-migration.sh | ||
|
||
# Version of PostgreSQL | ||
readonly POSTGRES_VERSION="12.1" | ||
# Version of Marquez | ||
readonly MARQUEZ_VERSION="0.29.0" | ||
# Build version of Marquez | ||
readonly MARQUEZ_BUILD_VERSION="$(git log --pretty=format:'%h' -n 1)" # SHA1 | ||
|
||
readonly DB_MIGRATION_VOLUME="marquez_db-backup" | ||
readonly DB_MIGRATION_BACKUP="db-migration-backup" | ||
readonly DB_MIGRATION_QUERY=$(cat <<-END | ||
SELECT version,installed_on,checksum | ||
FROM flyway_schema_history | ||
WHERE version IS NOT NULL | ||
ORDER BY installed_on DESC LIMIT 1; | ||
END | ||
) | ||
|
||
log() { | ||
echo -e "\033[1m>>\033[0m ${1}" | ||
} | ||
|
||
error() { | ||
echo -e "\033[0;31merror: ${1}\033[0m" | ||
} | ||
|
||
exit_with_cause() { | ||
log "please view container logs for more details on cause:" | ||
docker-compose logs | ||
exit 1 | ||
} | ||
|
||
query_db_migration() { | ||
# Start db using backup | ||
[[ $(docker ps -f "name=${DB_MIGRATION_BACKUP}" --format '{{.Names}}') == "${DB_MIGRATION_BACKUP}" ]] || \ | ||
docker run -d --name "${DB_MIGRATION_BACKUP}" \ | ||
-v "${DB_MIGRATION_VOLUME}:/var/lib/postgresql/data" \ | ||
"postgres:${POSTGRES_VERSION}" | ||
# Query applied db migrations | ||
log "latest migration applied to db:" | ||
docker exec "${DB_MIGRATION_BACKUP}" \ | ||
psql -U marquez -c "${DB_MIGRATION_QUERY}" | ||
} | ||
|
||
# Change working directory to project root | ||
project_root=$(git rev-parse --show-toplevel) | ||
cd "${project_root}/" | ||
|
||
# (1) Apply db migrations on latest Marquez release | ||
log "start db with latest migrations (marquez=${MARQUEZ_VERSION}):" | ||
if ! ./docker/up.sh \ | ||
--args "--exit-code-from seed_marquez" \ | ||
--tag "${MARQUEZ_VERSION}" \ | ||
--no-web \ | ||
--seed > /dev/null; then | ||
error "failed to start db using backup!" | ||
exit_with_cause | ||
fi | ||
|
||
# Query, then display schema migration applied | ||
query_db_migration | ||
|
||
# (2) Apply db migrations on latest Marquez build using backup | ||
log "start db using backup (marquez=${MARQUEZ_BUILD_VERSION}):" | ||
if ! ./docker/up.sh \ | ||
--args "--exit-code-from seed_marquez" \ | ||
--no-web \ | ||
--no-volumes \ | ||
--build \ | ||
--seed > /dev/null; then | ||
error "failed to start db using backup!" | ||
exit_with_cause | ||
fi | ||
|
||
# Query, then display additional schema migration applied on backup (if any) | ||
query_db_migration | ||
|
||
log "DONE!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
#!/bin/bash | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# Copyright 2018-2022 contributors to the Marquez project | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Usage: $ ./get-docker-compose.sh | ||
|
||
set -e | ||
|
||
curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` > ~/docker-compose | ||
chmod +x ~/docker-compose | ||
sudo mv ~/docker-compose /usr/local/bin/docker-compose | ||
docker-compose --version | ||
# Download docker compose | ||
curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose | ||
|
||
# Change permissions, relocate docker compose, then verify | ||
chmod +x ~/docker-compose && \ | ||
sudo mv ~/docker-compose /usr/local/bin/docker-compose && \ | ||
docker-compose --version | ||
|
||
echo "DONE!" | ||
echo "DONE!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: "3.7" | ||
services: | ||
web: | ||
build: | ||
context: ./web | ||
dockerfile: Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3.7" | ||
services: | ||
web: | ||
image: "marquezproject/marquez-web:${TAG}" | ||
container_name: marquez-web | ||
environment: | ||
- MARQUEZ_HOST=api | ||
- MARQUEZ_PORT=${API_PORT} | ||
ports: | ||
- "${WEB_PORT}:${WEB_PORT}" | ||
depends_on: | ||
- api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.