-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (73 loc) · 3.1 KB
/
deploy-dev.yml
File metadata and controls
83 lines (73 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: KOIN_BATCH CD (develop)
on:
push:
branches:
- develop
jobs:
deploy:
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Record start time
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Notify Slack - Deploy Start
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \":rocket: *[Develop] KOIN_BATCH 배포 시작*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• <${ACTIONS_URL}|Actions 보기>\"
}"
- name: Create archive
run: tar -cvzf batch.tar.gz --exclude='.git' --exclude='.github' .
- name: Transfer archive to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
source: batch.tar.gz
target: ${{ secrets.DEPLOY_PATH }}
- name: Execute deploy commands
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
source ~/.profile
cd ${{ secrets.DEPLOY_PATH }}
tar -xvzf batch.tar.gz
rm batch.tar.gz
chmod +x run.sh
pip3 install -r requirements.txt
cp -n crawling/config.example.py crawling/config.py
cp -n crawling/koreatech_article/config.example.py crawling/koreatech_article/config.py
cp -n crawling/koreatech_portal/config.example.py crawling/koreatech_portal/config.py
cp -n crawling/city_bus/config.example.py crawling/city_bus/config.py
- name: Notify Slack - Deploy Result
if: always()
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
DURATION_SEC=$(( $(date +%s) - START_TIME ))
DURATION="${DURATION_SEC}초 (약 $(( DURATION_SEC / 60 ))분)"
if [ "${{ job.status }}" = "success" ]; then
ICON=":white_check_mark:"
STATUS="배포 성공"
else
ICON=":x:"
STATUS="배포 실패"
fi
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"${ICON} *[Develop] KOIN_BATCH ${STATUS}*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• Duration: ${DURATION}\n• <${ACTIONS_URL}|Actions 보기>\"
}"