Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jidea-59 Dockerise web app #19

Merged
merged 32 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
07effeb
dockerfile
EmmaLRussell Aug 8, 2024
ecd5317
Add build and run scripts, use ghcr tags
EmmaLRussell Aug 9, 2024
051d63f
add build and push workflow
EmmaLRussell Aug 9, 2024
d0293c2
use token
EmmaLRussell Aug 9, 2024
b18a672
set sha
EmmaLRussell Aug 9, 2024
5b141e6
set branch name
EmmaLRussell Aug 9, 2024
4ae953c
update script perms
EmmaLRussell Aug 9, 2024
07042a4
combine docker and e2e workflows
EmmaLRussell Aug 10, 2024
92eea07
push branch tag on test success
EmmaLRussell Aug 10, 2024
66faee0
actually push the branch tag!"
EmmaLRussell Aug 10, 2024
4fa5953
merge with main
EmmaLRussell Aug 12, 2024
519fb4e
run script
EmmaLRussell Aug 12, 2024
7687dbe
add db build and push
EmmaLRussell Aug 14, 2024
a0b27f4
add db build and push
EmmaLRussell Aug 14, 2024
a6f5fbe
run migrations in web container, and run in network
EmmaLRussell Aug 14, 2024
7e9c5e0
fix push path
EmmaLRussell Aug 14, 2024
28e3fd6
tidy up
EmmaLRussell Aug 16, 2024
bfe65ab
update README
EmmaLRussell Aug 16, 2024
da39d80
lint
EmmaLRussell Aug 16, 2024
140ae62
reinstate lint-staged
EmmaLRussell Aug 16, 2024
cfbd8b4
refresh lock file
EmmaLRussell Aug 16, 2024
5b8081b
run-dev scripts tear down previous if running, and docker run checks …
EmmaLRussell Aug 19, 2024
f820da5
Do ci in Dockerfile
EmmaLRussell Aug 19, 2024
5e1a060
make nuxt modules deps
EmmaLRussell Aug 19, 2024
6cf96f9
remaining changes from PR
EmmaLRussell Aug 19, 2024
c4f518b
lint
EmmaLRussell Aug 19, 2024
292ef19
fix typo in branch script
EmmaLRussell Aug 20, 2024
b918b35
Remove the use of Github Actions variables
david-mears-2 Aug 29, 2024
81d7fcc
Merge pull request #22 from jameel-institute/remove-github-action-env…
EmmaLRussell Aug 29, 2024
b14978e
readme note about teardown order, and pin prisma versions
EmmaLRussell Aug 29, 2024
68a0c87
Merge branch 'jidea-59-dockerise-web-app' of github.com:jameel-instit…
EmmaLRussell Aug 29, 2024
3735157
merge with main
EmmaLRussell Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/docker-e2e.yml
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 tag
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved
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
39 changes: 0 additions & 39 deletions .github/workflows/playwright.yml

This file was deleted.

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,15 @@ npm run preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

# Docker

There are Dockerfiles for both the web app (in `/docker`) and the database (in `/db`).

To run the app in docker:
- `./run-dev-dependencies`
- `./docker/build`
- `./docker/run`

This will build and run the app container, exposing port 3000, so you should be able to access the web app at
http://localhost:3000 as you can when running locally outside docker.
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions db/scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
set -euxo pipefail

HERE=$(dirname $0)
. $HERE/common
. $HERE/../../docker/common

PACKAGE_ROOT=$(realpath $HERE/..)

docker build \
-t "$TAG_SHA" \
-t "$TAG_BRANCH" \
-t "$DB_TAG_SHA" \
-t "$DB_TAG_BRANCH" \
$PACKAGE_ROOT
21 changes: 0 additions & 21 deletions db/scripts/common

This file was deleted.

6 changes: 6 additions & 0 deletions db/scripts/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/../../docker/common

docker push "$DB_TAG_SHA"
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions db/scripts/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
set -euxo pipefail

HERE=$(dirname $0)
. $HERE/common
. $HERE/../../docker/common

docker run --rm -d \
--network=bridge \
--name daedalus-web-app-db \
-p 5432:5432 \
"$TAG_BRANCH"
"$DB_TAG_SHA"
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:20

ARG PORT=3000

ENV NODE_ENV=production

WORKDIR /src

COPY . .
RUN npm install --production=false
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved

# Generate the prisma client code
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"]
9 changes: 9 additions & 0 deletions docker/build
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 \
.
23 changes: 23 additions & 0 deletions docker/common
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}"
6 changes: 6 additions & 0 deletions docker/push
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"
10 changes: 10 additions & 0 deletions docker/push-branch-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
et -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"
14 changes: 14 additions & 0 deletions docker/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/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).
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved
docker run -d \
--name "$APP_IMAGE_NAME" \
--network=daedalus \
-p 3000:3000 \
--env-file env.docker \
"$APP_TAG_SHA"
2 changes: 2 additions & 0 deletions env.docker
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/
david-mears-2 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading