From d1b7ce358f953ef924dcb055f71b70cf247a30e7 Mon Sep 17 00:00:00 2001 From: ysyoo Date: Mon, 27 May 2024 12:55:13 +0900 Subject: [PATCH] [CICD] add Github Runner --- .github/workflows/build.yaml | 27 ++++++++++++++++++++++++ Dockerfile | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..367b83c --- /dev/null +++ b/.github/workflows/build.yaml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa0b94d --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file