Skip to content

Commit

Permalink
db migrate image
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Aug 12, 2024
1 parent 6c6323c commit b6d104b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/docker-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build docker image
- name: Build docker images
run: ./docker/build
run: ./docker/db-migrate/build
- name: Push SHA tag
run: ./docker/push
run: ./docker/db-migrate/push
- name: Set environment variables for app
run: scripts/ci/copy-env-vars-to-dot-env-file
env:
Expand All @@ -35,7 +37,10 @@ jobs:
- name: Run service dependencies
run: scripts/run-dependencies
- name: Run app in docker
run: ./docker/run
run: ./docker/run
- name: log check
# TODO: remove this!
run: docker logs daedalus-web-app
- name: Set up Node
uses: actions/setup-node@v4
with:
Expand Down
13 changes: 10 additions & 3 deletions docker/common
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -ex
set -euxo pipefail

GIT_SHA=$(git rev-parse --short=7 HEAD)
if [[ -v "BRANCH_NAME" ]]; then
Expand All @@ -10,12 +10,19 @@ fi

REGISTRY=ghcr.io
ORG=jameel-institute
PREFIX="${REGISTRY}/${ORG}"

DB_IMAGE_NAME=daedalus-web-app-db
DB_TAG="${REGISTRY}/${ORG}/${DB_IMAGE_NAME}"
DB_TAG="${PREFIX}/${DB_IMAGE_NAME}"
DB_TAG_SHA="${DB_TAG}:${GIT_SHA}"
DB_TAG_BRANCH="${DB_TAG}:${GIT_BRANCH}"

DB_MIGRATE_IMAGE_NAME=daedalus-web-app-db-migrate
DB_MIGRATE_TAG="${PREFIX}/${DB_MIGRATE_IMAGE_NAME}"
DB_MIGRATE_TAG_SHA="${DB_MIGRATE_TAG}:${GIT_SHA}"
DB_MIGRATE_TAG_BRANCH="${DB_MIGRATE_TAG}:${GIT_BRANCH}"

APP_IMAGE_NAME=daedalus-web-app
APP_TAG="${REGISTRY}/${ORG}/${APP_IMAGE_NAME}"
APP_TAG="$PREFIX}/${APP_IMAGE_NAME}"
APP_TAG_SHA="${APP_TAG}:${GIT_SHA}"
APP_TAG_BRANCH="${APP_TAG}:${GIT_BRANCH}"
7 changes: 7 additions & 0 deletions docker/db-migrate/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:20-slim as base

WORKDIR /src

RUN npm ci

CMD [ "prisma", "migrate", "deploy" ]
9 changes: 9 additions & 0 deletions docker/db-migrate/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euxo pipefail
HERE=$(dirname $0)
. $HERE/../common

docker build \
--tag $DB_MIGRATE_TAG_SHA \
-f docker/db-migrate/Dockerfile \
.
6 changes: 6 additions & 0 deletions docker/db-migrate/push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euxo pipefail
HERE=$(dirname $0)
. $HERE/common

docker push "$DB_MIGRATE_TAG_SHA"
7 changes: 5 additions & 2 deletions docker/push-branch-tag
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash
set -e
set -euxo pipefail
HERE=$(dirname $0)
. $HERE/common

docker tag "$APP_TAG_SHA" "$APP_TAG_BRANCH"
docker push "$APP_TAG_BRANCH"
docker push "$APP_TAG_BRANCH"

docker tag "$DB_MIGRATE_TAG_SHA" "$DB_MIGRATE_TAG_BRANCH"
docker push "$DB_MIGRATE_TAG_BRANCH"
19 changes: 13 additions & 6 deletions docker/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
set -euxo pipefail
HERE=$(dirname $0)
. $HERE/common
# run web app image, assuming dependencies are already running

# Migrate the db - db container and other dependencies should already be running
docker run --rm -d \
--name $DB_MIGRATE_IMAGE_NAME
--env DATABASE_URL=postgresql://daedalus-web-app-user:changeme@localhost:5432/daedalus-web-app
"$DB_MIGRATE_TAG_SHA"

docker run --rm -d \
--network bridge \
--name "$APP_IMAGE_NAME" \
-p 3000:3000 \
--env DATABASE_URL=postgresql://daedalus-web-app-user:changeme@localhost:5432/daedalus-web-app
--env NUXT_R_API_BASE=http://daedalus-api:8001/
"$APP_TAG_SHA"

# env vars

# TODO: Need to have build both SHA images.. maybe roll build scripts together
# TODO: docker env file
# TODO: WAIT?

# Migrate the db
docker exec "$APP_IMAGE_NAME" prisma migrate deploy

# TODO: build and push db container in same pattern as app and migrate containers

0 comments on commit b6d104b

Please sign in to comment.