|
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 | | - |
8 | 1 | name: Java CI with Gradle |
9 | 2 |
|
10 | 3 | on: |
11 | 4 | push: |
12 | | - branches: [ "main" ] |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
13 | 8 |
|
14 | 9 | jobs: |
15 | 10 | build: |
16 | | - if: github.event.repository.fork == false |
17 | 11 | runs-on: ubuntu-latest |
18 | 12 | permissions: |
19 | | - id-token: write |
20 | 13 | contents: read |
21 | | - |
22 | 14 | steps: |
23 | | - - uses: actions/checkout@v4 |
24 | | - - name: Set up JDK 21 |
25 | | - uses: actions/setup-java@v4 |
26 | | - with: |
27 | | - java-version: '21' |
28 | | - distribution: 'temurin' |
29 | | - |
30 | | - # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. |
31 | | - # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md |
32 | | - - name: Setup Gradle |
33 | | - uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |
34 | | - |
35 | | - - name: Build with Gradle Wrapper |
36 | | - run: ./gradlew build |
37 | | - |
38 | | - # 3. 도커허브 로그인 |
39 | | - - name: Login to DockerHub |
40 | | - uses: docker/login-action@v3 |
41 | | - with: |
42 | | - username: ${{ secrets.DOCKER_USERNAME }} |
43 | | - password: ${{ secrets.DOCKER_PASSWORD }} |
44 | | - |
45 | | - # 4. 도커 허브에 이미지 푸시 |
46 | | - - name: Push Docker Image |
47 | | - uses: docker/build-push-action@v6 |
48 | | - with: |
49 | | - push: true |
50 | | - context: . |
51 | | - tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest |
52 | | - |
53 | | - # 5. GCP 인증 |
54 | | - - name: Authenticate to GCP |
55 | | - id: 'auth' |
56 | | - uses: 'google-github-actions/auth@v2' |
57 | | - with: |
58 | | - workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} # 생성한 워크로드 아이덴티티 풀의 ID |
59 | | - service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} # IAM 서비스 계정 |
60 | | - |
61 | | - # 6. GCP Compute Engine SSH로 배포 |
62 | | - - name: Deploy to GCP Compute Engine |
63 | | - id: 'compute-ssh' |
64 | | - uses: 'google-github-actions/ssh-compute@v1' |
65 | | - with: |
66 | | - instance_name: ${{ secrets.GCP_INSTANCE_NAME }} |
67 | | - zone: ${{ secrets.GCP_INSTANCE_ZONE }} |
68 | | - ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} |
69 | | - command: | |
70 | | - mkdir ./${{ github.repository }} |
71 | | - cd ./${{ github.repository }} |
72 | | - ls -al |
73 | | - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml |
74 | | - sudo docker-compose down |
75 | | - sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }} |
76 | | - sudo docker image prune -a -f |
77 | | -
|
78 | | - # Example of using the output |
79 | | - - id: 'debug' |
80 | | - run: |- |
81 | | - echo '${{ steps.compute-ssh.outputs.stdout }}' |
82 | | - echo '${{ steps.compute-ssh.outputs.stderr }}' |
83 | | -
|
84 | | -
|
85 | | - dependency-submission: |
86 | | - |
87 | | - runs-on: ubuntu-latest |
88 | | - permissions: |
89 | | - contents: write |
90 | | - |
91 | | - steps: |
92 | | - - uses: actions/checkout@v4 |
93 | | - - name: Set up JDK 17 |
94 | | - uses: actions/setup-java@v4 |
95 | | - with: |
96 | | - java-version: '21' |
97 | | - distribution: 'temurin' |
98 | | - |
99 | | - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. |
100 | | - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md |
101 | | - - name: Generate and submit dependency graph |
102 | | - uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up JDK 21 |
| 18 | + uses: actions/setup-java@v4 |
| 19 | + with: |
| 20 | + java-version: '21' |
| 21 | + distribution: 'temurin' |
| 22 | + |
| 23 | + - name: Setup Gradle |
| 24 | + uses: gradle/actions/setup-gradle@v4 |
| 25 | + |
| 26 | + - name: Build with Gradle |
| 27 | + run: ./gradlew build |
| 28 | + |
| 29 | + # 빌드 결과물을 아티팩트로 업로드 (JAR 파일) |
| 30 | + - name: Upload JAR Artifact |
| 31 | + uses: actions/upload-artifact@v4 |
| 32 | + with: |
| 33 | + name: application-jar |
| 34 | + path: build/libs/*.jar |
0 commit comments