Skip to content

Commit b27164d

Browse files
author
hodoon
committed
hotfix : 개발서버 CI/CD Workflow 추가
1 parent 3b70f2d commit b27164d

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI (develop)
22

33
on:
44
pull_request:
5-
branches: ["main", develop" ]
5+
branches: ["main", "develop" ]
66

77
permissions:
88
contents: read

.github/workflows/cicd-dev.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: CI/CD (develop)
2+
3+
on:
4+
push:
5+
branches: [ "develop" ]
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: valuedi-dev-deploy
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
image_repo: ${{ steps.meta.outputs.image_repo }}
20+
image_tag: ${{ steps.meta.outputs.image_tag }}
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4.2.2
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3.10.0
31+
32+
- name: Log in to Docker Hub
33+
uses: docker/login-action@v3.4.0
34+
with:
35+
username: ${{ secrets.DOCKER_USERNAME }}
36+
password: ${{ secrets.DOCKER_PASSWORD }}
37+
38+
- name: Set image meta
39+
id: meta
40+
run: |
41+
echo "image_repo=${{ secrets.DOCKER_USERNAME }}/valuedi-backend" >> $GITHUB_OUTPUT
42+
echo "image_tag=${{ github.sha }}" >> $GITHUB_OUTPUT
43+
44+
- name: Build & Push (ARM64)
45+
uses: docker/build-push-action@v6.16.0
46+
with:
47+
context: .
48+
file: ./Dockerfile
49+
push: true
50+
platforms: linux/arm64 # 라즈베리 파이용
51+
tags: |
52+
${{ steps.meta.outputs.image_repo }}:dev-latest
53+
${{ steps.meta.outputs.image_repo }}:${{ steps.meta.outputs.image_tag }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
57+
deploy:
58+
runs-on: ubuntu-latest
59+
needs: build-and-push
60+
61+
steps:
62+
- name: Deploy via SSH (Blue/Green)
63+
uses: appleboy/ssh-action@v1.2.2
64+
with:
65+
host: ${{ secrets.DEV_SERVER_HOST }} # 개발 서버 IP
66+
port: ${{ secrets.DEV_SERVER_PORT }} # 개발 서버 SSH 포트
67+
username: ${{ secrets.DEV_SERVER_USERNAME }} # 개발 서버 유저 (예: pi)
68+
key: ${{ secrets.DEV_SERVER_KEY }} # 개발 서버 SSH Key
69+
script_stop: true
70+
script: |
71+
set -euo pipefail
72+
73+
APP_DIR="/home/${{ secrets.DEV_SERVER_USERNAME }}/valuedi/app" # 라즈베리 파이 경로
74+
cd "$APP_DIR"
75+
76+
# 1) DEV_ENV를 .env로 반영
77+
cat > .env << 'EOF'
78+
${{ secrets.DEV_ENV }}
79+
EOF
80+
81+
# 2) IMAGE_REPO / IMAGE_TAG 주입
82+
IMAGE_REPO="${{ secrets.DOCKER_USERNAME }}/valuedi-backend"
83+
IMAGE_TAG="${{ github.sha }}"
84+
85+
if grep -q '^IMAGE_REPO=' .env; then
86+
sed -i "s|^IMAGE_REPO=.*|IMAGE_REPO=${IMAGE_REPO}|" .env
87+
else
88+
echo "IMAGE_REPO=${IMAGE_REPO}" >> .env
89+
fi
90+
91+
if grep -q '^IMAGE_TAG=' .env; then
92+
sed -i "s|^IMAGE_TAG=.*|IMAGE_TAG=${IMAGE_TAG}|" .env
93+
else
94+
echo "IMAGE_TAG=${IMAGE_TAG}" >> .env
95+
fi
96+
97+
# 3) 배포 스크립트 실행
98+
# (스크립트 파일들이 실행 권한이 있는지 확인)
99+
chmod +x deploy.sh scripts/healthcheck.sh scripts/switch_upstream.sh
100+
./deploy.sh
101+
102+
# 4) 정리
103+
docker image prune -f

0 commit comments

Comments
 (0)