How to run google cloud sdk and Node commands in single job?

I want to run test few of which require database connection, so i have dynamically setting up circle-ci job instance IP to cloud sql. Now as per support staff each job can have different IP so i can not run test command in another job. So the problem is now i want to run google cloud sdk commands and nodejs commands in single job.

I tried this by nodejs commands were not found error occur. Vice-versa google cloud sdk commands were not found.

docker:
  - image: google/cloud-sdk

  - image: circleci/node:10.18.0

Is there any way i can use both commands in single job?

so i have dynamically setting up circle-ci job instance IP to cloud sql

You might find it easier to change your Cloud SQL instance to allow connections from all IPs and use certificates with TLS to authenticate clients. Then, you could add those certificates to your CircleCI project as environment variables and use them in your job. That way, there’s no need to track IPs.

Is there any way i can use both commands in single job?

The example you have:

docker:
  - image: google/cloud-sdk

  - image: circleci/node:10.18.0

would use google/cloud-sdk as the container to run the job in (the executor) and would use circleci/node:10.18.0 as a backing service container. This is described in the docs (https://circleci.com/docs/2.0/executor-types/#using-multiple-docker-images). Specifically, the docs say:

In a multi-image configuration job, all steps are executed in the container created by the first image listed.

If your goal is to have access to the installed tools provided by both the google/cloud-sdk image and the circleci/node:10.18.0 image, you could:

  • Choose one of those two images to be the container image the steps run in, and install the tools from the other image in one of the steps (check out orbs if you go this route), or
  • Make a custom image including all of these tools for your job to use (upload the image to Docker Hub or another registry you have access to)

Personally, I tend to use a base image like cimg/node for a Node.js app, and then use an orb like CircleCI Developer Hub - circleci/gcp-cli early in my job to install the gcloud tool I plan to use in my steps. If I needed more tools, I’d add more orbs to install them (or code up the steps to install them if orbs don’t exist already for them) but still have cimg/node as my base image. This base image is cached heavily so my jobs start quick.

Note that cimg/<name> replaces circleci/<name> for the recommended CircleCI-provided base images.

1 Like