-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (72 loc) Β· 3.47 KB
/
server-action.yml
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
84
85
86
87
name: hana-server workflow
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Notify Slack - Deployment Started
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"μΈν°λ ν°λΈ νλ μλ² λ°°ν¬κ° μμλμμ΅λλ€."}' https://hooks.slack.com/services/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
- name: Gradle Build
run: ./gradlew bootJar
- name: Verify Build Output
run: ls -la build/libs
- name: Docker Image Build
env:
DOCKER_BUILDKIT: 1
run: docker build --tag rlawjddn5980/hana-server:latest .
- name: Docker Hub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker Hub Push
run: docker push rlawjddn5980/hana-server:latest
- name: Connect to WAS & Execute Application
id: deploy_step
uses: appleboy/[email protected]
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
# νμ¬ νμ±νλ 컨ν
μ΄λ νμΈ
if [ "$(sudo docker ps -q -f name=hana-server-blue)" ]; then
NEW_CONTAINER_NAME="hana-server-green"
OLD_CONTAINER_NAME="hana-server-blue"
PORT_MAPPING="8081:8080" # λΈλ£¨κ° νμ±νλ κ²½μ° 8081 μ¬μ©
TARGET_PORT="8081"
else
NEW_CONTAINER_NAME="hana-server-blue"
OLD_CONTAINER_NAME="hana-server-green"
PORT_MAPPING="8080:8080" # κ·Έλ¦°μ΄ νμ±νλ κ²½μ° 8080 μ¬μ©
TARGET_PORT="8080"
fi
# μλ‘μ΄ μ»¨ν
μ΄λ μ€ν
sudo docker run -d -p $PORT_MAPPING --name $NEW_CONTAINER_NAME --network hana_network -v /home/ubuntu/logs:/logs rlawjddn5980/hana-server:latest
sudo docker exec nginx sh -c 'sed -i "s/set \$service_ip .*/set \$service_ip \"$NEW_CONTAINER_NAME\";/" /etc/nginx/conf.d/service-url.inc && sed -i "s/set \$service_port .*/set \$service_port \"$TARGET_PORT\";/" /etc/nginx/conf.d/service-url.inc && nginx -s reload'
# Nginx μ¬μμ μμλ‘ .. λμ€μ 무μ€λ¨ λ³κ²½
sudo docker exec nginx nginx -s reload
# μ΄μ 컨ν
μ΄λ μ€μ§ λ° μ κ±°
if [ "$(sudo docker ps -q -f name=$OLD_CONTAINER_NAME)" ]; then
sudo docker stop $OLD_CONTAINER_NAME || true
sudo docker rm $OLD_CONTAINER_NAME || true
fi
- name: Notify Slack - Deployment Finished
if: success()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"μΈν°λ ν°λΈ νλ μλ² λ°°ν¬κ° μλ£λμμ΅λλ€."}' https://hooks.slack.com/services/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
- name: Notify Slack - Deployment Failed
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"μΈν°λ ν°λΈ νλ μλ² λ°°ν¬μ μ€ν¨νμ΅λλ€."}' https://hooks.slack.com/services/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