From 3590ef53e8616f67287dcb4c67468dc45dc8ce6b Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:58:55 +0100 Subject: [PATCH] feat(Docker): add Dockerfile and docker-compose for app and services setup --- Dockerfile | 25 ++++++++++++++++++ docker-compose.yml | 65 ++++++++++++++++++++++++++++++++++++++++++++++ example.env | 9 ++++--- next.config.mjs | 2 ++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1aae5d9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM oven/bun:alpine AS base + +# Stage 1: Install dependencies +FROM base AS deps +WORKDIR /app +COPY package.json bun.lockb ./ +RUN bun install + +# Stage 2: Build the application +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN bun run build + +# Stage 3: Production server +FROM base AS runner +WORKDIR /app +ENV NODE_ENV=production +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +EXPOSE 3000 +CMD ["bun", "run", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..326b80a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +services: + pocketbase: + image: ghcr.io/muchobien/pocketbase:latest + restart: unless-stopped + command: + - --encryptionEnv #optional + - ENCRYPTION #optional + environment: + ENCRYPTION: ${ENCRYPTION_SECRET} + ports: + - "3002:8090" + volumes: + - ./data/pb/data:/pb_data + - ./data/pb/public:/pb_public #optional + - ./data/pb/hooks:/pb_hooks #optional + healthcheck: #optional (recommended) since v0.10.0 + test: wget --no-verbose --tries=1 --spider http://localhost:8090/api/health || exit 1 + interval: 5s + timeout: 5s + retries: 5 + + umami: + image: ghcr.io/umami-software/umami:postgresql-latest + ports: + - "3001:3000" + environment: + DATABASE_URL: postgresql://umami:umami@umami-db:5432/umami + DATABASE_TYPE: postgresql + APP_SECRET: ${APP_SECRET} + depends_on: + umami-db: + condition: service_healthy + restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"] + interval: 5s + timeout: 5s + retries: 5 + + app: + build: . + ports: + - '3000:3000' + environment: + - NODE_ENV=production + - NEXT_PUBLIC_UMAMI_URL=${NEXT_PUBLIC_UMAMI_URL} + - NEXT_PUBLIC_UMAMI_TOKEN=${NEXT_PUBLIC_UMAMI_TOKEN} + - NEXT_PUBLIC_POCKETBASE_URL=${NEXT_PUBLIC_POCKETBASE_URL} + restart: unless-stopped + + umami-db: + image: postgres:15-alpine + environment: + POSTGRES_DB: umami + POSTGRES_USER: umami + POSTGRES_PASSWORD: umami + volumes: + - ./data/umami/data:/var/lib/postgresql/data + restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 5 + diff --git a/example.env b/example.env index 42a6af9..91c930b 100644 --- a/example.env +++ b/example.env @@ -1,3 +1,6 @@ -NEXT_PUBLIC_POCKETBASE_URL=https://pb-phs.fly.dev -NEXT_PUBLIC_ANALYTICS_URL= -NEXT_PUBLIC_ANALYTICS_TOKEN= \ No newline at end of file +NEXT_PUBLIC_POCKETBASE_URL=https://pocketbase.proxmoxve-scripts.com +NEXT_PUBLIC_ANALYTICS_URL=https://analytics.proxmoxve-scripts.com +NEXT_PUBLIC_ANALYTICS_TOKEN=b60d130323-1a11-4244-a1010-81d263c5c49a7 +APP_SECRET=faeziwezrdgsjibjahyusndwwpiwykgfhdjhysaidmtwywivmh +ENCRYPTION_SECRET=idtrkpcthrnirnqxkafbivyditqnxsnymrfpeqqsookzjyuvmz +NODE_ENV=production diff --git a/next.config.mjs b/next.config.mjs index c2fb590..03e3a80 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -14,6 +14,8 @@ const nextConfig = { ], }, + output: "standalone", + async rewrites() { return [ {