Skip to content

🍀 [배포] sendRedirect 값 localhost:3000 으로 변경 #10

🍀 [배포] sendRedirect 값 localhost:3000 으로 변경

🍀 [배포] sendRedirect 값 localhost:3000 으로 변경 #10

Workflow file for this run

# github repository actions 페이지에 나타날 이름
name: CI/CD using github actions & docker
# event trigger
# main브랜치에 pull request가 발생 되었을 때 실행
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build Project with Gradle
run: |
echo ${{ secrets.APPLICATION_SECRET }} | base64 --decode > ./src/main/resources/application-secret.yml
./gradlew bootJar
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build docker image
run: docker build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/angelbridge .
- name: Publish image to docker hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/angelbridge:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set Target IP
run: |
STATUS=$(curl -o /dev/null -w "%{http_code}" "http://${{ secrets.ANGELBRIDGE_SERVER_IP }}/env")
echo $STATUS
if [ $STATUS = 200 ]; then
CURRENT_UPSTREAM=$(curl -s "http://${{ secrets.ANGELBRIDGE_SERVER_IP }}/env")
else
CURRENT_UPSTREAM=green
fi
echo CURRENT_UPSTREAM=$CURRENT_UPSTREAM >> $GITHUB_ENV
if [ $CURRENT_UPSTREAM = blue ]; then
echo "CURRENT_PORT=8080" >> $GITHUB_ENV
echo "STOPPED_PORT=8081" >> $GITHUB_ENV
echo "TARGET_UPSTREAM=green" >> $GITHUB_ENV
else
echo "CURRENT_PORT=8081" >> $GITHUB_ENV
echo "STOPPED_PORT=8080" >> $GITHUB_ENV
echo "TARGET_UPSTREAM=blue" >> $GITHUB_ENV
fi
- name: Docker Compose
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.ANGELBRIDGE_SERVER_IP }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/angelbridge:latest
sudo docker-compose -f docker-compose-${{env.TARGET_UPSTREAM}}.yml up -d
- name: Check deploy server URL
uses: jtalk/url-health-check-action@v3
with:
url: http://${{ secrets.ANGELBRIDGE_SERVER_IP }}:${{ env.STOPPED_PORT }}/env
max-attempts: 5
retry-delay: 10s
- name: Change nginx upstream
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.ANGELBRIDGE_SERVER_IP }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
sudo docker exec -i nginxserver bash -c 'echo "set \$service_url ${{env.TARGET_UPSTREAM}};" > etc/nginx/conf.d/service-env.inc && nginx -s reload'
- name: Stop current server
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.ANGELBRIDGE_SERVER_IP }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
sudo docker stop ${{ env.CURRENT_UPSTREAM }}
sudo docker rm ${{ env.CURRENT_UPSTREAM }}