Which executor for a Dockerized Node app deployed to Google Cloud?

nodejs
docker
2.0

#1

I’ve been reading about 1.0->2.0 migration steps and skimming the docs, trying to assess whether the benefits are worth it for us.

I’m most interested in improved run times through better cache control.

We build and test our NodeJS app in Circle (babel transpilation + mocha unit tests), build a Docker image, and depending on the branch push it to Google’s Container registry and trigger a Kubernetes deployment (both using the gcloud SDK)

So basically, I need both a Node environment and the Google Cloud SDK installed.

  • Since the Docker executor supports multiple images, I was thinking of using an official Node image + the google/cloud-sdk one. However the doc says “steps are executed in the first container listed”. Would I be able to run gcloud commands from the second container at all, or is it just meant for daemons that the main container connects to ?

  • It looks like I’m going to need setup_docker_engine to build Docker images. Is it so slow to start up that it negates the instantness of the Docker executor compared to the Machine one ? Should I just go straight to Machine for more flexibility ?

  • Any other benefits I’m missing ?


#2

You can not run commands in the second container.

Using setup_docker_engine boots a VM for you so it’s essentially the same speed as using the machine.

I draw the line between docker and machine at the requirements to build the Docker image. If you need to connect from your base image to the container you’re running, you can’t do that on docker, so you’re better off with machine. The same is true for mounting volumes- you can only do that on the machine.


#3

Thanks for the reply,

Ok, I missed the fact that you can still “docker build” from the container executor even without setup_docker_engine, as long as you don’t need to connect to the resulting container. We actually only “docker run” the built image to check if it’s working, but we could get rid of that.

Regarding available base images, IIUC our best bet would then be to build a custom image with both Node + Google Cloud SDK ?


#4

That sounds right. Building an image specifically for your app takes some time but it’s definitely worth the investment.


#5

Just my $0.02 here.

I personally used the docker executor & build a custom base image which includes the google cloud sdk.

Docker file can be found here: https://github.com/EasyMetrics/circleci-gcp-node6

It needs a bit of polish after using it for a couple of months but for the most part the approach has been effective.

For the record, we build our deployment container in the container mentioned above, not from the container cache of the image above. Deployments just require too many other layers to make building on top of a base image viable.


#6

I just use this but probably should get round to creating a container:

docker:
  - image: google/cloud-sdk
steps:
  - run: curl -sL https://deb.nodesource.com/setup_6.x | bash -
  - run: apt-get install -y nodejs
  - run: echo ${GCP_SERVICE_ACCOUNT} | base64 --decode > key.json
  - run: gcloud auth activate-service-account --key-file key.json
  - run: gcloud config set compute/zone us-central1
  - run: gcloud config set project foo
  - run: gsutil cp ...

#7