-
Notifications
You must be signed in to change notification settings - Fork 2
[WIP] [Feat] Docker를 통한 CI/CD 설정 #241
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
01407d8
a9c8a92
3a927ce
d142130
c83548b
7620f34
714773d
9246381
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||||||
# 워크플로우의 이름 | ||||||||||
name: Deploy Next.js to Server With Docker Image | ||||||||||
|
||||||||||
# 워크플로우가 실행될 조건 | ||||||||||
on: | ||||||||||
pull_request: | ||||||||||
branches: ['main', 'develop'] | ||||||||||
workflow_dispatch: | ||||||||||
|
||||||||||
# 실행될 작업들 | ||||||||||
jobs: | ||||||||||
build-and-deploy: | ||||||||||
# 작업이 실행될 환경 | ||||||||||
runs-on: ubuntu-latest | ||||||||||
|
||||||||||
# 작업의 단계들 | ||||||||||
steps: | ||||||||||
# 1. 코드 체크아웃 | ||||||||||
- name: Checkout code | ||||||||||
uses: actions/checkout@v4 | ||||||||||
|
||||||||||
# 3. Docker Hub 로그인 | ||||||||||
# GitHub Secrets에 DOCKERHUB_USERNAME와 DOCKERHUB_TOKEN를 등록해야 합니다. | ||||||||||
- name: Docker Hub 로그인 | ||||||||||
uses: docker/login-action@v3 | ||||||||||
with: | ||||||||||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||||||||||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||||||||||
|
||||||||||
# 2. Docker Buildx 설정 (멀티-플랫폼 빌드 지원) | ||||||||||
- name: Set up Docker Buildx | ||||||||||
uses: docker/setup-buildx-action@v3 | ||||||||||
|
||||||||||
# 4. Docker 이미지 빌드 및 푸시 | ||||||||||
- name: Build and push Docker image | ||||||||||
uses: docker/build-push-action@v6 | ||||||||||
with: | ||||||||||
context: . | ||||||||||
file: ./scripts/docker/Dockerfile | ||||||||||
push: true | ||||||||||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:latest | ||||||||||
kyeoungwoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
# 5. SSH를 통해 서버에 배포 | ||||||||||
# GitHub Secrets에 DEPLOY_HOST, DEPLOY_USERNAME, DEPLOY_KEY, DEPLOY_PORT를 등록해야 합니다. | ||||||||||
- name: SSH 접속 및 스크립트 실행 | ||||||||||
uses: appleboy/ssh-action@v1 | ||||||||||
with: | ||||||||||
host: ${{ secrets.SERVER_SSH_HOST }} | ||||||||||
username: ${{ secrets.SERVER_SSH_USERNAME }} | ||||||||||
key: ${{ secrets.SERVER_SSH_PRIVATE_KEY }} | ||||||||||
port: ${{ secrets.SERVER_SSH_PORT }} | ||||||||||
script: | | ||||||||||
docker stop ${{ secrets.SERVER_DOCKER_CONTAINER_NAME }} || true | ||||||||||
docker rm ${{ secrets.SERVER_DOCKER_CONTAINER_NAME }} || true | ||||||||||
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:latest | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space after
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
docker run -d -p ${{ secrets.DOCKER_HOST_PORT }}:${{ secrets.DOCKER_CONTAINER_PORT }} --name ${{ secrets.SERVER_DOCKER_CONTAINER_NAME }} --restart always ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:latest | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space after
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||||||||
FROM node:24-alpine AS builder | ||||||||||||||||
WORKDIR /app | ||||||||||||||||
|
||||||||||||||||
RUN corepack enable && corepack prepare pnpm@latest --activate | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
|
||||||||||||||||
COPY package*.json pnpm-lock.yaml ./ | ||||||||||||||||
RUN pnpm install --frozen-lockfile | ||||||||||||||||
COPY . . | ||||||||||||||||
RUN pnpm run build | ||||||||||||||||
|
||||||||||||||||
FROM node:24-alpine | ||||||||||||||||
WORKDIR /app | ||||||||||||||||
|
||||||||||||||||
RUN corepack enable && corepack prepare pnpm@latest --activate | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
|
||||||||||||||||
COPY --from=builder /app/.next ./.next | ||||||||||||||||
COPY --from=builder /app/node_modules ./node_modules | ||||||||||||||||
COPY --from=builder /app/package.json ./package.json | ||||||||||||||||
COPY --from=builder /app/public ./public | ||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copying the entire node_modules directory from the builder stage is inefficient. Consider using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
|
||||||||||||||||
EXPOSE 3000 | ||||||||||||||||
|
||||||||||||||||
CMD ["pnpm", "start"] |
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.
The step numbering in comments is inconsistent. Step 3 appears before step 2 (line 30). Consider reordering the comments to match the actual execution order.
Copilot uses AI. Check for mistakes.