๐ง Chore: JVM ์ด๊ธฐ ํ ๋ฐ ์ต๋ ํ ์ค์ ๊ฐ ๋ณ๊ฒฝ #42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Java CI with Gradle | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| paths-ignore: | |
| - ".github/**" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| if: github.event.repository.fork == false | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | |
| # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Build with Gradle Wrapper | |
| run: ./gradlew build | |
| # 3. ๋์ปคํ๋ธ ๋ก๊ทธ์ธ | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # 4. ๋์ปค ํ๋ธ์ ์ด๋ฏธ์ง ํธ์ | |
| - name: Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| context: . | |
| tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
| # 5. GCP ์ธ์ฆ | |
| - name: Authenticate to GCP | |
| id: 'auth' | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} # ์์ฑํ ์ํฌ๋ก๋ ์์ด๋ดํฐํฐ ํ์ ID | |
| service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} # IAM ์๋น์ค ๊ณ์ | |
| # 6. GCP Compute Engine SSH๋ก ๋ฐฐํฌ | |
| - name: Deploy to GCP Compute Engine | |
| id: 'compute-ssh' | |
| uses: 'google-github-actions/ssh-compute@v1' | |
| with: | |
| instance_name: ${{ secrets.GCP_INSTANCE_NAME }} | |
| zone: ${{ secrets.GCP_INSTANCE_ZONE }} | |
| ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
| command: | | |
| mkdir ./${{ github.repository }} | |
| cd ./${{ github.repository }} | |
| ls -al | |
| sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml | |
| sudo docker-compose down | |
| sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }} | |
| sudo docker image prune -a -f | |
| # Example of using the output | |
| - id: 'debug' | |
| run: |- | |
| echo '${{ steps.compute-ssh.outputs.stdout }}' | |
| echo '${{ steps.compute-ssh.outputs.stderr }}' |