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.
This commit is contained in:
google-labs-jules[bot] 2025-06-23 16:15:46 +00:00
parent 13817a5ff8
commit 21bdfb4e14
2 changed files with 69 additions and 0 deletions

41
apps/web/Dockerfile Normal file
View File

@ -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"]

View File

@ -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: