Update server-action.yml #63
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: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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 |