Merge pull request #152 from farmingsoon/develop #94
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: 'work' | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
update: | |
name: 프로젝트 버전 업데이트 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
build: | |
name: 이미지 빌드 및 도커허브 푸시 | |
runs-on: ubuntu-latest | |
needs: update | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: refs/heads/main | |
- name: application-prod.yml 생성 | |
env: | |
ACTIONS_STEP_DEBUG: true | |
APPLICATION_PROD: ${{ secrets.APPLICATION_PROD_YML }} | |
run: echo "$APPLICATION_PROD" > src/main/resources/application-prod.yml | |
- name: application-secret.yml 생성 | |
env: | |
ACTIONS_STEP_DEBUG: true | |
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET_YML }} | |
run: echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml | |
- name: 테스트용 redis docker로 띄우기 | |
run: | | |
docker run --name redis -d -p 6379:6379 redis:latest | |
- name: jdk 17 설치 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: gradlew 실행 권한 부여 | |
run: chmod +x gradlew | |
- name: gradle 빌드 | |
run: ./gradlew build --no-daemon -i | |
- name: build 폴더를 캐시에 저장 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifact | |
path: build | |
retention-days: 1 | |
- name: 도커 이미지 빌드 및 푸시 | |
run: | | |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_REPO }}/farming . | |
docker push ${{ secrets.DOCKER_REPO }}/farming | |
deploy: | |
name: 원격 서버에 배포 | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: 원격 서버에 배포하기 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
port: 22 | |
script: | | |
sudo docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} | |
sudo docker stop farming_app || true | |
sudo docker rm farming_app || true | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/farming | |
sudo docker run --name=farming_app --restart unless-stopped \ | |
-p 8080:8080 -e TZ=Asia/Seoul -d ${{ secrets.DOCKER_REPO }}/farming | |
sudo docker image prune -f |