Skip to content

Commit 8bba30e

Browse files
committed
Initial Docker and docker compose setup
1 parent fd94a32 commit 8bba30e

11 files changed

Lines changed: 344 additions & 99 deletions

File tree

apps/webapp/Dockerfile

Lines changed: 0 additions & 67 deletions
This file was deleted.

apps/webapp/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"format": "prettier --write .",
1212
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
1313
"start": "cross-env NODE_ENV=production node --max-old-space-size=8192 ./build/server.js",
14-
"docker:build": "cd ../.. && docker build -t trigger-webapp -f ./apps/webapp/Dockerfile .",
1514
"test": "vitest run",
1615
"test:cov": "vitest run --coverage",
1716
"test:e2e:dev": "start-server-and-test dev http://localhost:3000 \"npx cypress open\"",
@@ -238,4 +237,4 @@
238237
"engines": {
239238
"node": ">=16.0.0"
240239
}
241-
}
240+
}

apps/webapp/prisma/seed.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ async function seedIntegrationAuthMethods() {
6666

6767
async function seed() {
6868
await seedIntegrationAuthMethods();
69+
70+
// TODO: extract this into a separate file and put it behind some kind of env var
6971
// Create a user, organization, and project
7072
const user = await prisma.user.upsert({
7173
where: {

docker-compose.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

docker/.env.example

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LOGIN_ORIGIN=http://localhost:3000
2+
APP_ORIGIN=http://localhost:3000
3+
4+
# Encryption key that will be used to encrypt magic link tokens
5+
MAGIC_LINK_SECRET=secret
6+
# Encryption key that will be used to encrypt session cookies
7+
SESSION_SECRET=secret
8+
9+
POSTGRES_USER=postgres
10+
POSTGRES_PASSWORD=postgres
11+
POSTGRES_DB=postgres
12+
DATABASE_HOST=database:5432
13+
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
14+
15+
# Github sign in OAUTH client id and secret
16+
GITHUB_CLIENT_ID=
17+
GITHUB_SECRET=
18+
19+
# E-mail settings
20+
FROM_EMAIL=
21+
REPLY_TO_EMAIL=
22+
RESEND_API_KEY=
23+
24+
NODE_ENV=production

docker/Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM node:18 AS pruner
2+
3+
WORKDIR /triggerdotdev
4+
5+
COPY . .
6+
RUN npx turbo prune --scope=webapp --docker
7+
RUN find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
8+
9+
# Base strategy to have layer caching
10+
FROM node:18 AS base
11+
RUN apt-get update && apt-get install -y openssl
12+
WORKDIR /triggerdotdev
13+
COPY .gitignore .gitignore
14+
COPY --from=pruner /triggerdotdev/out/json/ .
15+
COPY --from=pruner /triggerdotdev/out/pnpm-lock.yaml ./pnpm-lock.yaml
16+
COPY --from=pruner /triggerdotdev/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
17+
18+
## Dev deps
19+
FROM base AS dev-deps
20+
WORKDIR /triggerdotdev
21+
# Corepack is used to install pnpm
22+
RUN corepack enable
23+
ENV NODE_ENV development
24+
RUN pnpm install --ignore-scripts --no-frozen-lockfile
25+
26+
## Production deps
27+
FROM base AS production-deps
28+
WORKDIR /triggerdotdev
29+
# Corepack is used to install pnpm
30+
RUN corepack enable
31+
ENV NODE_ENV production
32+
RUN pnpm install --prod --no-frozen-lockfile
33+
COPY --from=pruner /triggerdotdev/packages/database/prisma/schema.prisma /triggerdotdev/packages/database/prisma/schema.prisma
34+
RUN pnpx prisma generate --schema /triggerdotdev/packages/database/prisma/schema.prisma
35+
36+
## Builder (builds the webapp)
37+
FROM base AS builder
38+
WORKDIR /triggerdotdev
39+
# Corepack is used to install pnpm
40+
RUN corepack enable
41+
COPY --from=pruner /triggerdotdev/out/full/ .
42+
COPY --from=dev-deps /triggerdotdev/ .
43+
COPY turbo.json turbo.json
44+
COPY docker/scripts ./scripts
45+
RUN chmod +x ./scripts/entrypoint.sh
46+
RUN pnpm run generate
47+
RUN pnpm run build --filter=webapp...
48+
49+
# Runner
50+
FROM node:18 AS runner
51+
RUN apt-get update && apt-get install -y openssl
52+
WORKDIR /triggerdotdev
53+
RUN corepack enable
54+
ENV NODE_ENV production
55+
56+
COPY --from=pruner /triggerdotdev/out/full/ .
57+
COPY --from=production-deps /triggerdotdev .
58+
COPY --from=builder /triggerdotdev/apps/webapp/build/server.js ./apps/webapp/build/server.js
59+
COPY --from=builder /triggerdotdev/apps/webapp/build ./apps/webapp/build
60+
COPY --from=builder /triggerdotdev/apps/webapp/public ./apps/webapp/public
61+
COPY --from=builder /triggerdotdev/scripts ./scripts
62+
63+
CMD ["./scripts/entrypoint.sh"]

docker/compose-without-app.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3"
2+
3+
volumes:
4+
database-data:
5+
6+
networks:
7+
app_network:
8+
external: false
9+
10+
services:
11+
database:
12+
container_name: database
13+
image: postgres:latest
14+
restart: always
15+
volumes:
16+
- database-data:/var/lib/postgresql/data/
17+
env_file: .env
18+
networks:
19+
- app_network
20+
ports:
21+
- 5432:5432

docker/compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: "3"
2+
3+
volumes:
4+
database-data:
5+
6+
networks:
7+
app_network:
8+
external: false
9+
10+
services:
11+
webapp:
12+
build:
13+
context: ../
14+
dockerfile: docker/Dockerfile
15+
ports:
16+
- 3000:3000
17+
depends_on:
18+
- database
19+
env_file: .env
20+
environment:
21+
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
22+
networks:
23+
- app_network
24+
25+
database:
26+
container_name: database
27+
image: postgres:latest
28+
restart: always
29+
volumes:
30+
- database-data:/var/lib/postgresql/data/
31+
env_file: .env
32+
networks:
33+
- app_network
34+
ports:
35+
- 5432:5432

docker/scripts/entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
set -x
3+
4+
scripts/wait-for-it.sh ${DATABASE_HOST}:5432 -- echo "database is up"
5+
npx prisma migrate deploy --schema /triggerdotdev/packages/database/prisma/schema.prisma
6+
npx ts-node@latest --transpile-only /triggerdotdev/apps/webapp/prisma/seed.ts
7+
npx turbo run start

0 commit comments

Comments
 (0)