fix : docker-compose-prod.yml 운영 서버 식별 이름 변경 ( backend-dev -> backend… #5
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
name: Deploy to Prod | |
on: | |
push: | |
branches: | |
- prod | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Cache Gradle packages #속도를 빠르게 | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: ${{ runner.os }}-gradle- | |
- name: Grant execute permission for gradlew #권한 | |
run: chmod +x gradlew | |
- name: Make application-prod.yml #환경변수 주입 | |
run: | | |
touch ./src/main/resources/application-prod.yml | |
echo "$PROPERTIES_PROD" > ./src/main/resources/application-prod.yml | |
env: | |
PROPERTIES_PROD: ${{ secrets.PROPERTIES_PROD }} | |
- name: Build with Gradle | |
run: ./gradlew build -x test #test 코드 빼고 돌리기 | |
- name: Docker meta | |
id: docker_meta | |
uses: crazy-max/ghaction-docker-meta@v1 | |
with: | |
images: limhwasup/gifty-server-prod | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker build & push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile.prod | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
- name: create remote directory | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ubuntu | |
key: ${{ secrets.KEY_DEV }} | |
script: mkdir -p ~/srv/ubuntu/gifty-prod | |
- name: copy source via ssh key | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr --delete | |
remote_path: ~/srv/ubuntu/gifty-prod | |
remote_host: ${{ secrets.HOST_DEV }} | |
remote_user: ubuntu | |
remote_key: ${{ secrets.KEY_DEV }} | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ubuntu | |
key: ${{ secrets.KEY_DEV }} | |
script: | | |
sh ~/srv/ubuntu/gifty-prod/config/scripts/deploy.sh | |
sudo docker stop backend-prod | |
sudo docker stop gifty-nginx-prod | |
sudo docker stop gifty-redis-prod | |
sudo docker rm backend-prod | |
sudo docker rm gifty-nginx-prod | |
sudo docker rm gifty-redis-prod | |
sudo docker rmi -f $(sudo docker images -q) | |
sudo docker-compose -f ~/srv/ubuntu/gifty-prod/docker-compose-prod.yml pull | |
sudo docker-compose -f ~/srv/ubuntu/gifty-prod/docker-compose-prod.yml up --build -d |