Update server-action.yml #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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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 |