-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (73 loc) · 2.92 KB
/
cd-pipeline.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
name: BE - CD
on:
push:
branches: [main]
paths:
[
"src/**",
"build.gradle",
]
permissions:
contents: read
jobs:
be-test:
name: test spring boot
runs-on: ubuntu-20.04
steps:
- name: setup repo
uses: actions/checkout@v3
- name: setup java 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
cache: gradle
- name: Insert Database Information
run: |
sed -i "s|\${MYSQL_URL}|$MYSQL_URL|g" ./src/main/resources/application-db.yml
sed -i "s|\${MYSQL_USERNAME}|$MYSQL_USERNAME|g" ./src/main/resources/application-db.yml
sed -i "s|\${MYSQL_PASSWORD}|$MYSQL_PASSWORD|g" ./src/main/resources/application-db.yml
sed -i "s|\${CLIENT_ORIGIN}|$CLIENT_ORIGIN|g" ./src/main/resources/application-cors.yml
sed -i "s|\${SECRET_KEY}|$SECRET_KEY|g" ./src/main/resources/application-security.yml
sed -i "s|\${ACCESS_EXPIRED_TIME}|$ACCESS_EXPIRED_TIME|g" ./src/main/resources/application-security.yml
sed -i "s|\${REFRESH_EXPIRED_TIME}|$REFRESH_EXPIRED_TIME|g" ./src/main/resources/application-security.yml
env:
MYSQL_URL: ${{ secrets.MYSQL_URL }}
MYSQL_USERNAME: ${{ secrets.MYSQL_USERNAME }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
CLIENT_ORIGIN: ${{ secrets.CLIENT_ORIGIN }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ACCESS_EXPIRED_TIME: ${{ secrets.ACCESS_EXPIRED_TIME }}
REFRESH_EXPIRED_TIME: ${{ secrets.REFRESH_EXPIRED_TIME }}
- name: use gradle cache
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: grant execute permission for gradlew
run: chmod +x gradlew
- name: build with gradle
run: ./gradlew build
- name: docker build & push
run: |
docker login -u "${{ secrets.DOCKER_ID }}" -p "${{ secrets.DOCKER_PASSWORD }}"
docker build -f Dockerfile -t "${{ secrets.DOCKER_REPO }}"/kkeuroolryo .
docker push "${{ secrets.DOCKER_REPO }}"/kkeuroolryo
- name: run remote ssh command plugin
uses: appleboy/[email protected]
id: deploy-prod
with:
host: "${{ secrets.EC2_HOST }}"
username: "${{ secrets.EC2_USERNAME }}"
key: "${{ secrets.EC2_PRIVATE_KEY }}"
envs: GITHUB_SHA
script: |
docker stop kkeuroolryo
docker rm kkeuroolryo
sudo docker pull "${{ secrets.DOCKER_REPO }}"/kkeuroolryo
docker run -d --name kkeuroolryo -p 8080:8080 "${{ secrets.DOCKER_REPO }}"/kkeuroolryo
docker rmi -f $(docker images -f "dangling=true" -q)