Dean Hiller
Dean Hiller

Reputation: 20210

cloud run build and building docker images while building a docker image

Currently, I found out a google cloud build happens during building a docker image time(not as I thought in that it would build my image and then execute my image to do all the building). That was in this post

quick start in google cloud build

soooo, I have a Dockerfile that is real simple now like so

FROM gcr.io/google.com/cloudsdktool/cloud-sdk:alpine

RUN mkdir -p ./monobuild
COPY . ./monobuild/
WORKDIR "/monobuild"
RUN ["/bin/bash", "./downloadAndExtract.sh"]

and I have a single downloadAndExtract that downloads any artifacts(zip files) from the last monobuild run that were built(only modified servers are built OR servers that dependend on changes in the last CI build are built like downstream libraries may be changed). This first line just lists urls of the zip files I need in a file...

curl "https://circleci.com/api/v1.1/project/butbucket/Twilio/orderly/latest/artifacts?circle-token=$token" | grep -o 'https://[^"]*zip' > artifacts.txt

while read url; do
    echo "Downloading url=$url"
    zipFile=${url/*\//}
    projectName=${zipFile/.zip/}
    echo "Zip filename=$zipFile"
    echo "projectName=$projectName"

    wget "$url?circle-token=$token"

    mv "$zipFile?circle-token=$token" $zipFile

    unzip $zipFile
    rm $zipFile
    cd $projectName

    ./deployGcloud.sh

    cd ..

done <artifacts.txt

echo "DONE"

Of course, the deployGcloud script has these commands in it sooooo this means we are building docker images WHILE building the google cloud build docker image(which still seems funny to me)....

docker build . --tag gcr.io/twix/authservice docker push gcr.io/twix/authservice

gcloud run deploy staging-admin --region us-west1 --image gcr.io/twix/authservice --platform managed

BOTH docker commands seem to be erroring out on this..

 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

while the gcloud command seems to be very happy doing a deploy but just using a previous image we deployed at that location.

So, how to get around this error so my build will work and build N images and deploy them all to cloud run?

Upvotes: 1

Views: 1458

Answers (1)

Dean Hiller
Dean Hiller

Reputation: 20210

oh, I finally figured it out. Google has this weird thing in it's config.yaml files of use this docker image to run a curl command and then on next step use this OTHER dockerr image to run some other command and so on using 5 different images. This is all very confusing so instead, I realized I had to figure out how to create my ONE docker image and just run it as a command so I modify the above to have an ENTRYPOINT instead and then docker build and docker push my image into google. Then, I have a cloudbuild.yaml with a single step image command to run.

In this way, we can tweak our builds easily within our docker image that is just run. This is now way simpler than the complex model that google had setup as it becomes basic do your build in the container however you like and install whatever tools you need in the one docker image.

ie. beware the google quick starts which honestly IMHO are really overcomplicating it compared to circleCI and other systems. (of course, that is just an opinion and each to their own).

Upvotes: 1

Related Questions