Skip to content

Commit

Permalink
ci: 🔧 Add Docker configuration files and Dockerfile for building and …
Browse files Browse the repository at this point in the history
…running the app
  • Loading branch information
edwinhern committed Apr 6, 2024
1 parent c97ae05 commit a00cadc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
25 changes: 25 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Image CI

on:
push:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_Token }}

- name: Build the Docker image
run: docker build . --file Dockerfile --tag ghcr.io/${{ github.repository }}:latest

- name: Push the Docker image
run: docker push ghcr.io/${{ github.repository }}:latest
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Stage 1: Building the app
FROM node:18-alpine AS builder

# Set the working directory in the Docker container
WORKDIR /app

# Copy the package.json and package-lock.json (or yarn.lock) files
COPY package*.json ./
# If you're using Yarn, uncomment the next line and remove the COPY command above
# COPY package.json yarn.lock ./

# Install dependencies
RUN npm ci
# For Yarn, use the following command instead
# RUN yarn install

# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .

# Build the Next.js application
RUN npm run build
# For Yarn, use the following command instead
# RUN yarn build

# Stage 2: Run the app
FROM node:18-alpine AS runner
WORKDIR /app

# Copy the build output from the builder stage
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

# Expose the port Next.js runs on
EXPOSE 3000

# Command to run the app
CMD ["npm", "start"]
# For Yarn, use the following command instead
# CMD ["yarn", "start"]

0 comments on commit a00cadc

Please sign in to comment.