Skip to content

Commit

Permalink
Merge pull request #1 from safeinsights/dockerize
Browse files Browse the repository at this point in the history
dockerize and deploy
  • Loading branch information
nathanstitt authored Oct 3, 2024
2 parents 513c8f2 + cd20799 commit 1199e9a
Show file tree
Hide file tree
Showing 29 changed files with 1,548 additions and 86 deletions.
35 changes: 35 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# .dockerignore
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
31 changes: 16 additions & 15 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ on:
branches: [main, master]
jobs:
all:
timeout-minutes: 60
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: docker/bake-action@master
with:
node-version: lts/*
- name: Install dependencies
run: npm i
- name: Lint
run: npm run lint
- name: Typecheck
run: npm run typecheck
- name: Unit Test
run: npm run test:unit
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm run test:e2e
push: false
load: true
files: |-
docker-compose.yml
.github/workflows/gh-docker-compse-cache.json
- name: Run docker compose
run: docker compose up postgres mgmnt-app --wait --detach --wait-timeout 60
- name: Run Specs
run: docker compose exec mgmnt-app npm run ci
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ vars.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/gh-docker-compse-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"target": {
"mgmnt-app": {
"cache-from": ["type=gha,scope=safeinsights/management-app/mgmnt-app"],
"cache-to": ["type=gha,mode=max,scope=safeinsights/management-app/mgmnt-app"],
"output": ["type=docker"]
}
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.idea
*.log
tmp/

.next/
test-results/
*.tern-port
Expand All @@ -15,3 +14,5 @@ yarn-error.log*
.eslintcache
coverage/
playwright-report/
.env
.parcel-cache
27 changes: 27 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:21-bookworm AS base

WORKDIR /app


COPY package.json package-lock.json ./

RUN npm install

RUN npx playwright install
RUN npx playwright install-deps

#COPY .gitignore .editorconfig next.config.mjs tsconfig.json kysely.config.ts .eslintrc.json .prettierrc.json .

# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
# Uncomment the following line to disable telemetry at run time
ENV NEXT_TELEMETRY_DISABLED=1

# for deploting the build version

# RUN bun next build
# and
# CMD bun next start

# OR for sart Next.js in development, comment above two lines and uncomment below line

CMD ["./bin/docker-dev-init"]
45 changes: 45 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM public.ecr.aws/docker/library/node:21-bookworm-slim AS base

# add aws-lambda-adapter extension
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter

RUN mkdir /app
WORKDIR /app

FROM base AS npm

COPY package.json package-lock.json* ./
RUN npm ci

FROM base AS builder

COPY . .

COPY --from=npm /app/node_modules ./node_modules

# disables nextjs telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV AWS_LWA_ENABLE_COMPRESSION=true

RUN npm run build

WORKDIR /app

FROM base AS release

ENV NODE_ENV=production
ENV PORT=8080
EXPOSE $PORT

COPY ./bin/lambda-server.sh ./run.sh

# copy static files and images from build
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
RUN ln -s /tmp/cache ./.next/cache


CMD ["./run.sh"]
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ The management app serves as an interface for researchers to submit and members

It’s responsible for:

* Researcher creates/modifies/deletes study
* Member is notified when a study proposal is submitted
* Researcher is notified when study is approved
* Member reviews/approves/denies study
* Reports study status in response to enclave's SetupApp requests

- Researcher creates/modifies/deletes study
- Member is notified when a study proposal is submitted
- Researcher is notified when study is approved
- Member reviews/approves/denies study
- Reports study status in response to enclave's SetupApp requests
14 changes: 14 additions & 0 deletions bin/docker-dev-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# this file is the entrypoint for the Dockerfile.dev
# and is used for local development

set -e

npm install

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

$SCRIPT_DIR/migrate-dev-db

npm run dev
7 changes: 7 additions & 0 deletions bin/lambda-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

[ ! -d '/tmp/cache' ] && mkdir -p /tmp/cache

exec node server.js
11 changes: 11 additions & 0 deletions bin/migrate-dev-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

TYPES=src/database/types.ts

npx kysely migrate:up

npx kysely-codegen --camel-case --dialect postgres --out-file $TYPES
npx prettier --write $TYPES
npx eslint --fix $TYPES
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
services:
postgres:
image: 'postgres:16'
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- mgmnt-app
environment:
- POSTGRES_USER=mgmnt
- POSTGRES_PASSWORD=mgmntpass
- POSTGRES_DB=mgmnt_dev
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U mgmnt -d mgmnt_dev']
interval: 10s
retries: 5
start_period: 30s
timeout: 10s
mgmnt-app:
container_name: mgmnt-app
depends_on:
postgres:
condition: service_healthy
restart: true
environment:
- CI=$CI
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
- CLERK_SECRET_KEY=$CLERK_SECRET_KEY
- E2E_CLERK_USER_USERNAME=$E2E_CLERK_USER_USERNAME
- E2E_CLERK_USER_PASSWORD=$E2E_CLERK_USER_PASSWORD
- DATABASE_URL=postgres://mgmnt:mgmntpass@postgres:5432/mgmnt_dev
build:
context: .
dockerfile: ./Dockerfile.dev
volumes:
- ./:/app/
- node_modules:/app/node_modules
restart: always
networks:
- mgmnt-app
ports:
- 3000:3000
healthcheck:
test: ['CMD-SHELL', 'curl -s http://localhost:3000/']
interval: 10s
retries: 5
start_period: 30s
timeout: 10s
networks:
mgmnt-app:
volumes:
pgdata:
node_modules:
9 changes: 9 additions & 0 deletions kysely.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'kysely-ctl'
import { dialect } from './src/database/dialect'

export default defineConfig({
dialect,
migrations: {
migrationFolder: 'src/database/migrations',
},
})
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
5 changes: 4 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createVanillaExtractPlugin } from '@vanilla-extract/next-plugin'

const withVanillaExtract = createVanillaExtractPlugin()

/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
output: 'standalone',
}

export default withVanillaExtract(nextConfig)
Loading

0 comments on commit 1199e9a

Please sign in to comment.