Skip to content

Update server-action.yml #63

Update server-action.yml

Update server-action.yml #63

Workflow file for this run

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
docker exec -it 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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