Skip to content

Commit

Permalink
Separate secrets and variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Aug 17, 2024
1 parent d0ec142 commit ee2a518
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

Expand All @@ -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:
Expand All @@ -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 }} \
Expand All @@ -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

0 comments on commit ee2a518

Please sign in to comment.