diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbe1bad..d577356 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,15 +33,13 @@ jobs: cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} - run: ./gradlew assemble check + deploy: name: Build and push container image to Google Artifact Registry, deploy to Cloud Run needs: [ assemble-and-check ] if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest env: - CONTAINER_IMAGE: ${{ secrets.GCP_CONTAINER_IMAGE }} - REGION: ${{ secrets.GCP_REGION }} - SERVICE_NAME: ${{ secrets.GCP_SERVICE_NAME }} CPU: 4 MEMORY: 2Gi MIN_INSTANCES: 0 @@ -64,7 +62,7 @@ jobs: - uses: docker/login-action@v3 with: - registry: ${{ env.REGION }}-docker.pkg.dev + registry: ${{ env.GCP_REGION }}-docker.pkg.dev username: _json_key password: ${{ secrets.GCP_CREDENTIALS_JSON }} @@ -76,7 +74,7 @@ jobs: with: context: . push: true - tags: ${{ env.CONTAINER_IMAGE }}:${{ env.SHA_SHORT }},${{ env.CONTAINER_IMAGE }}:latest + tags: ${{ env.GCP_CONTAINER_IMAGE }}:${{ env.SHA_SHORT }},${{ env.GCP_CONTAINER_IMAGE }}:latest - uses: google-github-actions/auth@v2 with: @@ -86,9 +84,9 @@ jobs: - name: Deploy to Cloud Run run: | - gcloud run deploy ${{ env.SERVICE_NAME }} \ - --image ${{ env.CONTAINER_IMAGE }}:${{ env.SHA_SHORT }} \ - --region ${{ env.REGION }} \ + gcloud run deploy ${{ env.GCP_SERVICE_NAME }} \ + --image ${{ env.GCP_CONTAINER_IMAGE }}:${{ env.SHA_SHORT }} \ + --region ${{ env.GCP_REGION }} \ --cpu ${{ env.CPU }} \ --memory ${{ env.MEMORY }} \ --timeout ${{ env.REQUEST_TIMEOUT }} \ @@ -100,13 +98,13 @@ jobs: - name: Cleanup old images run: | # Get all images except the most recent 2 - IMAGES_TO_DELETE=$(gcloud artifacts docker images list ${{ env.CONTAINER_IMAGE }} \ + IMAGES_TO_DELETE=$(gcloud artifacts docker images list ${{ env.GCP_CONTAINER_IMAGE }} \ --format="get(DIGEST)" \ --sort-by="~CREATE_TIME" | tail -n +3) # Delete the older images for DIGEST in $IMAGES_TO_DELETE; do - gcloud artifacts docker images delete ${{ env.CONTAINER_IMAGE }}@$DIGEST \ + gcloud artifacts docker images delete ${{ env.GCP_CONTAINER_IMAGE }}@$DIGEST \ --delete-tags \ --quiet done