-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) ยท 2.41 KB
/
CD-dev.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
name: CD
on:
push: #ํด๋น ๋ธ๋์น์ push(merge) ํ์ ๋
branches:
- qa
permissions: write-all #ํ
์คํธ ๊ฒฐ๊ณผ ์์ฑ์ ์ํด ์ฐ๊ธฐ๊ถํ ์ถ๊ฐ
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1) ์ํฌํ๋ก์ฐ ์คํ ์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฒดํฌ์์ ํ์
- uses: actions/checkout@v3
# 2) JDK 17 ๋ฒ์ ์ค์น
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
# 3) Gradle Caching
- name: Gradle Cashing
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 4) Gradle ๊ถํ ๋ถ์ฌ
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 5) Set for application-secret.yml
- name: Make application-secret.yml
run: |
cd ./src/main/resources
touch ./application-secret.yml
echo "${{ secrets.PROPERTIES_SECRET }}" > ./application-secret.yml
shell: bash
# 6) ๋ก๊ทธ xml ํ์ผ ์ค์
- name: Make logback-spring.xml
run: |
cd ./src/main/resources
touch ./logback-spring.xml
echo "${{ secrets.LOGBACK_SPRING }}" > ./logback-spring.xml
shell: bash
# 7) jar ํ์ผ ์์ฑ
- name: Build With Gradle
run: ./gradlew bootJar
# 8) Docker ๋น๋ & ํธ์ฌ
- name: docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}}
# 9) Deploy (DEV-Server)
- name: Deploy (DEV)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
script: |
docker stop server
docker rm server
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY}}:latest
sudo docker-compose up -d
docker rmi -f $(docker images -f "dangling=true" -q)