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-
81name : Java CI with Gradle
92
103on :
114 push :
125 branches : [ "develop" ]
13- pull_request :
14- branches : [ "develop" ]
6+
7+ permissions :
8+ contents : read
159
1610jobs :
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
0 commit comments