Skip to content

Commit

Permalink
Merge pull request #996 from guardian/aajb/dev-prisma-migrate
Browse files Browse the repository at this point in the history
Add a possibility to test prisma migrations locally
  • Loading branch information
JuliaBrigitte authored May 13, 2024
2 parents 8649c60 + 7a8cd72 commit 8ad7f56
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: ./
context: ./containers/${{ inputs.IMAGE_NAME }}
file: containers/${{ inputs.IMAGE_NAME }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
Expand Down
2 changes: 1 addition & 1 deletion containers/prisma-migrate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...`
Expand Down
8 changes: 8 additions & 0 deletions packages/dev-environment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ It includes:
> **Note**
> You can also use other Postgres clients, such as `psql` to query the data, or even your IDE!
## Testing the prima migration container
To test the prisma migration container you can run the following script:

```sh
./packages/dev-environment/script/start-prisma-migrate-test
```
This will run the run-prisma-migrate.sh script.

## RepoCop

To develop locally once the tables have been populated follow the steps in the repocop [README](../repocop/README.md)
Expand Down
31 changes: 31 additions & 0 deletions packages/dev-environment/docker-compose-prisma-migrate.yaml
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'
49 changes: 49 additions & 0 deletions packages/dev-environment/script/start-prisma-migrate-test
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

0 comments on commit 8ad7f56

Please sign in to comment.