-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (64 loc) · 3.11 KB
/
gradle.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
name: SB CI/CD with Gradle
on:
push:
branches: ["main", "dev"]
pull_request:
branches: ["main", "dev"]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set prod.yml
run: |
cd ./src/main/resources
sed -i 's|${DB_URL}|'"${{ secrets.DB_URL }}"'|g' application-prod.yml
sed -i 's|${DB_USER}|'"${{ secrets.DB_USER }}"'|g' application-prod.yml
sed -i 's|${DB_PW}|'"${{ secrets.DB_PW }}"'|g' application-prod.yml
sed -i 's|${S3_BUCKET}|'"${{ secrets.S3_BUCKET }}"'|g' application-prod.yml
sed -i 's|${S3_REGION}|'"${{ secrets.S3_REGION }}"'|g' application-prod.yml
sed -i 's|${S3_ACCESS_KEY}|'"${{ secrets.S3_ACCESS_KEY }}"'|g' application-prod.yml
sed -i 's|${S3_SECRET_KEY}|'"${{ secrets.S3_SECRET_KEY }}"'|g' application-prod.yml
sed -i 's|${KAKAO_CLIENT_ID}|'"${{ secrets.KAKAO_CLIENT_ID }}"'|g' application-prod.yml
sed -i 's|${KAKAO_CLIENT_SECRET}|'"${{ secrets.KAKAO_CLIENT_SECRET }}"'|g' application-prod.yml
- name: Grant permission
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_NAME }}
key: ${{ secrets.EC2_KEY }}
port: 22
script: |
sudo usermod -aG docker $USER
sudo docker stop showhoo-server || true
sudo docker rm showhoo-server || true
sudo docker image rm ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} || true
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
sudo docker run -e SPRING_PROFILES_ACTIVE=prod \
-e DB_URL=${{ secrets.DB_URL }} \
-e DB_USER=${{ secrets.DB_USER }} \
-e DB_PASSWORD=${{ secrets.DB_PW }} \
-e S3_BUCKET=${{ secrets.S3_BUCKET }} \
-e S3_REGION=${{ secrets.S3_REGION }} \
-e S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \
-e S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} \
-e KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} \
-e KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }} \
-e EC2_HOST=${{ secrets.EC2_HOST }} \
--name showhoo-server -p 8081:8081 -d ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}