Deploy API To Prod #63
Workflow file for this run
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: Deploy API To Prod | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set Up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Grant Execute Permission For Gradlew | |
run: chmod +x gradlew | |
- name: Make Prod1 Yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-prod1.yml | |
echo "${{ secrets.PROPERTIES_PROD1 }}" > ./application-prod1.yml | |
shell: bash | |
- name: Make Prod2 Yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-prod2.yml | |
echo "${{ secrets.PROPERTIES_PROD2 }}" > ./application-prod2.yml | |
- name: Build With Gradle | |
run: ./gradlew :bootJar -x test | |
- name: Docker Build And Push | |
run: | | |
docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} | |
docker build -f docker/api.Dockerfile -t skku-api . | |
docker tag skku-api sinkyoungdeok/skku-api | |
docker push sinkyoungdeok/skku-api | |
- name: Deploy Prod | |
uses: appleboy/ssh-action@v0.1.4 | |
with: | |
key: ${{ secrets.SSH_KEY }} | |
host: ${{ secrets.HOST_NAME }} | |
username: ubuntu | |
port: 22 | |
script: | | |
docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} | |
docker pull sinkyoungdeok/skku-api | |
echo "> 구동중인 Profile 확인" | |
CURRENT_PROFILE=$(curl -s http://localhost/profile) | |
echo "> $CURRENT_PROFILE" | |
echo "> profile setting" | |
if [ "$CURRENT_PROFILE" == "prod1" ] | |
then | |
IDLE_PROFILE=prod2 | |
IDLE_PORT=8082 | |
elif [ "$CURRENT_PROFILE" == "prod2" ] | |
then | |
IDLE_PROFILE=prod1 | |
IDLE_PORT=8081 | |
else | |
echo "> 일치하는 Profile이 없음." | |
IDLE_PROFILE=prod1 | |
IDLE_PORT=8081 | |
fi | |
echo "> 배포" | |
if [ "$IDLE_PROFILE" == "prod1" ] | |
then | |
docker compose build skku-api-1 | |
docker compose up -d skku-api-1 | |
else | |
docker compose build skku-api-2 | |
docker compose up -d skku-api-2 | |
fi | |
sleep 60 | |
echo "> Change Nginx Proxy Port" | |
echo "set \$service_url http://127.0.0.1:${IDLE_PORT};" |sudo tee /etc/nginx/conf.d/service-url.inc | |
echo "> Nginx Reload" | |
sudo service nginx reload |