-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (102 loc) · 3.73 KB
/
prod-deploy.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
name: Deploy to Prod
## main에 릴리즈가 일어날 때마다 빌드 및 배포
on:
push:
branches: [ main ]
tags: [ "v*.*.*" ]
jobs:
build:
## checkout 후 자바 17 버전으로 설정
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## gradlew에 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
## Copy properties files
- name: Make application.yml
run: |
echo "$PROFILE_PROD" > ./src/main/resources/application.yml
# Make env file
env:
PROFILE_PROD: ${{ secrets.PROFILE_PROD }}
## Copy properties files
- name: Make application-prod.yml
run: |
touch ./src/main/resources/application-prod.yml
echo "$PROPERTIES_PROD" > ./src/main/resources/application-prod.yml
# Make env file
env:
PROPERTIES_PROD: ${{ secrets.PROPERTIES_PROD }}
## gradle build
- name: Build with Gradle
run: ./gradlew clean build
## docker metadata(namespace/repository)
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: jeonhaeseung/ness-server-prod
tag-semver: |
{{version}}
{{major}}.{{minor}}
## 멀티-플랫폼 빌드 도구 Buildx 사용
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
## DockerHub에 로그인
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
## 위에서 설정한 테그를 참고해 push
- name: Docker build & push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.prod
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
## 원격에 접속 및 디렉토리 생성
- name: create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USER_PROD }}
key: ${{ secrets.KEY_PROD }}
script: mkdir -p ./ness
## 소스 코드 복사 붙여넣기
- name: copy source via ssh key
uses: burnett01/[email protected]
with:
switches: -avzr --delete
path: ./config
remote_path: ./ness
remote_host: ${{ secrets.HOST_PROD }}
remote_user: ${{ secrets.USER_PROD }}
remote_key: ${{ secrets.KEY_PROD }}
## EC2에 배포(CD)
## 아래 두 개는 이미 되어 있는 상태
## docker network create ness_network
## docker network connect ness_network redis-server
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USER_PROD }}
key: ${{ secrets.KEY_PROD }}
script: |
sh ./prod/config/scripts/deploy.sh
sudo docker stop $(sudo docker ps -a --filter="name=backend-server" -q)
sudo docker rm $(sudo docker ps -a --filter="name=backend-server" -q)
sudo docker rmi $(sudo docker images -q)
docker pull jeonhaeseung/ness-server-prod:main
docker run -d --name backend-server -p 80:8080 --restart unless-stopped jeonhaeseung/ness-server-prod:main
docker network connect ness_network backend-server