Skip to content

Commit 0879a55

Browse files
authored
[#31] CI / CD 단순화 (#32)
1 parent a10ad5f commit 0879a55

1 file changed

Lines changed: 2 additions & 45 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,57 +41,24 @@ jobs:
4141
runs-on: ubuntu-latest
4242
outputs:
4343
sha: ${{ steps.sha.outputs.short }}
44-
api_changed: ${{ steps.changes.outputs.api_changed }}
45-
batch_changed: ${{ steps.changes.outputs.batch_changed }}
4644
steps:
4745
- name: Checkout
4846
uses: actions/checkout@v4
49-
with:
50-
fetch-depth: 2
51-
52-
- name: Detect changes
53-
id: changes
54-
run: |
55-
if git rev-parse HEAD~1 >/dev/null 2>&1; then
56-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
57-
else
58-
CHANGED_FILES=$(git ls-files)
59-
fi
60-
61-
API_CODE_CHANGED=$(echo "$CHANGED_FILES" | grep -cE "^(api|core)/.*\.(kt|java|gradle)(\.kts)?$" || true)
62-
BATCH_CODE_CHANGED=$(echo "$CHANGED_FILES" | grep -cE "^(batch|core)/.*\.(kt|java|gradle)(\.kts)?$" || true)
63-
COMPOSE_CHANGED=$(echo "$CHANGED_FILES" | grep -c "docker-compose\.yml" || true)
64-
65-
# 코드 변경 또는 compose 변경 시 배포
66-
API_CHANGED=$((API_CODE_CHANGED + COMPOSE_CHANGED))
67-
BATCH_CHANGED=$((BATCH_CODE_CHANGED + COMPOSE_CHANGED))
68-
69-
# 빌드는 코드 변경 시에만
70-
BUILD_API=$API_CODE_CHANGED
71-
BUILD_BATCH=$BATCH_CODE_CHANGED
72-
73-
echo "api_changed=$API_CHANGED" >> $GITHUB_OUTPUT
74-
echo "batch_changed=$BATCH_CHANGED" >> $GITHUB_OUTPUT
75-
echo "build_api=$BUILD_API" >> $GITHUB_OUTPUT
76-
echo "build_batch=$BUILD_BATCH" >> $GITHUB_OUTPUT
7747

7848
- name: Login to Docker Hub
79-
if: steps.changes.outputs.api_changed > 0 || steps.changes.outputs.batch_changed > 0
8049
uses: docker/login-action@v3
8150
with:
8251
username: ${{ secrets.DOCKERHUB_USERNAME }}
8352
password: ${{ secrets.DOCKERHUB_TOKEN }}
8453

8554
- name: Set up Docker Buildx
86-
if: steps.changes.outputs.api_changed > 0 || steps.changes.outputs.batch_changed > 0
8755
uses: docker/setup-buildx-action@v3
8856

8957
- name: Extract commit SHA
9058
id: sha
9159
run: echo "short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
9260

9361
- name: Build and push API
94-
if: steps.changes.outputs.build_api > 0
9562
uses: docker/build-push-action@v5
9663
with:
9764
context: .
@@ -104,7 +71,6 @@ jobs:
10471
cache-to: type=gha,mode=max
10572

10673
- name: Build and push Batch
107-
if: steps.changes.outputs.build_batch > 0
10874
uses: docker/build-push-action@v5
10975
with:
11076
context: .
@@ -127,13 +93,12 @@ jobs:
12793
**Status:** ${{ job.status == 'success' && '✅' || '❌' }}
12894
**Branch:** `${{ github.ref_name }}`
12995
**Commit:** `${{ steps.sha.outputs.short }}`
130-
**Built:** ${{ steps.changes.outputs.api_changed > 0 && '🔹API ' || '' }}${{ steps.changes.outputs.batch_changed > 0 && '🔹Batch' || '' }}
96+
**Built:** 🔹API 🔹Batch
13197
color: ${{ job.status == 'success' && '0x57F287' || '0xED4245' }}
13298

13399
deploy:
134100
name: Deploy
135101
needs: build-and-push
136-
#if: needs.build-and-push.outputs.api_changed > 0 || needs.build-and-push.outputs.batch_changed > 0
137102
if: always()
138103
runs-on: ubuntu-latest
139104
timeout-minutes: 15
@@ -172,19 +137,15 @@ jobs:
172137
env:
173138
DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }}
174139
SHA: ${{ needs.build-and-push.outputs.sha }}
175-
API_CHANGED: ${{ needs.build-and-push.outputs.api_changed }}
176-
BATCH_CHANGED: ${{ needs.build-and-push.outputs.batch_changed }}
177140
with:
178141
host: ${{ secrets.SERVER_HOST }}
179142
username: root
180143
password: ${{ secrets.SERVER_PASSWORD }}
181-
envs: DOCKER_USER,SHA,API_CHANGED,BATCH_CHANGED
144+
envs: DOCKER_USER,SHA
182145
script: |
183146
set -e
184147
cd ~/retoday
185148
186-
# Deploy API if changed
187-
if [ "$API_CHANGED" -gt 0 ]; then
188149
echo "=== Deploying API ==="
189150
docker pull ${DOCKER_USER}/retoday-api:${SHA}
190151
docker images retoday-api:latest -q | grep -q . && docker tag retoday-api:latest retoday-api:previous || true
@@ -210,10 +171,7 @@ jobs:
210171
}
211172
sleep 10
212173
done
213-
fi
214174
215-
# Deploy Batch if changed
216-
if [ "$BATCH_CHANGED" -gt 0 ]; then
217175
echo "=== Deploying Batch ==="
218176
docker pull ${DOCKER_USER}/retoday-batch:${SHA}
219177
docker images retoday-batch:latest -q | grep -q . && docker tag retoday-batch:latest retoday-batch:previous || true
@@ -234,7 +192,6 @@ jobs:
234192
exit 1
235193
fi
236194
echo "✅ Batch running"
237-
fi
238195
239196
# Cleanup
240197
docker image prune -f --filter "until=24h" || true

0 commit comments

Comments
 (0)