-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (72 loc) ยท 2.65 KB
/
github-actions.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
# github repository actions ํ์ด์ง์ ๋ํ๋ ์ด๋ฆ
name: CI/CD using github actions & docker
# event trigger
# main์ด๋ develop ๋ธ๋์น์ push๊ฐ ๋์์ ๋ ์คํ
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
# JDK setting - github actions์์ ์ฌ์ฉํ JDK ์ค์ (ํ๋ก์ ํธ๋ AWS์ java ๋ฒ์ ๊ณผ ๋ฌ๋ผ๋ ๋ฌด๋ฐฉ)
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# gradle caching - ๋น๋ ์๊ฐ ํฅ์
- 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-
# ํ๊ฒฝ๋ณ yml ํ์ผ ์์ฑ - application.yml
- name: make application.yml
if: |
contains(github.ref, 'main')
run: |
mkdir ./planfit/src/main/resources # resources ํด๋ ์์ฑ
cd ./planfit/src/main/resources # resources ํด๋๋ก ์ด๋
touch ./application.yml # application.yml ์์ฑ
echo "${{ secrets.YML }}" > ./application.yml # github actions์์ ์ค์ ํ ๊ฐ์ application.yml ํ์ผ์ ์ฐ๊ธฐ
shell: bash
# gradle build
- name: Build with Gradle
run: |
./planfit/gradlew build --project-dir ./planfit -x test
# docker login
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# docker build & push to production
- name: Docker build & push to prod
if: contains(github.ref, 'main')
run: |
pwd
docker build -f ./planfit/Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/planfit .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/planfit
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST_PROD }} # EC2 ํผ๋ธ๋ฆญ IPv4 DNS
username: ubuntu
key: ${{ secrets.PEM_KEY }}
envs: GITHUB_SHA
script: |
sudo docker ps
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/planfit
sudo docker run -d -p 8081:8081 ${{ secrets.DOCKERHUB_USERNAME }}/planfit
sudo docker image prune -f