-
Notifications
You must be signed in to change notification settings - Fork 6
92 lines (80 loc) · 2.68 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: ✨ Celuveat backend PROD CD ✨
env:
PROFILE: prod
IMAGE_TAG: back-dev-${{ secrets.APP_VERSION_TAG }}
DOCKER_CONTAINER_NAME: backend
DOCKER_HUB_REPOSITORY: celuveat/celuveat
SERVER_LOG_DIR_PATH: ~/log
DOCKER_LOG_DIR_PATH: /app/logs
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "backend/**"
jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- name: ✨ Checkout repository
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.ACTION_TOKEN }}
- name: ✨ JDK 17 설정
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: ✨ Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: ✨ Gradlew 권한 설정
run: chmod +x ./gradlew
- name: ✨ Jar 파일 빌드
run: ./gradlew bootJar
- name: ✨ DockerHub에 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: ✨ Docker Image 빌드 후 DockerHub에 Push
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
platforms: linux/arm64
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
backend-docker-pull-and-run:
runs-on: [self-hosted, prod]
if: ${{ needs.backend-docker-build-and-push.result == 'success' }}
needs: [ backend-docker-build-and-push ]
steps:
- name: ✨ DockerHub에서 Image Pull
run: |
docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_PASSWORD }}
docker pull ${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker stop ${{ env.DOCKER_CONTAINER_NAME }} || true
docker container prune -f
docker image prune -f
- name: ✨ Docker Image 실행
run: |
docker run \
-d \
--name ${{ env.DOCKER_CONTAINER_NAME }} \
-p 8080:8080 \
-p 18080:18080 \
-e "SPRING_PROFILES_ACTIVE=${{ env.PROFILE }}" \
-v ${{ env.SERVER_LOG_DIR_PATH }}:${{ env.DOCKER_LOG_DIR_PATH }} \
${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}