From 21bdfb4e1407c026032ce59410b712e8cc3eb2d3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:15:46 +0000 Subject: [PATCH] feat: Add Docker configuration for local development This commit introduces Docker support for the OpenCut application. - Adds a `Dockerfile` for the `apps/web` Next.js application, using a multi-stage build with `bun`. - Updates `docker-compose.yaml` to include the `web` service, along with existing `db` (PostgreSQL) and `redis` services. - Configures dependencies between services and sets up environment variables. - Creates an `apps/web/.env` file based on the example, tailored for the Docker environment. These changes allow developers to easily set up and run the entire application stack using Docker Compose. --- apps/web/Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 28 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 apps/web/Dockerfile diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile new file mode 100644 index 00000000..9b337bdf --- /dev/null +++ b/apps/web/Dockerfile @@ -0,0 +1,41 @@ +# 1. Install dependencies only when needed +FROM oven/bun:1 AS deps +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json bun.lockb* ./ +RUN bun install --frozen-lockfile + +# 2. Rebuild the source code only when needed +FROM oven/bun:1 AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN bun run build + +# 3. Production image, copy all the files and run next +FROM oven/bun:1 AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +COPY --from=builder /app/public ./public +COPY --from=builder --chown=bun:bun /app/.next/standalone ./ +COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static + +EXPOSE 3000 + +ENV PORT 3000 +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/docker-compose.yaml b/docker-compose.yaml index c1c61a47..85a749b6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -42,6 +42,34 @@ services: timeout: 10s retries: 5 start_period: 10s + depends_on: + - redis + + web: + build: + context: ./apps/web + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + # Example environment variables - these should be tailored + # using apps/web/.env.example as a guide + NEXT_PUBLIC_DATABASE_URL: "postgresql://opencut:opencutthegoat@db:5432/opencut" + NEXT_PUBLIC_REDIS_URL: "redis://redis:6379" + NEXT_PUBLIC_UPSTASH_REDIS_REST_URL: "http://serverless-redis-http:8079" + NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN: "example_token" + # Add other necessary environment variables from .env.example + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + serverless-redis-http: + condition: service_healthy + volumes: + - ./apps/web:/app # Optional: for development to reflect code changes without rebuilding + - /app/node_modules # Ensure node_modules in container is used + - /app/.next # Ensure .next in container is used volumes: postgres_data: