-
Notifications
You must be signed in to change notification settings - Fork 1
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 #19 from jameel-institute/jidea-59-dockerise-web-app
jidea-59 Dockerise web app
- Loading branch information
Showing
22 changed files
with
5,674 additions
and
3,829 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Playwright tests and docker push | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- '*' | ||
env: | ||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | ||
jobs: | ||
test-and-push: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Login to GHCR (GitHub Packages) | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build docker images | ||
run: ./docker/build && ./db/scripts/build | ||
- name: Push SHA tags | ||
run: ./docker/push && ./db/scripts/push | ||
- name: Run service dependencies | ||
run: scripts/run-dependencies --db-build-skip | ||
- name: Run app in docker | ||
run: ./docker/run | ||
- name: Set up Node for Playwright | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
- name: Install npm dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps && npx playwright install msedge | ||
- name: Run Playwright tests | ||
run: npm run test:e2e | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 | ||
- name: Push branch tag on success | ||
run: ./docker/push-branch-tag |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
HERE=$(dirname $0) | ||
. $HERE/../../docker/common | ||
|
||
docker push "$DB_TAG_SHA" |
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,21 @@ | ||
FROM node:20 | ||
|
||
ARG PORT=3000 | ||
|
||
ENV NODE_ENV=production | ||
|
||
WORKDIR /src | ||
|
||
COPY . . | ||
RUN npm ci | ||
|
||
# Generate the prisma client code | ||
RUN npm install [email protected] | ||
RUN npx prisma generate | ||
|
||
RUN npm run build | ||
|
||
ENV PORT=$PORT | ||
|
||
# migrate the db before running the server | ||
CMD ["/bin/bash", "-c", "npx prisma migrate deploy;node .output/server/index.mjs"] |
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,9 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
HERE=$(dirname $0) | ||
. $HERE/common | ||
|
||
docker build \ | ||
--tag $APP_TAG_SHA \ | ||
-f docker/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,23 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
|
||
GIT_SHA=$(git rev-parse --short=7 HEAD) | ||
if [[ -v "BRANCH_NAME" ]]; then | ||
GIT_BRANCH=${BRANCH_NAME} | ||
else | ||
GIT_BRANCH=$(git symbolic-ref --short HEAD) | ||
fi | ||
|
||
REGISTRY=ghcr.io | ||
ORG=jameel-institute | ||
PREFIX="${REGISTRY}/${ORG}" | ||
|
||
DB_IMAGE_NAME=daedalus-web-app-db | ||
DB_TAG="${PREFIX}/${DB_IMAGE_NAME}" | ||
DB_TAG_SHA="${DB_TAG}:${GIT_SHA}" | ||
DB_TAG_BRANCH="${DB_TAG}:${GIT_BRANCH}" | ||
|
||
APP_IMAGE_NAME=daedalus-web-app | ||
APP_TAG="${PREFIX}/${APP_IMAGE_NAME}" | ||
APP_TAG_SHA="${APP_TAG}:${GIT_SHA}" | ||
APP_TAG_BRANCH="${APP_TAG}:${GIT_BRANCH}" |
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 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
HERE=$(dirname $0) | ||
. $HERE/common | ||
|
||
docker push "$APP_TAG_SHA" |
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,10 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
HERE=$(dirname $0) | ||
. $HERE/common | ||
|
||
docker tag "$APP_TAG_SHA" "$APP_TAG_BRANCH" | ||
docker push "$APP_TAG_BRANCH" | ||
|
||
docker tag "$DB_TAG_SHA" "$DB_TAG_BRANCH" | ||
docker push "$DB_TAG_BRANCH" |
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,19 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
HERE=$(dirname $0) | ||
. $HERE/common | ||
|
||
# NB SHA image must be built before running this script | ||
# run-dependencies should also have been run, to create network and db container (the web app container will apply | ||
# migrations to the db, so the db container must be running first). | ||
|
||
# Check for dependencies - fail if not found | ||
(docker container top daedalus-web-app-db && docker container top daedalus-api && docker network inspect daedalus) > /dev/null || \ | ||
(echo "Not all dependencies are running." && exit 1) | ||
|
||
docker run -d \ | ||
--name "$APP_IMAGE_NAME" \ | ||
--network=daedalus \ | ||
-p 3000:3000 \ | ||
--env-file env.docker \ | ||
"$APP_TAG_SHA" |
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,20 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
# From now on, if the user presses Ctrl+C we should teardown gracefully | ||
function cleanup() { | ||
set +e # allow teardown errors | ||
docker container stop daedalus-web-app | ||
docker container rm daedalus-web-app | ||
set -e | ||
} | ||
cleanup | ||
trap cleanup EXIT | ||
|
||
HERE=$(realpath "$(dirname $0)") | ||
"$HERE"/run | ||
|
||
|
||
# Wait for Ctrl+C | ||
echo "Ready to use. Press Ctrl+C to teardown." | ||
sleep infinity |
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,2 @@ | ||
DATABASE_URL=postgresql://daedalus-web-app-user:changeme@daedalus-web-app-db:5432/daedalus-web-app | ||
NUXT_R_API_BASE=http://daedalus-api:8001/ |
Oops, something went wrong.