diff --git a/.cline-context.md b/.cline-context.md index 9f1ff90..4681d44 100644 --- a/.cline-context.md +++ b/.cline-context.md @@ -24,7 +24,10 @@ - Added Export modal in Sidebar user popover menu supporting format selection, target list filtering, completed tasks inclusion toggle, and seamless Demo mode client-side Blob generation. - Added localized i18n strings for Export across English, Korean, and Japanese. - Migrated repository and commit history to self-hosted Gitea remote origin. - - Configured production multi-stage `Dockerfile` and automated Gitea Actions CI workflow (`.gitea/workflows/docker-build.yaml`) for building & pushing container images to Gitea Container Registry. + - Configured production multi-stage `Dockerfile` with standalone Next.js runner, Prisma CLI migrations support, and automated `docker-entrypoint.sh` startup script. + - Added `.dockerignore` for minimal context transfer and fast build times. + - Refined `docker-compose.yml` and `.env.example` to support prebuilt registry images (`CHECKFLOW_IMAGE`) and automated database migrations. + - Automated Gitea Actions CI workflow (`.gitea/workflows/docker-build.yaml`) for building & pushing container images to Gitea Container Registry. - Validated that `npm run lint` and `npm run build` execute with 0 errors and 0 warnings. - **Next Steps (Todo):** diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2737492 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,35 @@ +# Dependencies & Build Output +node_modules +.next +out + +# Git & Version Control +.git +.gitignore + +# Environment & Secret Files +.env +.env*.local +*.pem + +# Log Files +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# AI & Editor Contexts +.clinecontext +.cline-context.md +.clinerules +src/.clinerules +CLAUDE.md + +# Documentation & CI Workflows (not needed inside container image) +.gitea +docker-compose*.yml + +# Local Dev DBs +prisma/dev +prisma/*.db +prisma/*.db-journal diff --git a/.env.example b/.env.example index af25751..ccd331f 100644 --- a/.env.example +++ b/.env.example @@ -8,4 +8,7 @@ NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=change-this-to-a-random-string # Port to expose (default 3000) -PORT=3000 \ No newline at end of file +PORT=3000 + +# Container Registry Image (Optional, default: checkflow:latest) +# CHECKFLOW_IMAGE=gitea.example.com/username/checkflow:latest diff --git a/Dockerfile b/Dockerfile index 5ed4559..6d37cb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,16 +22,23 @@ ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs +# Copy runtime assets and standalone build COPY --from=builder --chown=nextjs:nodejs /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma +COPY --from=builder --chown=nextjs:nodejs /app/node_modules/prisma ./node_modules/prisma +COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json + +COPY --chown=nextjs:nodejs docker-entrypoint.sh ./docker-entrypoint.sh +RUN chmod +x ./docker-entrypoint.sh USER nextjs EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" +ENTRYPOINT ["./docker-entrypoint.sh"] CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml index 0cc4a26..3208bf8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,24 +17,16 @@ services: timeout: 5s retries: 5 - migrate: - build: . - container_name: checkflow-migrate - depends_on: - postgres: - condition: service_healthy - environment: - DATABASE_URL: postgresql://checkflow:${POSTGRES_PASSWORD:-changeme}@postgres:5432/checkflow - command: npx prisma migrate deploy - restart: "no" - app: - build: . + image: ${CHECKFLOW_IMAGE:-checkflow:latest} + build: + context: . + dockerfile: Dockerfile container_name: checkflow-app restart: unless-stopped depends_on: - migrate: - condition: service_completed_successfully + postgres: + condition: service_healthy ports: - "${PORT:-3000}:3000" environment: @@ -46,4 +38,4 @@ services: - ./prisma:/app/prisma volumes: - postgres_data: \ No newline at end of file + postgres_data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..27bc840 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +# Run Prisma database migrations if DATABASE_URL is set and not explicitly skipped +if [ -n "$DATABASE_URL" ] && [ "$SKIP_DB_MIGRATE" != "true" ]; then + echo "[CheckFlow] Checking and applying database migrations..." + if [ -f "./node_modules/prisma/build/index.js" ]; then + node ./node_modules/prisma/build/index.js migrate deploy --schema=./prisma/schema.prisma || echo "[CheckFlow] Warning: Prisma migration step skipped or encountered non-fatal error." + fi +fi + +exec "$@"