Skip to content

Merge pull request #193 from 100-hours-a-week/dev #3

Merge pull request #193 from 100-hours-a-week/dev

Merge pull request #193 from 100-hours-a-week/dev #3

name: 백엔드 DEV CD
on:
workflow_dispatch:
push:
branches:
- main
jobs:
docker-build-and-push:
runs-on: ubuntu-latest
steps:
- name: 리포지토리 체크아웃
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.ACTIONS_TOKEN }}
- name: JDK 17 버전 설치
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Gradle 캐싱
uses: actions/cache@v4
id: cache-gradle
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle 을 통해 빌드
run: |
chmod +x ./gradlew
./gradlew bootJar
- name: Docker 빌드 도구 설정
uses: docker/[email protected]
- name: Docker Hub 로그인
uses: docker/[email protected]
with:
username: ${{ secrets.PROD_DOCKER_HUB_USERNAME }}
password: ${{ secrets.PROD_DOCKER_HUB_ACCESS_TOKEN }}
- name: Docker 이미지 빌드 및 푸시
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile-prod
push: true
platforms: linux/amd64
tags: ${{ secrets.PROD_DOCKER_HUB_REPOSITORY }}:${{ secrets.PROD_IMAGE_TAG }}
docker-pull-and-run:
runs-on: [ self-hosted, Linux, X64, prod ]
needs: [ docker-build-and-push ]
if: ${{ needs.docker-build-and-push.result == 'success' }}
steps:
- name: 도커 허브 리포지토리에서 최신 이미지 가져오기
run: |
sudo docker login --username ${{ secrets.PROD_DOCKER_HUB_USERNAME }} --password ${{ secrets.PROD_DOCKER_HUB_ACCESS_TOKEN }}
sudo docker pull ${{ secrets.PROD_DOCKER_HUB_REPOSITORY }}:${{ secrets.PROD_IMAGE_TAG }}
- name: blue green 배포
run: |
sudo chmod +x deploy.sh
sudo ./deploy.sh
- name: 도커 이미지 정리
run: |
sudo docker image prune --all --force