-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #996 from guardian/aajb/dev-prisma-migrate
Add a possibility to test prisma migrations locally
- Loading branch information
Showing
5 changed files
with
90 additions
and
2 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 |
---|---|---|
|
@@ -12,7 +12,7 @@ RUN npm init -y | |
# TODO: Keep the version automatically in sync with common/package.json | ||
RUN npm install [email protected] | ||
|
||
COPY ./containers/prisma-migrate/run-prisma-migrate.sh /usr/src/app/run-prisma-migrate.sh | ||
COPY ./run-prisma-migrate.sh /usr/src/app/run-prisma-migrate.sh | ||
RUN chmod +x /usr/src/app/run-prisma-migrate.sh | ||
|
||
# The default entrypoint for the node image is `node ...` | ||
|
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
31 changes: 31 additions & 0 deletions
31
packages/dev-environment/docker-compose-prisma-migrate.yaml
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,31 @@ | ||
version: '3.9' | ||
services: | ||
# Test environment for prisma migration only | ||
prisma-migrate: | ||
build: | ||
context: ../../containers/prisma-migrate | ||
volumes: | ||
- ~/.aws/credentials:/.aws/credentials | ||
environment: | ||
AWS_CONFIG_FILE: /.aws/config | ||
AWS_SHARED_CREDENTIALS_FILE: /.aws/credentials | ||
AWS_DEFAULT_PROFILE: deployTools | ||
AWS_REGION: eu-west-1 | ||
ARTIFACT_BUCKET: deploy-tools-dist | ||
PRISMA_ARTIFACT_KEY: deploy/PROD/service-catalogue-prisma-migrations/prisma.zip | ||
POSTGRES_DB: ${DATABASE_NAME} | ||
DB_USERNAME: ${DATABASE_USER} | ||
DB_PASSWORD: ${DATABASE_PASSWORD} | ||
DB_HOST: 'postgres-prisma-migrate-test' | ||
DB_PORT: '5433' | ||
|
||
postgres: | ||
container_name: postgres-prisma-migrate-test | ||
image: postgres:14.6 | ||
ports: | ||
- '5433:5433' | ||
environment: | ||
POSTGRES_DB: ${DATABASE_NAME} | ||
POSTGRES_USER: ${DATABASE_USER} | ||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD} | ||
POSTGRES_PORT: '5433' |
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,49 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
ROOT_DIR=$DIR/../../.. | ||
|
||
MAIN_ENV_FILE=$ROOT_DIR/.env | ||
LOCAL_ENV_FILE=$HOME/.gu/service_catalogue/.env.local | ||
clear='\033[0m' | ||
cyan='\033[0;36m' | ||
|
||
step() { | ||
((STEP_COUNT++)) | ||
echo -e "\n${cyan}Step ${STEP_COUNT}${clear}: $1" | ||
} | ||
|
||
check_aws_credentials() { | ||
step "Checking AWS credentials" | ||
|
||
STATUS=$(aws sts get-caller-identity --profile deployTools 2>&1 || true) | ||
if [[ ${STATUS} =~ (ExpiredToken) ]]; then | ||
echo "Credentials for the deployTools profile have expired. Please fetch new credentials, and run this script again." | ||
exit 1 | ||
elif [[ ${STATUS} =~ ("could not be found") ]]; then | ||
echo "Credentials for the deployTools profile are missing. Please fetch some, and run this script again." | ||
exit 1 | ||
else | ||
echo "AWS credentials are valid" | ||
fi | ||
} | ||
|
||
start_containers() { | ||
step "Launching Docker containers" | ||
|
||
if (docker info) 2>&1 >/dev/null; then | ||
docker-compose -f "${DIR}/../docker-compose-prisma-migrate.yaml" --env-file "$MAIN_ENV_FILE" --env-file "$LOCAL_ENV_FILE" up -d --build | ||
else | ||
echo "Docker is not running. Please start Docker." | ||
exit 1 | ||
fi | ||
} | ||
|
||
main() { | ||
check_aws_credentials | ||
start_containers | ||
} | ||
|
||
main |