diff --git a/.github/workflows/Backend-CD-My-A.yml b/.github/workflows/Backend-CD-My-A.yml new file mode 100644 index 000000000..2ba66e1f0 --- /dev/null +++ b/.github/workflows/Backend-CD-My-A.yml @@ -0,0 +1,77 @@ +name: Backend Production Server My A + +on: + workflow_call: + +permissions: + contents: read + +jobs: + deploy: + runs-on: [ cd, my-a ] + steps: + - name: Change permission + run: | + sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-pokerogue-helper + + - name: Port forwarding begin + run: | + sudo sysctl -w net.ipv4.ip_forward=1 + sudo iptables --policy FORWARD ACCEPT + sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -t nat -I PREROUTING 1 -p tcp --dport 80 -j DNAT --to-destination ${{ secrets.BE_PROD_B_MY_PRIVATE_IP }}:80 + sudo iptables -t nat -I POSTROUTING 1 -p tcp --dport 80 -j SNAT --to-source ${{ secrets.BE_PROD_A_MY_PRIVATE_IP }} + sleep 5 + + - name: Deploy + run: | + cd /home/ubuntu + + sudo chmod 666 /var/run/docker.sock + + if [ "$(docker ps -qa -f name=server)" ]; then + docker rm -f server + else + echo "No container named 'server' to remove." + fi + + sudo docker system prune -f + + docker pull ${{ secrets.DOCKER_SERVER_IMAGE }} + + docker run -d -p 80:8080 --name server \ + -e JAVA_OPTS="-XX:InitialRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0" \ + -e TZ=Asia/Seoul \ + ${{ secrets.DOCKER_SERVER_IMAGE }} + + - name: Check service availability + run: | + SUCCESS=false + + for i in {1..10}; do + HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) || { + echo "Attempt $i: curl command failed. Retrying..."; + sleep 3; + continue; + } + + if [ $? -eq 0 ] && [ "$HTTP_STATUS" -eq 200 ]; then + echo "Service is up and running" + SUCCESS=true + break + fi + done + + - name: Port forwarding end + run: | + sudo iptables -D INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -t nat -D PREROUTING 1 + sudo iptables -t nat -D POSTROUTING 1 + sudo iptables -L -v -t nat + + - name: Exit if fails + run: | + if [ "$SUCCESS" = false ]; then + echo "Service did not respond successfully after $ATTEMPTS attempts, stopping github actions.." + sudo exit 1 + fi diff --git a/.github/workflows/Backend-CD-My-All.yml b/.github/workflows/Backend-CD-My-All.yml new file mode 100644 index 000000000..df60150bf --- /dev/null +++ b/.github/workflows/Backend-CD-My-All.yml @@ -0,0 +1,53 @@ +name: Backend Production Server CD My All + +permissions: + contents: read + +on: + push: + branches: [ "be/my-test" ] + tags: + - 'v*' + +jobs: + test: + uses: ./.github/workflows/Backend-CI.yml + secrets: inherit + + build: + needs: test + runs-on: ci + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.ACTION_TOKEN }} + submodules: true + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build with Gradle + run: ./gradlew bootJar + working-directory: ./backend/pokerogue + + - name: Docker build and push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + + docker build -t ${{ secrets.DOCKER_SERVER_IMAGE }} -f ./backend/pokerogue/docker/Dockerfile ./backend/pokerogue + docker push ${{ secrets.DOCKER_SERVER_IMAGE }} + + prod_a: + needs: build + name: Backend Production Server CD My A + uses: ./.github/workflows/Backend-CD-My-A.yml + secrets: inherit + prod_b: + needs: prod_a + name: Backend Production Server CD My B + uses: ./.github/workflows/Backend-CD-My-B.yml + secrets: inherit diff --git a/.github/workflows/Backend-CD-My-B.yml b/.github/workflows/Backend-CD-My-B.yml new file mode 100644 index 000000000..bf6875699 --- /dev/null +++ b/.github/workflows/Backend-CD-My-B.yml @@ -0,0 +1,77 @@ +name: Backend Production Server My B + +on: + workflow_call: + +permissions: + contents: read + +jobs: + deploy: + runs-on: [ cd, my-b ] + steps: + - name: Change permission + run: | + sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-pokerogue-helper + + - name: Port forwarding begin + run: | + sudo sysctl -w net.ipv4.ip_forward=1 + sudo iptables --policy FORWARD ACCEPT + sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -t nat -I PREROUTING 1 -p tcp --dport 80 -j DNAT --to-destination ${{ secrets.BE_PROD_A_MY_PRIVATE_IP }}:80 + sudo iptables -t nat -I POSTROUTING 1 -p tcp --dport 80 -j SNAT --to-source ${{ secrets.BE_PROD_B_MY_PRIVATE_IP }} + sleep 5 + + - name: Deploy + run: | + cd /home/ubuntu + + sudo chmod 666 /var/run/docker.sock + + if [ "$(docker ps -qa -f name=server)" ]; then + docker rm -f server + else + echo "No container named 'server' to remove." + fi + + sudo docker system prune -f + + docker pull ${{ secrets.DOCKER_SERVER_IMAGE }} + + docker run -d -p 80:8080 --name server \ + -e JAVA_OPTS="-XX:InitialRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0" \ + -e TZ=Asia/Seoul \ + ${{ secrets.DOCKER_SERVER_IMAGE }} + + - name: Check service availability + run: | + SUCCESS=false + + for i in {1..10}; do + HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) || { + echo "Attempt $i: curl command failed. Retrying..."; + sleep 3; + continue; + } + + if [ $? -eq 0 ] && [ "$HTTP_STATUS" -eq 200 ]; then + echo "Service is up and running" + SUCCESS=true + break + fi + done + + - name: Port forwarding end + run: | + sudo iptables -D INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -t nat -D PREROUTING 1 + sudo iptables -t nat -D POSTROUTING 1 + sudo iptables -L -v -t nat + + - name: Exit if fails + run: | + if [ "$SUCCESS" = false ]; then + echo "Service did not respond successfully after 10 attempts, stopping github actions.." + sudo exit 1 + fi diff --git a/backend/pokerogue/src/main/resources b/backend/pokerogue/src/main/resources index 84d406f5f..db9800ae1 160000 --- a/backend/pokerogue/src/main/resources +++ b/backend/pokerogue/src/main/resources @@ -1 +1 @@ -Subproject commit 84d406f5f4d2cdb524a5bc60caf1530066a022f4 +Subproject commit db9800ae13cba0a0d35714a3e0b9994ce02fa98d