Skip to content

Update server-action.yml #73

Update server-action.yml

Update server-action.yml #73

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:8081"
TARGET_PORT="8081"
else
NEW_CONTAINER_NAME="hana-server-blue"
OLD_CONTAINER_NAME="hana-server-green"
PORT_MAPPING="8080:8080"
TARGET_PORT="8080"
fi
sudo docker rmi rlawjddn5980/hana-server:latest || true
sudo docker pull rlawjddn5980/hana-server:latest
sudo docker run -d -p $PORT_MAPPING --name $NEW_CONTAINER_NAME --network hana_network -v /home/ubuntu/logs:/logs -v /home/ubuntu/images:/images -e SERVER_PORT=$TARGET_PORT 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'
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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