From 061d2cc74792ac3029daaff42ab307fb6ea0a5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jinsoo=20Choi=20=28=EC=B5=9C=EC=A7=84=EC=88=98=29?= Date: Mon, 20 May 2024 01:04:28 +0900 Subject: [PATCH] Update gradle.yml --- .github/workflows/gradle.yml | 122 +++++++++++++++-------------------- 1 file changed, 53 insertions(+), 69 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index ccb1e67..d701a0f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,96 +1,80 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - name: Java CI with Gradle on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: - runs-on: ubuntu-latest permissions: contents: read steps: - - uses: actions/checkout@v4 - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' - - name: Copy application.properties into runner - run: | - mkdir -p ./src/main/resources - touch ./src/main/resources/application.properties - echo "${{secrets.APPLICATION_YML}}" > ./src/main/resources/application.properties + - name: Copy application.properties into runner + run: | + mkdir -p ./src/main/resources + touch ./src/main/resources/application.properties + echo "${{secrets.APPLICATION_YML}}" > ./src/main/resources/application.properties - - name: Build with Gradle - run: | - chmod +x gradlew - ./gradlew build + - name: Build with Gradle + run: | + chmod +x gradlew + ./gradlew build - - name: Docker Login - # You may pin to the exact commit or the version. - # uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 - uses: docker/login-action@v3.1.0 - with: - # Server address of Docker registry. If not set then will default to Docker Hub - registry: ghcr.io - # Username used to log against the Docker registry - username: ${{ secrets.GHCR_USERNAME }} - # Password or personal access token used to log against the Docker registry - password: ${{ secrets.GHCR_PASSWORD }} + - name: Docker Login + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USERNAME }} + password: ${{ secrets.GHCR_PASSWORD }} - - name: Build Docker - run: | - docker build -t ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest . + - name: Build Docker + run: | + docker build -t ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest . - - name: Push Docker - run: docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest + - name: Push Docker + run: docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest deploy: - runs-on: ubuntu-latest permissions: write-all needs: build steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Copy docker-compose into instance - uses: appleboy/scp-action@master #이미 존재하는 경우 덮어씀 - with: - host: ${{secrets.GCP_HOST}} - username: ${{secrets.GCP_USERNAME}} - key: ${{secrets.GCP_PRIVATEKEY}} - source: "./docker-compose.yml" - target: "/home/${{secrets.GCP_USERNAME}}" - strip_components: 3 - overwrite: true - debug: true - - + - name: Copy docker-compose into instance + uses: appleboy/scp-action@master + with: + host: ${{ secrets.GCP_HOST }} + username: ${{ secrets.GCP_USERNAME }} + key: ${{ secrets.GCP_PRIVATEKEY }} + source: "./docker-compose.yml" + target: "/home/${{ secrets.GCP_USERNAME }}" + strip_components: 3 + overwrite: true + debug: true - - name: Deploy to Instance - uses: appleboy/ssh-action@master - with: - host: ${{secrets.GCP_HOST}} - username: ${{secrets.GCP_USERNAME}} - key: ${{secrets.GCP_PRIVATEKEY}} - script: | - sudo docker login -u ${{ secrets.GHCR_USERNAME }} -p ${{ secrets.GHCR_PASSWORD }} - sudo docker pull ${{ secrets.GHCR_USERNAME }}/ssock:latest - sudo docker rm -f $(docker ps -qa) 2>/dev/null || true - cd /home/${{secrets.GCP_USERNAME}} - sudo docker-compose up -d - sudo docker image prune -f + - name: Deploy to Instance + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.GCP_HOST }} + username: ${{ secrets.GCP_USERNAME }} + key: ${{ secrets.GCP_PRIVATEKEY }} + script: | + echo ${{ secrets.GHCR_PASSWORD }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin + sudo docker pull ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest + sudo docker rm -f $(sudo docker ps -qa) || true + cd /home/${{ secrets.GCP_USERNAME }} + sudo docker-compose up -d + sudo docker image prune -f