-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (138 loc) · 4.26 KB
/
work.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#name: 'work'
#
#on:
# push:
# branches:
# - 'main'
#
#jobs:
# update:
# name: 프로젝트 버전 업데이트
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Set up JDK 17
# uses: actions/setup-java@v2
# with:
# java-version: '17'
# distribution: 'adopt'
#
# build:
# name: 이미지 빌드 및 도커허브 푸시
# runs-on: ubuntu-latest
# needs: update
# steps:
# - uses: actions/checkout@v3
# with:
# ref: refs/heads/main
#
# - name: application-prod.yml 생성
# env:
# ACTIONS_STEP_DEBUG: true
# APPLICATION_PROD: ${{ secrets.APPLICATION_PROD_YML }}
# run: echo "$APPLICATION_PROD" > src/main/resources/application-prod.yml
#
#
# - name: jdk 17 설치
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
# cache: 'gradle'
#
# - name: gradlew 실행 권한 부여
# run: chmod +x gradlew
#
# - name: gradle 빌드
# run: ./gradlew build --no-daemon -i
#
# - name: build 폴더를 캐시에 저장
# uses: actions/upload-artifact@v3
# with:
# name: build-artifact
# path: build
# retention-days: 1
# - name: 도커 이미지 빌드 및 푸시
# run: |
# docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
# docker build -t ${{ secrets.DOCKER_REPO }}/gadduck .
# docker push ${{ secrets.DOCKER_REPO }}/gadduck
# deploy:
# name: 원격 서버에 배포
# runs-on: ubuntu-latest
# needs: build
# steps:
# - name: 원격 서버에 배포하기
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.SSH_HOST }}
# username: ${{ secrets.SSH_USER }}
# key: ${{ secrets.SSH_KEY }}
# port: 22
# script: |
# sudo docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
# sudo docker stop gadduck_app || true
# sudo docker rm gadduck_app || true
# sudo docker pull ${{ secrets.DOCKER_REPO }}/gadduck
# sudo docker run --name=gadduck_app --restart unless-stopped \
# -p 8080:8080 -e TZ=Asia/Seoul -d ${{ secrets.DOCKER_REPO }}/gadduck
# sudo docker image prune -f
name: ✨ gadduck backend PROD CD ✨
on:
push:
branches:
- 'main'
jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest
steps:
- name: ✨ Checkout repository
uses: actions/checkout@v3
with:
ref: refs/heads/main
- name: application-prod.yml 생성
env:
ACTIONS_STEP_DEBUG: true
APPLICATION_PROD: ${{ secrets.APPLICATION_PROD_YML }}
run: echo "$APPLICATION_PROD" > src/main/resources/application-prod.yml
- 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: .
file: ./Dockerfile
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKER_REPO }}/gadduck:latest
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: ✨ 배포 스크립트 실행
run: |
sh /home/ubuntu/deploy.sh