Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/docker-deploy.yml
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 로그인
Copy link
Preview

Copilot AI Aug 12, 2025

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.

Suggested change
# 3. Docker Hub 로그인
# 2. Docker Hub 로그인

Copilot uses AI. Check for mistakes.

# 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

# 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
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after DOCKER_REPOSITORY_NAME and before the closing }}. This should be ${{ secrets.DOCKER_REPOSITORY_NAME }}:latest for consistency with other variable references.

Suggested change
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:latest
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:latest

Copilot uses AI. Check for mistakes.

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
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after DOCKER_REPOSITORY_NAME and before the closing }}. This should be ${{ secrets.DOCKER_REPOSITORY_NAME }}:latest for consistency with other variable references.

Suggested change
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:latest
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
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:latest
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

Copilot uses AI. Check for mistakes.

23 changes: 23 additions & 0 deletions scripts/docker/Dockerfile
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
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using pnpm@latest can lead to inconsistent builds across environments. Consider pinning to a specific version like [email protected] to ensure reproducible builds.

Suggested change
RUN corepack enable && corepack prepare pnpm@latest --activate
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate

Copilot uses AI. Check for mistakes.


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
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using pnpm@latest can lead to inconsistent builds across environments. Consider pinning to a specific version like [email protected] to ensure reproducible builds.

Suggested change
RUN corepack enable && corepack prepare pnpm@latest --activate
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate

Copilot uses AI. Check for mistakes.


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
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The 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 pnpm install --prod in the runtime stage to only install production dependencies, which will significantly reduce image size.

Suggested change
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=builder /app/public ./public
RUN pnpm install --prod --frozen-lockfile

Copilot uses AI. Check for mistakes.


EXPOSE 3000

CMD ["pnpm", "start"]
Loading