-
Notifications
You must be signed in to change notification settings - Fork 1
feat: ci/cd 구성 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: ci/cd 구성 #12
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b9fbe7a
feat: docker이미지 빌드 추가
caseBread 57dbdf8
feat : deploy workflow 추가
caseBread c5f4e1c
test : 테스트용 코드수정
caseBread d223531
fix : test용코드추가
caseBread a438302
fix: 버전수정
caseBread 9b1303f
fix : run_install 활성화
caseBread f61c6ad
fix : node버전 수정
caseBread 1f3d811
fix : port수정
caseBread 55fdaf9
fix : port변경
caseBread d52fab1
fix : TODO 수정
caseBread a0fc918
Merge branch 'main' into feature/cicd
caseBread 3eabc7b
fix : prettier 수정
caseBread File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| name: deploy | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| app-build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_TOKEN }} | ||
|
|
||
| - name: Build & Push | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| platforms: linux/amd64 | ||
| tags: | | ||
| ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGENAME }}:${{ github.run_id }} | ||
| ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGENAME }}:latest | ||
| cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGENAME }}:buildcache | ||
| cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGENAME }}:buildcache,mode=max | ||
|
|
||
| - name: Deploy via SSH | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.SSH_HOST }} | ||
| username: ${{ secrets.SSH_USERNAME }} | ||
| password: ${{ secrets.SSH_PASSWORD }} | ||
| port: ${{ secrets.SSH_PORT }} | ||
| script: | | ||
| set -e | ||
| APP=${{ secrets.DOCKER_IMAGENAME }} | ||
| IMAGE=${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGENAME }}:${{ github.run_id }} | ||
|
|
||
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }} | ||
| docker pull $IMAGE | ||
|
|
||
| # 새 컨테이너(임시 이름) 먼저 띄우고 헬스체크 | ||
| docker run -d --name ${APP}-next \ | ||
| --restart=always \ | ||
| -p 80:3000 \ | ||
| $IMAGE | ||
|
|
||
| # 기존 컨테이너 종료/삭제 | ||
| docker stop ${APP} || true | ||
| docker rm ${APP} || true | ||
|
|
||
| # 새 컨테이너를 정식 이름으로 교체 | ||
| docker rename ${APP}-next ${APP} | ||
|
|
||
| # 오래된 이미지 정리(선택) | ||
| docker image prune -f || true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # syntax=docker.io/docker/dockerfile:1 | ||
|
|
||
| FROM node:22-alpine AS base | ||
caseBread marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Install dependencies only when needed | ||
| FROM base AS deps | ||
| # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
|
|
||
| # Install dependencies based on the preferred package manager | ||
| COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ | ||
| RUN \ | ||
| if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ | ||
| elif [ -f package-lock.json ]; then npm ci; \ | ||
| elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ | ||
| else echo "Lockfile not found." && exit 1; \ | ||
| fi | ||
caseBread marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Rebuild the source code only when needed | ||
| FROM base AS builder | ||
| WORKDIR /app | ||
| COPY --from=deps /app/node_modules ./node_modules | ||
| COPY . . | ||
|
|
||
| # Next.js collects completely anonymous telemetry data about general usage. | ||
| # Learn more here: https://nextjs.org/telemetry | ||
| # Uncomment the following line in case you want to disable telemetry during the build. | ||
| # ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN \ | ||
| if [ -f yarn.lock ]; then yarn run build; \ | ||
| elif [ -f package-lock.json ]; then npm run build; \ | ||
| elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ | ||
| else echo "Lockfile not found." && exit 1; \ | ||
| fi | ||
caseBread marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Production image, copy all the files and run next | ||
| FROM base AS runner | ||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production | ||
| # Uncomment the following line in case you want to disable telemetry during runtime. | ||
| # ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN addgroup --system --gid 1001 nodejs | ||
| RUN adduser --system --uid 1001 nextjs | ||
|
|
||
| COPY --from=builder /app/public ./public | ||
|
|
||
| # Automatically leverage output traces to reduce image size | ||
| # https://nextjs.org/docs/advanced-features/output-file-tracing | ||
| COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | ||
| COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV PORT=3000 | ||
|
|
||
| # server.js is created by next build from the standalone output | ||
| # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output | ||
| ENV HOSTNAME="0.0.0.0" | ||
| CMD ["node", "server.js"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import type { NextConfig } from 'next'; | ||
|
|
||
| const nextConfig: NextConfig = { | ||
| /* config options here */ | ||
| output: 'standalone', | ||
| }; | ||
|
|
||
| export default nextConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| { | ||
| "name": "cheeese_fe", | ||
| "version": "0.1.0", | ||
| "packageManager": "[email protected]", | ||
| "engines": { | ||
| "node": "22.20.0" | ||
| }, | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "next dev --turbopack", | ||
| "build": "next build --turbopack", | ||
| "build:docker": "docker build -t cheese_frontend .", | ||
| "start": "next start", | ||
| "lint": "eslint" | ||
| }, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5 main 브랜치 변경 시 이번에 빌드할 최신 GIT 버전과 최근에 빌드된 버전을 모두 적용해서 문제가 없다면 최신GIT 버전을 사용하고 오류나 문제가 생긴다면 최근에 빌드된 버전을 그대로 유지하는 방식인거 같네요! 개선할 방법이 있나 찾아보긴했는데 제 지식이 얕아서,,., 요정도면 충분할 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 넵 말씀주신 방식처럼 새 빌드 돌려서 문제없으면 배포시키고, 문제있으면 배포가 안되는 방식이 맞습니다.