-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (90 loc) · 3.37 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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Deploy to Prod
on:
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Cache Gradle packages #속도를 빠르게
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-
#
- name: Grant execute permission for gradlew #권한
run: chmod +x gradlew
- name: Make application-prod.properties #환경변수 주입
run: |
touch ./src/main/resources/application-prod.properties
echo "$PROPERTIES_PROD" > ./src/main/resources/application-prod.properties
env:
PROPERTIES_PROD: ${{ secrets.PROPERTIES_PROD }}
- name: Build with Gradle
run: ./gradlew build -x test #test 코드 빼고 돌리기
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: kimwonjin/oeuvre-server-prod
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- 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 }}
- name: create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.KEY_PROD }}
script: mkdir -p ~/srv/ubuntu/oeuvre-prod
- name: copy source via ssh key
uses: burnett01/rsync-deployments@4.1
with:
switches: -avzr --delete
remote_path: ~/srv/ubuntu/oeuvre-prod
remote_host: ${{ secrets.HOST_PROD }}
remote_user: ubuntu
remote_key: ${{ secrets.KEY_PROD }}
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.KEY_PROD }}
script: |
sh ~/srv/ubuntu/oeuvre-prod/config/scripts/deploy.sh
sudo docker stop backend-prod
sudo docker rm backend-prod
sudo docker rmi $(sudo docker images -q)
sudo docker-compose -f ~/srv/ubuntu/oeuvre-prod/docker-compose-prod.yml pull
sudo docker-compose -f ~/srv/ubuntu/oeuvre-prod/docker-compose-prod.yml up --build -d