Skip to content

Commit aeb5a2f

Browse files
committed
feat: gradle.yml 파일 수정
- 자동 배포를 위한 yml 파일 수정 - health 코드 추가
1 parent 004ae9c commit aeb5a2f

File tree

2 files changed

+75
-50
lines changed

2 files changed

+75
-50
lines changed

.github/workflows/gradle.yml

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7-
81
name: Java CI with Gradle
92

103
on:
114
push:
125
branches: [ "develop" ]
13-
pull_request:
14-
branches: [ "develop" ]
6+
7+
permissions:
8+
contents: read
159

1610
jobs:
1711
build:
18-
1912
runs-on: ubuntu-latest
20-
permissions:
21-
contents: read
22-
2313
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up JDK 17
26-
uses: actions/setup-java@v4
27-
with:
28-
java-version: '17'
29-
distribution: 'temurin'
3014

31-
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
32-
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
33-
- name: Setup Gradle
34-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
15+
- name: checkout
16+
uses: actions/checkout@v3
3517

36-
- name: Build with Gradle Wrapper
37-
run: ./gradlew build
18+
- name: Set up JDK 17
19+
uses: actions/setup-java@v3
20+
with:
21+
java-version: '17'
22+
distribution: 'temurin'
3823

39-
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
40-
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
41-
#
42-
# - name: Setup Gradle
43-
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
44-
# with:
45-
# gradle-version: '8.9'
46-
#
47-
# - name: Build with Gradle 8.9
48-
# run: gradle build
24+
## create application-database.yaml
25+
- name: make application-database.yaml
26+
run: |
27+
## create application-database.yaml
28+
cd ./src/main/resources
29+
30+
# application.yaml 파일 생성
31+
touch ./application.properties
32+
33+
# GitHub-Actions 에서 설정한 전체 값을 application.properties 파일에 쓰기
34+
echo "${{ secrets.APPLICATION }}" >> ./application.properties
35+
shell: bash
4936

50-
dependency-submission:
37+
## gradle build
38+
- name: Build with Gradle
39+
run: ./gradlew bootJar
5140

52-
runs-on: ubuntu-latest
53-
permissions:
54-
contents: write
41+
## 원격 서버에서 docker-compose 실행
42+
- name: Build and Run Docker on Server
43+
uses: appleboy/ssh-action@master
44+
with:
45+
host: ${{ secrets.HOST }}
46+
username: ${{ secrets.USERNAME }}
47+
key: ${{ secrets.PRIVATE_KEY }}
48+
port: ${{ secrets.PORT }}
49+
script: |
50+
# 최신 코드 가져오기
51+
cd /home/ubuntu/server
52+
git pull origin develop
5553
56-
steps:
57-
- uses: actions/checkout@v4
58-
- name: Set up JDK 17
59-
uses: actions/setup-java@v4
60-
with:
61-
java-version: '17'
62-
distribution: 'temurin'
54+
# application.properties 새로 생성
55+
echo "${{ secrets.APPLICATION }}" | sudo tee /home/ubuntu/server/src/main/resources/application.properties > /dev/null
56+
57+
# 🔹 JAR 빌드 (서버에서 실행)
58+
./gradlew bootJar
59+
60+
# 파일명 변경
61+
mv /home/ubuntu/server/build/libs/SoundLink_Java-0.0.1-SNAPSHOT.jar /home/ubuntu/docker/soundlink.jar
62+
63+
# 기존 Spring 컨테이너 중지 및 제거
64+
sudo docker-compose stop spring
65+
sudo docker-compose rm -f spring
66+
67+
# Spring 컨테이너만 다시 빌드 & 실행
68+
cd /home/ubuntu/docker
69+
sudo docker-compose -f docker-compose.yml build --no-cache spring
70+
sudo docker-compose -f docker-compose.yml up -d spring
6371
64-
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
65-
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
66-
- name: Generate and submit dependency graph
67-
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
72+
# 불필요한 이미지 정리
73+
sudo docker image prune -f
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.dfbf.soundlink.global;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.dfbf.soundlink.global.exception.ErrorCode;
5+
import org.dfbf.soundlink.global.exception.ResponseResult;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
@RequiredArgsConstructor
12+
public class Controller {
13+
14+
// health check
15+
@GetMapping("/health")
16+
public ResponseResult health() {
17+
return new ResponseResult(ErrorCode.SUCCESS,"ok");
18+
}
19+
}

0 commit comments

Comments
 (0)