From b0382dfd1c563c78b509fa62f578efc20aa0c47c Mon Sep 17 00:00:00 2001 From: pwei1018 Date: Tue, 16 Jul 2024 09:24:43 -0700 Subject: [PATCH] Fixed deploy target issue. --- .../actions/backend-deploy-job/files/cloudbuild.yaml | 8 ++++++-- .github/actions/backend-deploy/files/cloudbuild.yaml | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/actions/backend-deploy-job/files/cloudbuild.yaml b/.github/actions/backend-deploy-job/files/cloudbuild.yaml index 31c818fc..2ed1806b 100644 --- a/.github/actions/backend-deploy-job/files/cloudbuild.yaml +++ b/.github/actions/backend-deploy-job/files/cloudbuild.yaml @@ -65,6 +65,10 @@ steps: script: | #!/usr/bin/env bash + PROJECT_ID=$(cat /workspace/project_id.txt) + PROJECT_NAME=$(echo $PROJECT_ID | cut -d'-' -f 1) + TARGE_ENV=${PROJECT_NAME}-${_DEPLOY_TARGET} + # tag image gcloud artifacts docker tags add \ ${_REGION}-docker.pkg.dev/${_DEPLOY_RUNNING_PROJECT_ID}/cloud-run-repo/${_APP_NAME}:$_SHORT_SHA \ @@ -78,7 +82,7 @@ steps: gcloud deploy releases create v-$_SHORT_SHA-${RELEASE_TIMESTAMP} \ --delivery-pipeline=${_DEPLOY_PIPELINE} \ --region=${_REGION} \ - --to-target=${_DEPLOY_TARGET} \ + --to-target=${TARGE_ENV} \ --images=image-placeholder=${_REGION}-docker.pkg.dev/${_DEPLOY_RUNNING_PROJECT_ID}/cloud-run-repo/${_APP_NAME}:$_SHORT_SHA else # prompt the existing release @@ -94,7 +98,7 @@ steps: gcloud deploy releases promote --release=${LATEST_RELEASE_NAME} \ --delivery-pipeline=${_DEPLOY_PIPELINE}\ --region=${_REGION} \ - --to-target=${_DEPLOY_TARGET} + --to-target=${TARGE_ENV} fi # handle multiple jobs diff --git a/.github/actions/backend-deploy/files/cloudbuild.yaml b/.github/actions/backend-deploy/files/cloudbuild.yaml index 3722a08c..ba5f988a 100644 --- a/.github/actions/backend-deploy/files/cloudbuild.yaml +++ b/.github/actions/backend-deploy/files/cloudbuild.yaml @@ -24,7 +24,9 @@ steps: script: | #!/usr/bin/env bash - PROJECT_NAME=$(op read -n op://CD/${_DEPLOY_TARGET}/${_APP_NAME}/DEPLOY_PROJECT_ID | cut -d'-' -f 1) + PROJECT_ID=$(op read -n op://CD/${_DEPLOY_TARGET}/${_APP_NAME}/DEPLOY_PROJECT_ID) + echo $PROJECT_ID > /workspace/project_id.txt + PROJECT_NAME=$(echo $PROJECT_ID | cut -d'-' -f 1) targets=(${_DEPLOY_TARGETS}) if [ -z ${_DEPLOY_TARGET_FROM} ] || [ ${_DEPLOY_TARGET_FROM} = ${targets[0]} ]; then @@ -75,6 +77,10 @@ steps: script: | #!/usr/bin/env bash + PROJECT_ID=$(cat /workspace/project_id.txt) + PROJECT_NAME=$(echo $PROJECT_ID | cut -d'-' -f 1) + TARGE_ENV=${PROJECT_NAME}-${_DEPLOY_TARGET} + # tag image gcloud artifacts docker tags add \ ${_REGION}-docker.pkg.dev/${_DEPLOY_RUNNING_PROJECT_ID}/cloud-run-repo/${_APP_NAME}:$_SHORT_SHA \ @@ -88,7 +94,7 @@ steps: gcloud deploy releases create v-${_APP_NAME}-${_SHORT_SHA}-${RELEASE_TIMESTAMP} \ --delivery-pipeline=${_DEPLOY_PIPELINE} \ --region=${_REGION} \ - --to-target=${_DEPLOY_TARGET} \ + --to-target=${TARGE_ENV} \ --images=image-placeholder=${_REGION}-docker.pkg.dev/${_DEPLOY_RUNNING_PROJECT_ID}/cloud-run-repo/${_APP_NAME}:$_SHORT_SHA else # prompt the existing release @@ -104,7 +110,7 @@ steps: gcloud deploy releases promote --release=${LATEST_RELEASE_NAME} \ --delivery-pipeline=${_DEPLOY_PIPELINE}\ --region=${_REGION} \ - --to-target=${_DEPLOY_TARGET} + --to-target=${TARGE_ENV} fi availableSecrets: