Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
70 changes: 70 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 워크플로우의 이름
name: Deploy Next.js to Server With Docker Image

# 워크플로우가 실행될 조건
on:
pull_request:
branches: ['main', 'develop']
workflow_dispatch:

# 실행될 작업들
jobs:
build-and-deploy:
# 작업이 실행될 환경
runs-on: self-hosted

# 작업의 단계들
steps:
# 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v4

- name: '🔧 Disable Docker credential helper'
run: |
echo "인증 정보 도우미 설정을 제거합니다."
jq -n 'del(.credsStore)' | tee ~/.docker/config.json > /dev/null

# 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 }}

# Docker Buildx 설정 (멀티-플랫폼 빌드 지원)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# 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
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME}}:${{ github.sha }}

# 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: |
bash -c '
echo "✅ SSH Connected ..."
echo "👤 Current User: $(whoami)"
echo "🖥️ Host Name: $(hostname)"
echo "⏰ Current Time: $(date)"
echo "📁 Current Directory: $(pwd)"
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
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
'
26 changes: 26 additions & 0 deletions .github/workflows/self-hosted-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test Workflow

# 워크플로우가 실행될 조건
on:
pull_request:
branches: ['main', 'develop']
workflow_dispatch:

jobs:
test:
runs-on: self-hosted
steps:
- name: check environment
run: |
bash -c '
echo "✅ SSH Connected ..."
echo "👤 Current User: $(whoami)"
echo "🖥️ Host Name: $(hostname)"
echo "⏰ Current Time: $(date)"
echo "📁 Current Directory: $(pwd)"
echo "🐳 Docker Version: $(docker --version)"
echo "📦 Installed Packages: $(npm list -g --depth=0)"
cd ~/GitHub
echo "📂 Current Directory: $(pwd)"
echo "📂 Directory Contents: $(ls -la)"
'
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*.yaml ./
RUN pnpm install --frozen-lockfile --ignore-scripts
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