-
Notifications
You must be signed in to change notification settings - Fork 4
76 lines (63 loc) · 2.13 KB
/
backend-prod-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: 백엔드 PROD 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