fix : workflow 에 cd 를 통한 이동 구문 추가 #13
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: Backend production CI/CD | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [ main ] | ||
types: [ closed ] | ||
paths: backend/** | ||
permissions: | ||
contents: read | ||
jobs: | ||
build-and-upload: | ||
if: github.event.pull_request.merged | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.SUBMODULE_ACCESS_TOKEN }} | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
- name: 테스트 환경변수 설정 | ||
run: | | ||
echo "TEST_JWT_SECRET_KEY=${{ secrets.TEST_JWT_SECRET_KEY }}" >> $GITHUB_ENV | ||
echo "TEST_JWT_EXPIRE_LENGTH=${{ secrets.TEST_JWT_EXPIRE_LENGTH }}" >> $GITHUB_ENV | ||
- name: gradlew 실행 권한 부여 | ||
run: chmod +x gradlew | ||
working-directory: backend | ||
- name: Gradle build 시작 | ||
run: ./gradlew clean build | ||
working-directory: backend | ||
- name: Docker buildx 설치 | ||
uses: docker/[email protected] | ||
- name: Docker Hub 로그인 | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_DEV_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_DEV_TOKEN }} | ||
- name: Docker Image Build | ||
working-directory: backend | ||
run: docker build --platform linux/arm64/v8 -t mapbefine/mapbefine -f Dockerfile-dev . | ||
- name: Docker Hub Push | ||
run: docker push mapbefine/mapbefine | ||
deploy: | ||
if: github.event.pull_request.merged | ||
runs-on: [ self-hosted, prod ] | ||
needs: build-and-upload | ||
steps: | ||
- name: 최신 Docker Image 가져오기 | ||
run: | | ||
sudo docker login --username ${{ secrets.DOCKERHUB_DEV_USERNAME }} --password ${{ secrets.DOCKERHUB_DEV_TOKEN }} | ||
sudo docker pull mapbefine/mapbefine:latest | ||
- name: Docker Compose | ||
run: | | ||
cd /home/ubuntu/backend | ||
sudo sh zero-downtime-deploy.sh | ||
sudo docker image prune -af | ||
- name: 슬랙 메시지 보내기 | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
mention: 'here' | ||
if_mention: always | ||
status: ${{ job.status }} | ||
fields: workflow,job,commit,message,ref,author,took | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
if: always() |