From 1cf801e663f114fd8f50553759207b25ec8e9337 Mon Sep 17 00:00:00 2001 From: Om Lanke Date: Thu, 25 Sep 2025 14:25:29 +0530 Subject: [PATCH] dockerize properly --- .gitignore | 1 + apps/admin/Dockerfile | 19 +++++++++++++++---- apps/admin/package.json | 4 ++-- apps/student/Dockerfile | 20 ++++++++++++++++---- apps/student/package.json | 4 ++-- docker-compose.yml | 40 +++++++++++++++++++-------------------- 6 files changed, 56 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index a5bdd00..c94fcef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ node_modules .pnp.js # Local env files +docker.env .env .env.local .env.development.local diff --git a/apps/admin/Dockerfile b/apps/admin/Dockerfile index d0ec5e7..7d5f137 100644 --- a/apps/admin/Dockerfile +++ b/apps/admin/Dockerfile @@ -15,21 +15,32 @@ COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./ COPY apps/admin/package.json ./apps/admin/ COPY packages/db/package.json ./packages/db/ COPY packages/ui/package.json ./packages/ui/ +COPY packages/eslint-config/package.json ./packages/eslint-config/ +COPY packages/typescript-config/package.json ./packages/typescript-config/ -# Install dependencies +# Install dependencies (including devDependencies for build process) RUN pnpm install --frozen-lockfile # Rebuild the source code only when needed FROM base AS builder +RUN apk update && apk add --no-cache libc6-compat +RUN corepack enable && corepack prepare pnpm@latest --activate WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +# Copy environment file for build process and create .env for dotenv-cli +COPY docker.env ./docker.env +COPY docker.env ./.env + # Set environment variables for build ENV NEXT_TELEMETRY_DISABLED 1 ENV NODE_ENV production -# Build the application +# Ensure devDependencies are available during build (needed for PostCSS plugins) +RUN pnpm install --frozen-lockfile + +# Build the application with environment variables RUN pnpm turbo run build --filter=admin... # Production image, copy all the files and run next @@ -53,9 +64,9 @@ RUN chown nextjs:nodejs .next USER nextjs -EXPOSE 3001 +EXPOSE 9001 -ENV PORT 3001 +ENV PORT 9001 ENV HOSTNAME "0.0.0.0" # server.js is created by next build from the standalone output diff --git a/apps/admin/package.json b/apps/admin/package.json index 189517d..b107c0b 100644 --- a/apps/admin/package.json +++ b/apps/admin/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "dotenv -e ../../.env -- next dev --turbopack -p 3001", + "dev": "dotenv -e ../../.env -- next dev --turbopack -p 9001", "build": "dotenv -e ../../.env -- next build", - "start": "dotenv -e ../../.env -- next start -p 3001", + "start": "dotenv -e ../../.env -- next start -p 9001", "lint": "next lint", "lint:fix": "next lint --fix", "typecheck": "tsc --noEmit" diff --git a/apps/student/Dockerfile b/apps/student/Dockerfile index 45adef3..755c53e 100644 --- a/apps/student/Dockerfile +++ b/apps/student/Dockerfile @@ -15,21 +15,32 @@ COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./ COPY apps/student/package.json ./apps/student/ COPY packages/db/package.json ./packages/db/ COPY packages/ui/package.json ./packages/ui/ +COPY packages/eslint-config/package.json ./packages/eslint-config/ +COPY packages/typescript-config/package.json ./packages/typescript-config/ -# Install dependencies +# Install dependencies (including devDependencies for build process) RUN pnpm install --frozen-lockfile # Rebuild the source code only when needed FROM base AS builder +RUN apk update && apk add --no-cache libc6-compat +RUN corepack enable && corepack prepare pnpm@latest --activate WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +# Copy environment file for build process and create .env for dotenv-cli +COPY docker.env ./docker.env +COPY docker.env ./.env + # Set environment variables for build ENV NEXT_TELEMETRY_DISABLED 1 ENV NODE_ENV production -# Build the application +# Ensure devDependencies are available during build (needed for PostCSS plugins) +RUN pnpm install --frozen-lockfile + +# Build the application with environment variables RUN pnpm turbo run build --filter=student... # Production image, copy all the files and run next @@ -38,6 +49,7 @@ WORKDIR /app ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1 +ENV ADMIN_DOMAIN "http://admin:9001" RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -53,9 +65,9 @@ RUN chown nextjs:nodejs .next USER nextjs -EXPOSE 3000 +EXPOSE 9000 -ENV PORT 3000 +ENV PORT 9000 ENV HOSTNAME "0.0.0.0" # server.js is created by next build from the standalone output diff --git a/apps/student/package.json b/apps/student/package.json index e706a7a..523fedf 100644 --- a/apps/student/package.json +++ b/apps/student/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "dotenv -e ../../.env -- next dev --turbopack -p 3000", + "dev": "dotenv -e ../../.env -- next dev --turbopack -p 9000", "build": "dotenv -e ../../.env -- next build", - "start": "dotenv -e ../../.env -- next start -p 3000", + "start": "dotenv -e ../../.env -- next start -p 9000", "lint": "next lint", "lint:fix": "next lint --fix", "typecheck": "tsc --noEmit" diff --git a/docker-compose.yml b/docker-compose.yml index 36f16b5..15b06a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,21 +7,21 @@ services: context: . dockerfile: apps/student/Dockerfile ports: - - "3000:3000" + - "9000:9000" environment: - NODE_ENV=production - - PORT=3000 + - PORT=9000 - HOSTNAME=0.0.0.0 # Add your environment variables here - # env_file: - # - .env + env_file: + - docker.env restart: unless-stopped - healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s + # healthcheck: + # test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9000/api/health"] + # interval: 30s + # timeout: 10s + # retries: 3 + # start_period: 40s # Admin application admin: @@ -29,21 +29,21 @@ services: context: . dockerfile: apps/admin/Dockerfile ports: - - "3001:3001" + - "9001:9001" environment: - NODE_ENV=production - - PORT=3001 + - PORT=9001 - HOSTNAME=0.0.0.0 # Add your environment variables here - # env_file: - # - .env + env_file: + - docker.env restart: unless-stopped - healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3001/api/health"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s + # healthcheck: + # test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9001/api/health"] + # interval: 30s + # timeout: 10s + # retries: 3 + # start_period: 40s # Database (if you need one) # postgres: