Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions .github/workflows/cd.yaml

This file was deleted.

25 changes: 17 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,23 @@ RUN adduser --system --uid 1001 nextjs
# Install wget for healthcheck
RUN apk add --no-cache wget

# Copy necessary files from builder
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma

# Set correct permissions
RUN chown -R nextjs:nodejs /app
# Copy necessary files from builder with correct ownership
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/prisma.config.ts ./prisma.config.ts
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodejs /app/pnpm-lock.yaml ./pnpm-lock.yaml

# Copy node_modules with Prisma from builder with correct ownership
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.bin/prisma ./node_modules/.bin/prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.bin/tsx ./node_modules/.bin/tsx
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.pnpm ./node_modules/.pnpm
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/dotenv ./node_modules/dotenv
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/tsx ./node_modules/tsx

USER nextjs

Expand Down
43 changes: 10 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
volumes:
- template-db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER}"]
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE_NAME}"]
interval: 5s
timeout: 5s
retries: 5
Expand Down Expand Up @@ -40,9 +40,16 @@ services:
- VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY}
- NEXTAUTH_URL=${NEXTAUTH_URL:-http://localhost:3000}
- AUTH_TRUST_HOST=${AUTH_TRUST_HOST:-true}
command: >
sh -c "
echo 'Running database migrations...' &&
./node_modules/.bin/prisma migrate deploy &&
echo 'Migrations completed, starting application...' &&
node server.js
"
depends_on:
template-migrate:
condition: service_completed_successfully
template-db:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1"]
interval: 10s
Expand All @@ -52,35 +59,5 @@ services:
profiles:
- production

# Database migration container (production only)
template-migrate:
build:
context: .
dockerfile: Dockerfile
target: builder
environment:
- DATABASE_URL=postgresql://${DATABASE_USER}:${DATABASE_PW}@template-db:5432/${DATABASE_NAME}
- DATABASE_PW=${DATABASE_PW}
- DATABASE_USER=${DATABASE_USER}
- DATABASE_NAME=${DATABASE_NAME}
- DATABASE_HOST=template-db
- DATABASE_PORT=5432
command: >
sh -c "
apk add --no-cache netcat-openbsd &&
echo 'Waiting for database to be ready...' &&
while ! nc -z template-db 5432; do
sleep 1
done &&
echo 'Database is ready, running migrations...' &&
pnpm exec prisma migrate deploy &&
echo 'Migrations completed successfully!'
"
depends_on:
template-db:
condition: service_healthy
profiles:
- production

volumes:
template-db-data: