Skip to content

도보 예상 시간 분 단위 반환하도록 수정 #36

도보 예상 시간 분 단위 반환하도록 수정

도보 예상 시간 분 단위 반환하도록 수정 #36

Workflow file for this run

name: Backend CD
on:
pull_request:
types: [closed]
jobs:
build-and-push:
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
contains(github.event.pull_request.labels.*.name, '🎅🏼deploy')
runs-on: ubuntu-latest
steps:
- name: 리포지토리를 가져옵니다
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: JDK 17을 설치합니다
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Install redis
run: sudo apt-get install -y redis-tools redis-server
- name: Verify that redis is up
run: redis-cli ping
- name: Gradle 명령 실행을 위한 권한을 부여합니다
run: chmod +x gradlew
- name: 변경된 모듈을 체크한다.
id: check_changes
run: |
git fetch origin main
if git diff --name-only HEAD^ HEAD | grep -q "^domain/"; then
echo "domain 모듈이 변경되었습니다."
echo "::set-output name=domain_changed::true"
else
if git diff --name-only HEAD^ HEAD | grep -q "^app-api/"; then
echo "api 모듈이 변경되었습니다."
echo "::set-output name=api_changed::true"
fi
if git diff --name-only HEAD^ HEAD | grep -q "^app-scheduler/"; then
echo "scheduler 모듈이 변경되었습니다."
echo "::set-output name=scheduler_changed::true"
fi
fi
- name: 변경된 모듈을 빌드한다.
run: |
domain_changed=${{ steps.check_changes.outputs.domain_changed }}
api_changed=${{ steps.check_changes.outputs.api_changed }}
scheduler_changed=${{ steps.check_changes.outputs.scheduler_changed }}
if [ "$domain_changed" == "true" ]; then
echo "도메인 모듈 및 하위 모듈을 빌드합니다."
./gradlew build --parallel
else
if [ "$api_changed" == "true" ]; then
echo "api 모듈을 빌드합니다."
./gradlew :app-api:build
fi
if [ "$scheduler_changed" == "true" ]; then
echo "scheduler 모듈을 빌드합니다."
./gradlew :app-scheduler:build
fi
if [ "$api_changed" != "true" ] && [ "$scheduler_changed" != "true" ]; then
echo "모듈에 변경 사항이 없습니다."
fi
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: 도커 로그인
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 도커 이미지 build 후 push (API)
uses: docker/build-push-action@v2
if: |
steps.check_changes.outputs.domain_changed == 'true' ||
steps.check_changes.outputs.api_changed == 'true'
with:
context: ./app-api
file: ./app-api/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.API_IMAGE }}:${{ github.sha }}
platforms: linux/amd64
- name: 도커 이미지 build 후 push (Scheduler)
uses: docker/build-push-action@v2
if: |
steps.check_changes.outputs.domain_changed == 'true' ||
steps.check_changes.outputs.scheduler_changed == 'true'
with:
context: ./app-scheduler
file: ./app-scheduler/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.SCHEDULER_IMAGE }}:${{ github.sha }}
platforms: linux/amd64
deploy-to-ec2:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Install SSH
run: sudo apt update && sudo apt install -y openssh-client
- name: EC2 접속 및 배포 진행
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
export COMMIT_VERSION=${{ github.sha }} &&
./deploy.sh
notify-slack:
runs-on: ubuntu-latest
needs: deploy-to-ec2
steps:
- name: 배포 성공시 Slack으로 알립니다
uses: 8398a7/action-slack@v3
with:
author_name: 배포 성공
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.