Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #454

Open
wants to merge 14 commits into
base: be/release
Choose a base branch
from
77 changes: 77 additions & 0 deletions .github/workflows/Backend-CD-My-A.yml
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions .github/workflows/Backend-CD-My-All.yml
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions .github/workflows/Backend-CD-My-B.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion backend/pokerogue/src/main/resources
Loading