diff --git a/docker-compose.yml b/docker-compose.yml index ef26ff8..95962b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,8 @@ services: interval: 5s timeout: 5s retries: 5 + networks: + - app-network backend: build: @@ -32,20 +34,33 @@ services: depends_on: db: condition: service_healthy + networks: + - app-network + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + args: + - NEXT_PUBLIC_API_URL=http://backend:8000 + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - NEXT_PUBLIC_API_URL=http://backend:8000 + depends_on: + - backend + healthcheck: + test: ["CMD", "wget", "--spider", "http://localhost:3000"] + interval: 10s + timeout: 5s + retries: 3 + networks: + - app-network -# frontend: -# build: -# context: . -# dockerfile: frontend/Dockerfile -# volumes: -# - ./frontend:/app -# - /app/node_modules -# ports: -# - "3000:3000" -# environment: -# - NEXT_PUBLIC_API_URL=http://backend:8000 -# depends_on: -# - backend volumes: - postgres_data: \ No newline at end of file + postgres_data: + +networks: + app-network: + driver: bridge diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..f1c551f --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.next +*.log +.git +.env* +.dockerignore +Dockerfile \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..65e4b19 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Dependencies +FROM node:20-alpine AS deps +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci + +# Stage 2: Builder +FROM node:20-alpine AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NEXT_TELEMETRY_DISABLED 1 +RUN npm run build + +# Stage 3: Runner +FROM node:20-alpine 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 +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/frontend/entrypoint.sh b/frontend/entrypoint.sh new file mode 100644 index 0000000..d36e3f4 --- /dev/null +++ b/frontend/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Wait for backend to be ready +echo "Waiting for backend..." +until nc -z backend 8000; do + sleep 1 +done +echo "Backend is up!" + +# Start the Next.js application +exec "$@" \ No newline at end of file diff --git a/frontend/next.config.ts b/frontend/next.config.ts index e9ffa30..fb75eab 100644 --- a/frontend/next.config.ts +++ b/frontend/next.config.ts @@ -1,7 +1,16 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: 'standalone', + // Ensure we can connect to the backend in Docker + async rewrites() { + return [ + { + source: '/api/:path*', + destination: 'http://backend:8000/:path*', + }, + ]; + }, }; -export default nextConfig; +export default nextConfig; \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 4222c3f..91e81f8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,10 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "docker:build": "docker build -t eventspace-frontend .", + "docker:run": "docker run -p 3000:3000 eventspace-frontend" + }, "dependencies": { "react": "^19.0.0", diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts new file mode 100644 index 0000000..2edc906 --- /dev/null +++ b/frontend/src/types/api.d.ts @@ -0,0 +1,7 @@ +declare namespace API { + interface ErrorResponse { + detail: string; + } + + // Add more types as you develop your API +} \ No newline at end of file