diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..72e9aa4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..04dbbc8 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..46fa7b8 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file