Skip to content

Commit 6a6fd3c

Browse files
authored
Merge pull request #186 from BCSDLab/feat/add-github-action-deploy
feat: Github Action 배포 워크 플로우 추가
2 parents 15945cd + 7a292c5 commit 6a6fd3c

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

.github/workflows/deploy-prod.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: KOIN_BATCH CD (production)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
if: github.ref == 'refs/heads/master'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Record start time
15+
id: start
16+
run: echo "time=$(date +%s)" >> "$GITHUB_OUTPUT"
17+
18+
- name: Notify Slack deploy started
19+
run: |
20+
curl -s -X POST "${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }}" \
21+
-H 'Content-Type: application/json' \
22+
-d '{
23+
"text": ":rocket: *[Production] 배포 시작*\n• *Repo:* ${{ github.repository }}\n• *Branch:* ${{ github.ref_name }}\n• *Author:* ${{ github.actor }}\n• *Commit:* `${{ github.sha }}`\n• *Actions:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|워크플로우 확인>"
24+
}'
25+
26+
- name: Create tar archive
27+
run: |
28+
tar -cvzf batch.tar.gz --exclude='.github' .
29+
30+
- name: Transfer archive via SCP
31+
uses: appleboy/scp-action@v0.1.7
32+
with:
33+
host: ${{ secrets.PROD_SSH_HOST }}
34+
username: ${{ secrets.PROD_SSH_USER }}
35+
key: ${{ secrets.PROD_SSH_KEY }}
36+
port: ${{ secrets.PROD_SSH_PORT }}
37+
source: batch.tar.gz
38+
target: ${{ secrets.PROD_DEPLOY_PATH }}
39+
40+
- name: Run deploy script via SSH
41+
uses: appleboy/ssh-action@v1.0.3
42+
with:
43+
host: ${{ secrets.PROD_SSH_HOST }}
44+
username: ${{ secrets.PROD_SSH_USER }}
45+
key: ${{ secrets.PROD_SSH_KEY }}
46+
port: ${{ secrets.PROD_SSH_PORT }}
47+
script: bash ${{ secrets.PROD_DEPLOY_SCRIPT_PATH }}
48+
49+
- name: Notify Slack deploy result
50+
if: always()
51+
run: |
52+
DURATION=$(( $(date +%s) - ${{ steps.start.outputs.time }} ))
53+
MINUTES=$((DURATION / 60))
54+
SECONDS=$((DURATION % 60))
55+
56+
if [ "${{ job.status }}" = "success" ]; then
57+
EMOJI=":white_check_mark:"
58+
STATUS="성공"
59+
else
60+
EMOJI=":x:"
61+
STATUS="실패"
62+
fi
63+
64+
curl -s -X POST "${{ secrets.PROD_SLACK_DEPLOY_WEBHOOK_URL }}" \
65+
-H 'Content-Type: application/json' \
66+
-d "{
67+
\"text\": \"${EMOJI} *[Production] 배포 ${STATUS}*\n• *Repo:* ${{ github.repository }}\n• *Branch:* ${{ github.ref_name }}\n• *Author:* ${{ github.actor }}\n• *Duration:* ${MINUTES}분 ${SECONDS}초\n• *Actions:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|워크플로우 확인>\"
68+
}"

.github/workflows/deploy-stage.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: KOIN_BATCH CD (stage)
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Record start time
15+
id: start
16+
run: echo "time=$(date +%s)" >> "$GITHUB_OUTPUT"
17+
18+
- name: Notify Slack deploy started
19+
run: |
20+
curl -s -X POST "${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }}" \
21+
-H 'Content-Type: application/json' \
22+
-d '{
23+
"text": ":rocket: *[Stage] 배포 시작*\n• *Repo:* ${{ github.repository }}\n• *Branch:* ${{ github.ref_name }}\n• *Author:* ${{ github.actor }}\n• *Commit:* `${{ github.sha }}`\n• *Actions:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|워크플로우 확인>"
24+
}'
25+
26+
- name: Create tar archive
27+
run: |
28+
tar -cvzf batch.tar.gz --exclude='.github' .
29+
30+
- name: Transfer archive via SCP
31+
uses: appleboy/scp-action@v0.1.7
32+
with:
33+
host: ${{ secrets.STAGE_SSH_HOST }}
34+
username: ${{ secrets.STAGE_SSH_USER }}
35+
key: ${{ secrets.STAGE_SSH_KEY }}
36+
port: ${{ secrets.STAGE_SSH_PORT }}
37+
source: batch.tar.gz
38+
target: ${{ secrets.STAGE_DEPLOY_PATH }}
39+
40+
- name: Run deploy script via SSH
41+
uses: appleboy/ssh-action@v1.0.3
42+
with:
43+
host: ${{ secrets.STAGE_SSH_HOST }}
44+
username: ${{ secrets.STAGE_SSH_USER }}
45+
key: ${{ secrets.STAGE_SSH_KEY }}
46+
port: ${{ secrets.STAGE_SSH_PORT }}
47+
script: bash ${{ secrets.STAGE_DEPLOY_SCRIPT_PATH }}
48+
49+
- name: Notify Slack deploy result
50+
if: always()
51+
run: |
52+
DURATION=$(( $(date +%s) - ${{ steps.start.outputs.time }} ))
53+
MINUTES=$((DURATION / 60))
54+
SECONDS=$((DURATION % 60))
55+
56+
if [ "${{ job.status }}" = "success" ]; then
57+
EMOJI=":white_check_mark:"
58+
STATUS="성공"
59+
else
60+
EMOJI=":x:"
61+
STATUS="실패"
62+
fi
63+
64+
curl -s -X POST "${{ secrets.STAGE_SLACK_DEPLOY_WEBHOOK_URL }}" \
65+
-H 'Content-Type: application/json' \
66+
-d "{
67+
\"text\": \"${EMOJI} *[Stage] 배포 ${STATUS}*\n• *Repo:* ${{ github.repository }}\n• *Branch:* ${{ github.ref_name }}\n• *Author:* ${{ github.actor }}\n• *Duration:* ${MINUTES}분 ${SECONDS}초\n• *Actions:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|워크플로우 확인>\"
68+
}"

0 commit comments

Comments
 (0)