Not really sure if I haven’t got the syntax right or if what I’m trying to do is impossible. It seems like it should be doable but I haven’t been able to find an example that demonstrates what I’m trying to do and I keep getting config errors in my attempts.
version: 2.1
orbs:
gcp-cli: circleci/gcp-cli@1.0
jobs:
build_and_push:
executor: gcp-cli/google
environment:
- PROJECT_NAME: "project"
- GOOGLE_PROJECT_ID: "project-uid"
- GOOGLE_COMPUTE_ZONE: "europe-west1-a"
- GOOGLE_CLUSTER_NAME: "project-cluster"
steps:
- checkout
- gcp-cli/initialize:
- setup_remote_docker
- run:
name: Docker build and push
command: |
docker build \
-t eu.gcr.io/${GOOGLE_PROJECT_ID}/${PROJECT_NAME}:${CIRCLE_SHA1} .
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://eu.gcr.io
docker push eu.gcr.io/${GOOGLE_PROJECT_ID}/${PROJECT_NAME}:${CIRCLE_SHA1}
So I’ve looked at the gcp-cli orb docs and I can see a lot of the default values are like default: $GOOGLE_PROJECT_ID
. So I’m assuming if I define these defaults along with other environment vars I need they’ll be parsed correctly.
I want a setup like above but the outcome I’m getting is:
# ERROR IN CONFIG FILE:
# jobs: build_and_push: 0 subschemas matched instead of one
# jobs: build_and_push: steps: 1: 0 subschemas matched instead of one
# jobs: build_and_push: steps: 1: expected type: String, found: Mapping
# jobs: build_and_push: steps: 1: minimum size: [1], found: [0]
# jobs: build_and_push: expected type: String, found: Mapping
I find this error message a little hard to read as it doesn’t represent very well the config I’ve typed or which line the error has occurred.
Is what I’m trying to do possible and is my syntax just bad in this case or will I need to duplicate environment declarations and explicitly pass them in to the gcp-cli/initialize
command?
As far as I’ve been able to work out from the docs yes they need to be explicitly passed like so:
executor: gcp-cli/google
environment:
- PROJECT_NAME: "project"
- GOOGLE_PROJECT_ID: "project-uid"
- GOOGLE_COMPUTE_ZONE: "europe-west1-a"
- GOOGLE_CLUSTER_NAME: "project-cluster"
steps:
- checkout
- gcp-cli/initialize:
gcloud-service-key: $GCLOUD_SERVICE_KEY # actually this one doesn't
google-project-id: $GOOGLE_PROJECT_ID
google-compute-zone: $GOOGLE_COMPUTE_ZONE
I assume it’s because they’re present in the job but not made available in the executor container. Unlike the service key which is because it’s project wide. So I guess my real question becomes can we add env variables into executors like we would a normal docker container?
docker:
- image: someimage
environment:
ENV: CI
I’m really only saving on two lines of text in this example but it would still be nice to be able to add variables to the container.