Skip to content

Commit

Permalink
[CICD] add Github Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
hoban4336 committed May 27, 2024
1 parent f4a0f0b commit d1b7ce3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Next.js Docker Build 🍃

# triggers ci cd when you push code to any branch
on:
push:
branches: [ "develop" ]
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
environment: dev
env:
image_name: ${{ secrets.DOCKER_REPO }}/docker/711-front
image_tag: ${{ github.sha }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Building Docker Image
run: |
docker login ${{ secrets.DOCKER_REPO }} -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ env.image_name }}:${{ env.image_tag }} -t ${{ env.image_name }}:latest .
docker push ${{ env.image_name }}:${{ env.image_tag }}
docker push ${{ env.image_name }}:latest
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat python3 build-base
WORKDIR /app
COPY package.json ./
RUN yarn install --frozen-lockfile
RUN rm -rf ./.next/cache

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build
RUN yarn install --frozen-lockfile --production
RUN rm -rf ./.next/cache

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
ENV SHOULD_PROFILE=true
ENV SHOULD_TRACE=true

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./next.config.js

USER nextjs

EXPOSE 3000

CMD ["yarn", "start"]

0 comments on commit d1b7ce3

Please sign in to comment.