forked from codesquad-members-2023/second-hand-max
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (91 loc) · 3.16 KB
/
auto-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
name: issue-tracker auto deploy
on:
push:
branches: [ "test1" ]
permissions:
contents: read
env:
BE_WORKING_DIR: ./secondhand
NGINX_WORKING_DIR: ./nginx
APPLICATION_FILE_PATH: ./src/main/resources/application.yml
jobs:
# Job[1]: BACKEND -> docker hub로 build & push
be-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.BE_WORKING_DIR }}
services:
mysql_db:
image: mysql:8.0
ports:
- 3306:3306 # HOST:CONTAINER
env:
MYSQL_DATABASE: second_hand
MYSQL_USER: root
MYSQL_PASSWORD: 1234
steps:
# 1. Source 단계
- name: Checkout Source Code
uses: actions/checkout@v3
# JDK 세팅
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# 2. yml 파일 변경
- name: Change Spring Active Profile
run: |
touch '${{ env.APPLICATION_FILE_PATH }}'
echo '${{ secrets.APPLICATION }}' > '${{ env.APPLICATION_FILE_PATH }}'
# 4. Redis 설치 및 실행
- name: Install and Start Redis Server
run: |
sudo apt-get update
sudo apt-get install -y redis-server
sudo service redis-server start
# 3. build 단계
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build -Djasypt.encryptor.password=${{ secrets.JASYPT_SECRET }}
# 4. docker hub로 build & push
- name: docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest
# job[2]: nginx -> docker hub로 build & push
nginx-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.NGINX_WORKING_DIR }}
steps:
# 1. Source 단계
- name: Checkout Source Code
uses: actions/checkout@v3
# 2. docker hub로 build & push
- name: docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest
# job[3]: EC2에서 docker 이미지 pull하고 실행
SSH-Transfer:
needs: [ be-deploy, nginx-deploy ]
runs-on: ubuntu-latest
steps:
- name: SSH Transfer
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
sudo docker-compose down -v
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest
sudo docker-compose up -d
sudo docker image prune -a -f