Skip to content

Commit cffa34d

Browse files
feat: add Docker support with Dockerfile, docker-compose, and GitHub Actions workflow
1 parent 9ed6f44 commit cffa34d

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
npm-debug.log
3+
.DS_Store
4+
.git
5+
.gitignore
6+
.env

.github/workflows/docker-image.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build Docker Image
2+
3+
on:
4+
push:
5+
branches: ["prod", "staging"]
6+
pull_request:
7+
branches: ["prod"]
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Login to GitHub Container Registry
21+
uses: docker/login-action@v1
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Build and Push Docker Image
28+
run: |
29+
docker build . --tag ghcr.io/upayanmazumder/papers-codechef:latest --build-arg NODE_ENV=production
30+
docker push ghcr.io/upayanmazumder/papers-codechef:latest

Dockerfile

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11
# Step 1: Build stage
2-
FROM node:22-alpine AS builder
2+
FROM node:23-alpine AS builder
3+
4+
# Install dependencies required for building native modules
5+
RUN apk add --no-cache \
6+
python3 \
7+
make \
8+
g++ \
9+
pkgconfig \
10+
pixman-dev \
11+
cairo-dev \
12+
pango-dev \
13+
glib-dev \
14+
jpeg-dev \
15+
giflib-dev
16+
17+
# Install pnpm globally
18+
RUN npm install -g pnpm
319

420
# Set the working directory
521
WORKDIR /app
622

7-
# Copy package.json and package-lock.json
8-
COPY package*.json ./
23+
# Copy package.json and pnpm-lock.yaml
24+
COPY package.json pnpm-lock.yaml ./
925

10-
# Install dependencies
11-
RUN npm install
26+
# Install dependencies using pnpm
27+
RUN pnpm install --frozen-lockfile
1228

1329
# Copy the rest of the application code
1430
COPY . .
1531

1632
# Build the application
17-
RUN npm run build
33+
RUN pnpm run build
1834

1935
# Step 2: Production stage
20-
FROM node:22-alpine
36+
FROM node:23-alpine
37+
38+
# Install pnpm globally
39+
RUN npm install -g pnpm
2140

2241
# Set the working directory
2342
WORKDIR /app
2443

44+
# Set NODE_ENV to production
45+
ENV NODE_ENV=production
46+
2547
# Copy only the built application and necessary files from the builder stage
26-
COPY --from=builder /app/package*.json ./
48+
COPY --from=builder /app/package.json ./
49+
COPY --from=builder /app/pnpm-lock.yaml ./
2750
COPY --from=builder /app/node_modules ./node_modules
2851
COPY --from=builder /app/.next ./.next
2952
COPY --from=builder /app/public ./public
@@ -32,4 +55,4 @@ COPY --from=builder /app/public ./public
3255
EXPOSE 3000
3356

3457
# Define the command to start the application
35-
CMD ["npm", "start"]
58+
CMD ["pnpm", "start"]

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
backend:
3+
image: ghcr.io/upayanmazumder/papers-codechef:latest
4+
build: .

0 commit comments

Comments
 (0)