Skip to content

Commit

Permalink
feat: add docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul15irsyad committed Oct 25, 2024
1 parent 14b3928 commit e700ecb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Stage 1: Install dependencies and build the app
FROM node:20 AS builder

# Set working directory
WORKDIR /app

# Copy package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile --ignore-scripts

# Copy the rest of the application code
COPY . .

# Build the Next.js app
RUN yarn build

# Stage 2: Run the app with a smaller image
FROM builder AS runner

# Set working directory
WORKDIR /app

# Install only production dependencies
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./

# Copy the built application from the builder stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public

# Expose the port on which the app runs
EXPOSE 3000

# Set environment variables (optional)
ENV NODE_ENV=production

# Run the app
CMD ["yarn", "start"]
51 changes: 51 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: portfolio

services:
app:
container_name: portfolio-app
build:
context: .
dockerfile: Dockerfile
ports:
- '4002:3000'
environment:
- NEXT_PUBLIC_ENV=local
- NEXT_PUBLIC_BASE_URL="http://localhost:4002"
- NEXT_PUBLIC_GA_MEASUREMENT_ID=GA_MEASUREMENT_ID
- NEXT_PUBLIC_EXPERIMENTAL=true
- DATABASE_URL=postgres://postgres:Qwerty123@database:5432/portfolio
- REDIS_URL=redis://cache:6379/1
- SENTRY_DSN=https://d16140d5bf02f802b5d2134985cf176c@o4506720354304000.ingest.us.sentry.io/4507581075619840
depends_on:
- database
- cache
networks:
- portfolio-network

database:
container_name: portfolio-db
image: postgres:latest
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: Qwerty123
POSTGRES_DB: portfolio
networks:
- portfolio-network
volumes:
- portfolio-postgres:/var/lib/postgresql/data

cache:
container_name: portfolio-redis
image: redis:latest
restart: unless-stopped
networks:
- portfolio-network

networks:
portfolio-network:
driver: bridge

volumes:
portfolio-postgres:
driver: local
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"dev": "next dev -p 4000",
"build": "npx prisma generate && next build",
"build": "next build",
"postbuild": "next-sitemap",
"postinstall": "npx prisma generate",
"start": "next start",
Expand Down

0 comments on commit e700ecb

Please sign in to comment.