Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: decouple from gcp cli #60

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 2.1
orbs:
gcp-gcr: circleci/gcp-gcr@dev:<<pipeline.git.revision>>
gcp-cli: circleci/[email protected]
orb-tools: circleci/[email protected]
filters: &filters
tags:
Expand All @@ -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
Expand Down Expand Up @@ -43,6 +46,9 @@ workflows:
filters: *filters
requires:
- integration-test
pre-steps:
- gcp-cli/install
- gcp-cli/initialize
post-steps:
- run:
command: |
Expand Down
1 change: 0 additions & 1 deletion src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ display:

orbs:
docker: circleci/[email protected]
gcp-cli: circleci/[email protected]
25 changes: 0 additions & 25 deletions src/commands/gcr-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,13 @@ 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
description: >
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,
Expand All @@ -34,14 +17,6 @@ parameters:
default: gcr.io

steps:
- gcp-cli/install

- gcp-cli/initialize:
google-project-id: <<parameters.google-project-id>>
google-compute-zone: <<parameters.google-compute-zone>>
google-compute-region: <<parameters.google-compute-region>>
gcloud-service-key: <<parameters.gcloud-service-key>>

- run:
name: gcloud auth configure-docker
environment:
Expand Down
4 changes: 4 additions & 0 deletions src/examples/build-and-push-digest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ usage:
version: 2.1

orbs:
gcp-cli: circleci/[email protected]
gcp-gcr: circleci/[email protected]

jobs:
build-and-push:
executor: gcp-gcr/default
steps:
- checkout

- gcp-cli/setup

- gcp-gcr/gcr-auth
- gcp-gcr/build-image:
image: orb-test
Expand Down
2 changes: 2 additions & 0 deletions src/examples/optimized-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 2 additions & 20 deletions src/jobs/add-image-tag.yml
Original file line number Diff line number Diff line change
@@ -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: <<parameters.executor>>

Expand All @@ -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
Expand All @@ -47,12 +32,9 @@ parameters:
description: A new Docker image tag

steps:

- gcr-auth:
registry-url: <<parameters.registry-url>>
google-project-id: <<parameters.google-project-id>>
google-compute-zone: <<parameters.google-compute-zone>>
google-compute-region: <<parameters.google-compute-region>>
gcloud-service-key: <<parameters.gcloud-service-key>>

- tag-image:
registry-url: <<parameters.registry-url>>
Expand Down
15 changes: 1 addition & 14 deletions src/jobs/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -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: <<parameters.executor>>

Expand All @@ -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
Expand Down Expand Up @@ -124,9 +114,6 @@ steps:

- gcr-auth:
google-project-id: <<parameters.google-project-id>>
google-compute-zone: <<parameters.google-compute-zone>>
google-compute-region: <<parameters.google-compute-region>>
gcloud-service-key: <<parameters.gcloud-service-key>>
registry-url: <<parameters.registry-url>>

- build-image:
Expand Down
33 changes: 33 additions & 0 deletions src/scripts/gcr-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down