From 7d83da4e8efc8d7cb461d6f560f9a1e98e1e5d5b Mon Sep 17 00:00:00 2001 From: Jaryt Date: Thu, 20 Oct 2022 16:12:31 -0400 Subject: [PATCH 1/3] feat!: decouple from gcp cli --- src/@orb.yml | 1 - src/commands/gcr-auth.yml | 25 ----------------- src/examples/build-and-push-digest.yml | 4 +++ src/examples/optimized-build-and-push.yml | 2 ++ src/jobs/add-image-tag.yml | 22 ++------------- src/jobs/build-and-push-image.yml | 15 +---------- src/scripts/gcr-auth.sh | 33 +++++++++++++++++++++++ 7 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/@orb.yml b/src/@orb.yml index b9add74..a23d64e 100644 --- a/src/@orb.yml +++ b/src/@orb.yml @@ -9,4 +9,3 @@ display: orbs: docker: circleci/docker@1.5 - gcp-cli: circleci/gcp-cli@2.1 diff --git a/src/commands/gcr-auth.yml b/src/commands/gcr-auth.yml index 8f82616..e25db9a 100644 --- a/src/commands/gcr-auth.yml +++ b/src/commands/gcr-auth.yml @@ -2,11 +2,6 @@ description: > Configure Docker to use gcloud as a credential helper. Using this command requires the use of a 'machine' executor. parameters: - gcloud-service-key: - type: env_var_name - default: GCLOUD_SERVICE_KEY - description: The gcloud service key - google-project-id: type: env_var_name default: GOOGLE_PROJECT_ID @@ -14,18 +9,6 @@ parameters: Environment variable name for the Google project ID to connect with via the gcloud CLI - google-compute-zone: - type: env_var_name - default: GOOGLE_COMPUTE_ZONE - description: > - The Google compute zone to connect with via the gcloud CLI - - google-compute-region: - type: env_var_name - default: GOOGLE_COMPUTE_REGION - description: > - The Google compute region to connect with via the gcloud CLI - registry-url: description: > The GCR registry URL from ['', us, eu, asia].gcr.io, @@ -34,14 +17,6 @@ parameters: default: gcr.io steps: - - gcp-cli/install - - - gcp-cli/initialize: - google-project-id: <> - google-compute-zone: <> - google-compute-region: <> - gcloud-service-key: <> - - run: name: gcloud auth configure-docker environment: diff --git a/src/examples/build-and-push-digest.yml b/src/examples/build-and-push-digest.yml index e867104..dcb1e01 100644 --- a/src/examples/build-and-push-digest.yml +++ b/src/examples/build-and-push-digest.yml @@ -5,6 +5,7 @@ usage: version: 2.1 orbs: + gcp-cli: circleci/gcp-cli@x.y.z gcp-gcr: circleci/gcp-gcr@x.y.z jobs: @@ -12,6 +13,9 @@ usage: executor: gcp-gcr/default steps: - checkout + + - gcp-cli/setup + - gcp-gcr/gcr-auth - gcp-gcr/build-image: image: orb-test diff --git a/src/examples/optimized-build-and-push.yml b/src/examples/optimized-build-and-push.yml index 2613202..413395a 100644 --- a/src/examples/optimized-build-and-push.yml +++ b/src/examples/optimized-build-and-push.yml @@ -24,3 +24,5 @@ usage: executor: my-executor # choose an image with gcloud already installed setup-remote-docker: true # mandatory for custom docker executor use-docker-layer-caching: true # optional, improved performance. + pre-steps: + - gcp-cli/setup diff --git a/src/jobs/add-image-tag.yml b/src/jobs/add-image-tag.yml index a05de73..75464e5 100644 --- a/src/jobs/add-image-tag.yml +++ b/src/jobs/add-image-tag.yml @@ -1,5 +1,5 @@ description: > - Install GCP CLI, if needed, and configure. Adds a tag to an existing image. + Adds a tag to an existing image. executor: <> @@ -9,26 +9,11 @@ parameters: description: executor to use for this job type: executor - gcloud-service-key: - description: The gcloud service key - type: env_var_name - default: GCLOUD_SERVICE_KEY - google-project-id: description: The Google project ID to connect with via the gcloud CLI type: env_var_name default: GOOGLE_PROJECT_ID - google-compute-zone: - description: The Google compute zone to connect with via the gcloud CLI - type: env_var_name - default: GOOGLE_COMPUTE_ZONE - - google-compute-region: - description: The Google compute zone to connect with via the gcloud CLI - type: env_var_name - default: GOOGLE_COMPUTE_REGION - registry-url: description: The GCR registry URL from ['', us, eu, asia].gcr.io type: string @@ -47,12 +32,9 @@ parameters: description: A new Docker image tag steps: - - gcr-auth: + registry-url: <> google-project-id: <> - google-compute-zone: <> - google-compute-region: <> - gcloud-service-key: <> - tag-image: registry-url: <> diff --git a/src/jobs/build-and-push-image.yml b/src/jobs/build-and-push-image.yml index d738258..4a9fe63 100644 --- a/src/jobs/build-and-push-image.yml +++ b/src/jobs/build-and-push-image.yml @@ -1,5 +1,5 @@ description: > - Install GCP CLI, if needed, and configure. Build and push image to repository. + Build and push image to repository. executor: <> @@ -9,21 +9,11 @@ parameters: description: executor to use for this job type: executor - gcloud-service-key: - description: The gcloud service key - type: env_var_name - default: GCLOUD_SERVICE_KEY - google-project-id: description: The Google project ID to connect with via the gcloud CLI type: env_var_name default: GOOGLE_PROJECT_ID - google-compute-zone: - description: The Google compute zone to connect with via the gcloud CLI - type: env_var_name - default: GOOGLE_COMPUTE_ZONE - google-compute-region: description: The Google compute zone to connect with via the gcloud CLI type: env_var_name @@ -124,9 +114,6 @@ steps: - gcr-auth: google-project-id: <> - google-compute-zone: <> - google-compute-region: <> - gcloud-service-key: <> registry-url: <> - build-image: diff --git a/src/scripts/gcr-auth.sh b/src/scripts/gcr-auth.sh index c567c79..a71aa93 100644 --- a/src/scripts/gcr-auth.sh +++ b/src/scripts/gcr-auth.sh @@ -3,6 +3,39 @@ # Set sudo to work whether logged in as root user or non-root user if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi + +# Check if the AWS CLI is installed +if ! command -v gcloud &>/dev/null; then + echo "GCP CLI could not be found. Please install it before initiating the GCP CLI. + +Use the circleci/gcp-cli orb to install the GCP CLI. +https://circleci.com/developer/orbs/orb/circleci/gcp-gcr#usage-examples + +Job example: + +jobs: + build_app: + executor: gcp-gcr/default + steps: + - checkout + + - gcp-cli/setup + + - gcp-gcr/gcr-auth + + +Workflow example: + +workflows: + test_and_deploy: + jobs: + - gcp-gcr/add-image-tag: + pre-steps: + - gcp-cli/setup +" + exit 1 +fi + # configure Docker to use gcloud as a credential helper mkdir -p "$HOME/.docker" From 54049956eb3ae922c3fae48cd13735a4e6b56f60 Mon Sep 17 00:00:00 2001 From: Jaryt Date: Thu, 20 Oct 2022 16:14:21 -0400 Subject: [PATCH 2/3] ci: add gcp cli install --- .circleci/test-deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 1420b12..557e894 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -1,6 +1,7 @@ version: 2.1 orbs: gcp-gcr: circleci/gcp-gcr@dev:<> + gcp-cli: circleci/gcp-cli@2.4.1 orb-tools: circleci/orb-tools@11.4 filters: &filters tags: @@ -11,6 +12,8 @@ jobs: steps: # test orb commands - checkout + - gcp-cli/install + - gcp-cli/initialize - gcp-gcr/gcr-auth - gcp-gcr/build-image: registry-url: us.gcr.io @@ -43,6 +46,9 @@ workflows: filters: *filters requires: - integration-test + pre-steps: + - gcp-cli/install + - gcp-cli/initialize post-steps: - run: command: | From 16da16283061d9489756725d495ee44ed7873f5c Mon Sep 17 00:00:00 2001 From: Jaryt Date: Thu, 20 Oct 2022 16:15:13 -0400 Subject: [PATCH 3/3] chore: fix linting error --- .circleci/test-deploy.yml | 2 +- src/examples/optimized-build-and-push.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 557e894..23e3970 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -46,7 +46,7 @@ workflows: filters: *filters requires: - integration-test - pre-steps: + pre-steps: - gcp-cli/install - gcp-cli/initialize post-steps: diff --git a/src/examples/optimized-build-and-push.yml b/src/examples/optimized-build-and-push.yml index 413395a..fe80b8a 100644 --- a/src/examples/optimized-build-and-push.yml +++ b/src/examples/optimized-build-and-push.yml @@ -24,5 +24,5 @@ usage: executor: my-executor # choose an image with gcloud already installed setup-remote-docker: true # mandatory for custom docker executor use-docker-layer-caching: true # optional, improved performance. - pre-steps: + pre-steps: - gcp-cli/setup