Skip to content

Commit

Permalink
Merge pull request #997 from guardian/mob/prisma-prisma-prisma
Browse files Browse the repository at this point in the history
fix(prisma): Correct volume permissions
  • Loading branch information
akash1810 authored May 13, 2024
2 parents 7554d2d + e3b7e59 commit 8649c60
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
8 changes: 4 additions & 4 deletions containers/prisma-migrate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ RUN apk --no-cache add aws-cli
# This will allow us to use the prisma migrate deploy command
RUN npm init -y
# TODO: Keep the version automatically in sync with common/package.json
RUN npm install [email protected]
RUN npm install [email protected]

COPY ./containers/prisma-migrate/run-prisma-migrate.sh ./run-prisma-migrate.sh
RUN chmod +x ./run-prisma-migrate.sh
COPY ./containers/prisma-migrate/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 ...`
# Switch it back here so we can run a .sh script
ENTRYPOINT [ "sh" ]

CMD ["./run-prisma-migrate.sh"]
CMD ["/usr/src/app/run-prisma-migrate.sh"]
11 changes: 8 additions & 3 deletions containers/prisma-migrate/run-prisma-migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

set -e

ROOT_DIR=/usr/src/app

# This path needs to be writable
ARTIFACT_FILE="${ROOT_DIR}/prisma/prisma.zip"

echo 'Retrieving Prisma artifact from S3'
aws s3 cp "s3://$ARTIFACT_BUCKET/$PRISMA_ARTIFACT_KEY" ./prisma/
aws s3 cp "s3://$ARTIFACT_BUCKET/$PRISMA_ARTIFACT_KEY" "${ARTIFACT_FILE}"

echo 'Unzipping Prisma artifact'
unzip -q prisma/prisma.zip
unzip -q "${ARTIFACT_FILE}"

DB_PORT=5432
export DATABASE_URL=postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/postgres

echo 'Running prisma migrate deploy'
prisma/node_modules/.bin/prisma migrate deploy
"${ROOT_DIR}/node_modules/.bin/prisma" migrate deploy
12 changes: 12 additions & 0 deletions packages/cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ deployments.set('service-catalogue-prisma-migrations', {
},
regions: new Set([region]),
stacks: new Set([stack]),

/*
The prisma-migrate ECS task is:
- Updated via a CloudFormation deployment
- Triggered by a file landing in S3
This deployment uploads the file to S3,
and only runs once the CloudFormation deployment succeeds.
This ensures the correct versions are used.
*/
dependencies: ['cfn-eu-west-1-deploy-service-catalogue'],
});

deployments.set('theguardian-servicecatalogue-app', {
Expand Down
6 changes: 3 additions & 3 deletions packages/cdk/lib/__snapshots__/service-catalogue.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18582,9 +18582,9 @@ spec:
},
"MountPoints": [
{
"ContainerPath": "/prisma",
"ContainerPath": "/usr/src/app/prisma",
"ReadOnly": false,
"SourceVolume": "prisma-volume",
"SourceVolume": "artifact-volume",
},
],
"Name": "prisma-migrate-taskContainer",
Expand Down Expand Up @@ -18674,7 +18674,7 @@ spec:
},
"Volumes": [
{
"Name": "prisma-volume",
"Name": "artifact-volume",
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions packages/cdk/lib/prisma-migrate-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ export function addPrismaMigrateTask(
db.grantConnect(taskDefinition.taskRole);
artifactBucket.grantRead(taskDefinition.taskRole, prismaArtifactKey);

const prismaVolume: Volume = {
name: 'prisma-volume',
const prismaArtifactVolume: Volume = {
name: 'artifact-volume',
};

taskDefinition.addVolume(prismaVolume);
taskDefinition.addVolume(prismaArtifactVolume);

prismaTask.addMountPoints({
// So that we can download the prisma.zip from the artifact bucket
containerPath: '/prisma',
sourceVolume: prismaVolume.name,
containerPath: '/usr/src/app/prisma',
sourceVolume: prismaArtifactVolume.name,
readOnly: false,
});

Expand Down

0 comments on commit 8649c60

Please sign in to comment.