aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.dockerignore7
-rw-r--r--Dockerfile117
-rw-r--r--docker-compose.yml39
-rw-r--r--packages/web/Dockerfile57
-rw-r--r--packages/web/next.config.mjs1
-rw-r--r--packages/workers/package.json1
6 files changed, 165 insertions, 57 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..c5500558
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,7 @@
+Dockerfile
+.dockerignore
+node_modules
+npm-debug.log
+README.md
+.next
+.git
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..668c6a46
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,117 @@
+FROM node:21-alpine AS base
+
+# Install dependencies only when needed
+FROM base AS deps
+# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
+RUN apk add --no-cache libc6-compat \
+ make \
+ g++ \
+ py3-pip \
+ linux-headers
+WORKDIR /app
+
+# Install dependencies based on the preferred package manager
+COPY package.json yarn.lock .yarnrc.yml ./
+COPY packages/web/package.json ./packages/web/package.json
+COPY packages/db/package.json ./packages/db/package.json
+COPY packages/shared/package.json ./packages/shared/package.json
+COPY packages/workers/package.json ./packages/workers/package.json
+COPY packages/browser-extension/package.json ./packages/browser-extension/package.json
+RUN corepack enable && \
+ yarn install --immutable && \
+ cd packages/web && \
+ yarn install --immutable
+
+################# The Web App ##############
+
+# Rebuild the source code only when needed
+FROM base AS web_builder
+WORKDIR /app
+COPY --from=deps /app/node_modules ./node_modules
+COPY packages packages
+COPY package.json yarn.lock .yarnrc.yml .
+
+ENV NEXT_TELEMETRY_DISABLED 1
+
+RUN cd packages/db && \
+ yarn prisma generate
+
+RUN corepack enable && \
+ cd packages/web/ && \
+ yarn run build
+
+FROM base AS web
+WORKDIR /app
+
+ENV NODE_ENV production
+ENV NEXT_TELEMETRY_DISABLED 1
+
+# RUN addgroup --system --gid 1001 nodejs
+# RUN adduser --system --uid 1001 nextjs
+
+COPY --from=web_builder --chown=node:node /app/packages/web/.next/standalone ./
+COPY --from=web_builder /app/packages/web/public ./packages/web/public
+
+# Set the correct permission for prerender cache
+RUN mkdir -p ./package/web/.next
+RUN chown node:node ./packages/web/.next
+
+# Automatically leverage output traces to reduce image size
+# https://nextjs.org/docs/advanced-features/output-file-tracing
+COPY --from=web_builder --chown=node:node /app/packages/web/.next/static ./packages/web/.next/static
+
+WORKDIR /app/packages/web
+
+USER node
+
+EXPOSE 3000
+
+ENV PORT 3000
+# set hostname to localhost
+ENV HOSTNAME "0.0.0.0"
+
+# server.js is created by next build from the standalone output
+# https://nextjs.org/docs/pages/api-reference/next-config-js/output
+CMD ["node", "server.js"]
+
+
+################# Db migrations ##############
+
+FROM base AS db
+WORKDIR /app
+
+COPY --from=deps /app/node_modules ./node_modules
+COPY packages packages
+COPY package.json yarn.lock .yarnrc.yml .
+
+
+RUN cd packages/db && \
+ yarn prisma generate
+
+WORKDIR /app/packages/db
+USER node
+
+CMD ["yarn", "prisma", "migrate", "deploy"]
+# CMD ["ls", "-la", "/data"]
+
+
+################# The workers ##############
+
+FROM base AS workers
+WORKDIR /app
+
+# Install chromium needed for puppeteer
+RUN apk add chromium
+env PUPPETEER_EXECUTABLE_PATH "/usr/bin/chromium-browser"
+
+COPY --from=deps /app/node_modules ./node_modules
+COPY packages packages
+COPY package.json yarn.lock .yarnrc.yml .
+
+RUN cd packages/db && \
+ yarn prisma generate
+
+WORKDIR /app/packages/workers
+USER node
+
+CMD ["yarn", "run", "start:prod"]
diff --git a/docker-compose.yml b/docker-compose.yml
index 55bb38ff..b2f6d156 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,11 +1,50 @@
version: "3.8"
name: remember
services:
+ web:
+ build:
+ context: .
+ target: web
+ volumes:
+ - data:/data
+ ports:
+ - 3000:3000
+ env_file:
+ - "packages/web/.env.local"
+ environment:
+ REDIS_HOST: redis
+ DATABASE_URL: "file:/data/db.db"
+ depends_on:
+ migration:
+ condition: service_completed_successfully
redis:
image: redis:7.2-alpine
ports:
- 6379:6379
volumes:
- redis:/data
+ workers:
+ build:
+ context: .
+ target: workers
+ volumes:
+ - data:/data
+ env_file:
+ - "packages/workers/.env"
+ environment:
+ REDIS_HOST: redis
+ DATABASE_URL: "file:/data/db.db"
+ depends_on:
+ migration:
+ condition: service_completed_successfully
+ migration:
+ build:
+ context: .
+ target: db
+ environment:
+ DATABASE_URL: "file:/data/db.db"
+ volumes:
+ - data:/data
volumes:
redis:
+ data:
diff --git a/packages/web/Dockerfile b/packages/web/Dockerfile
deleted file mode 100644
index 30a46bd3..00000000
--- a/packages/web/Dockerfile
+++ /dev/null
@@ -1,57 +0,0 @@
-FROM oven/bun:1.0-alpine AS base
-
-# Install dependencies only when needed
-FROM base AS deps
-# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
-# RUN apk add --no-cache libc6-compat
-WORKDIR /app
-
-# Install dependencies based on the preferred package manager
-COPY package.json bun.lockb ./
-RUN bun install --frozen-lockfile
-
-# Rebuild the source code only when needed
-FROM base AS builder
-WORKDIR /app
-COPY --from=deps /app/node_modules ./node_modules
-COPY . .
-
-ENV NODE_ENV production
-
-ENV NEXT_TELEMETRY_DISABLED 1
-
-RUN bun run build
-
-# Production image, copy all the files and run next
-FROM base AS runner
-WORKDIR /app
-
-ENV NODE_ENV production
-
-ENV NEXT_TELEMETRY_DISABLED 1
-
-RUN addgroup --system --gid 1001 nodejs
-RUN adduser --system --uid 1001 nextjs
-
-COPY --from=builder /app/public ./public
-
-# Set the correct permission for prerender cache
-RUN mkdir .next
-RUN chown nextjs:nodejs .next
-
-# Automatically leverage output traces to reduce image size
-# https://nextjs.org/docs/advanced-features/output-file-tracing
-COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
-COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
-
-USER nextjs
-
-EXPOSE 3000
-
-ENV PORT 3000
-# set hostname to localhost
-ENV HOSTNAME "0.0.0.0"
-
-# server.js is created by next build from the standalone output
-# https://nextjs.org/docs/pages/api-reference/next-config-js/output
-CMD ["node", "server.js"]
diff --git a/packages/web/next.config.mjs b/packages/web/next.config.mjs
index f2ed7754..3ebca31a 100644
--- a/packages/web/next.config.mjs
+++ b/packages/web/next.config.mjs
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
+ output: "standalone",
async headers() {
return [
{
diff --git a/packages/workers/package.json b/packages/workers/package.json
index 4c012143..e20dc7f2 100644
--- a/packages/workers/package.json
+++ b/packages/workers/package.json
@@ -28,6 +28,7 @@
},
"scripts": {
"start": "ts-node index.ts",
+ "start:prod": "ts-node -T index.ts",
"typecheck": "tsc --noEmit"
}
}