Reputation: 349
I have build a simple docker image to compile Hugo (SSG) into a static blog. I am trying to build the following pipe :
Commit code to GitHub
triggered build in GCP Google Cloud Container Builder, with 2 steps
-Use my image to "compile" *.md files
-Use GCP cloud-builders image to move the files to my GCP bucket
publish the content using Google Cloud Storage bucket with a custom domain name
This question concerns step 2.1
Here is my docker image :
FROM alpine:latest
LABEL description="Docker container for building static websites with Hugo as part of a Google Cloud Container Builder pipeline"
LABEL maintainer="me"
LABEL version="1.0"
#Install Hugo static website generator from sources
ARG HUGO_VERSION=0.36.1
ADD https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz /tmp
RUN tar -xf /tmp/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz -C /tmp \
&& mkdir -p /usr/local/sbin \
&& mv /tmp/hugo /usr/local/sbin/hugo \
&& rm -rf /tmp/hugo_${HUGO_VERSION}_linux_amd64 \
&& rm -rf /tmp/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz \
&& rm -rf /tmp/LICENSE.md \
&& rm -rf /tmp/README.md
RUN apk add --update git \
&& apk upgrade \
&& apk add --no-cache ca-certificates
VOLUME /src
VOLUME /build
WORKDIR /src
CMD "hugo"
I have published this image in the gcr.io, I have also test it locally and it works well if called like this :
sudo docker run --name "test" -P -v $(pwd):/src hugo-docker
.
If called in a folder, it compiles the hugo structure it finds there, and generates a ./public folder that contain the final site.
Here is how it is called in GCP
steps:
- name: gcr.io/thematic-lol-000000/hugo-builder:latest
args: ["-P", "-v .:/src"]
- name: gcr.io/cloud-builders/gsutil
args: ["-m", "rsync", "-r", "-c", "-d", "./public", "gs://gcp.jubi.blog"]
When launching it as part of a triggered build, I get the following error message :
Step #0: container_linux.go:262: starting container process caused "exec: \"-P\": executable file not found in $PATH"
Step #0: docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"-P\": executable file not found in $PATH".
I got this error locally, which I could fix by putting the arguments before the image name, but here I am not sure I can do this.
Also, GCP doc mentions that a /workspace dir is mounted and this is where it fetches the code from git hub, and I don't know how to reference this in my Dockerfile.
I would also like to be able to use the file both locally (passing . as the working directory) or in GCP Cloud container builder
Upvotes: 0
Views: 839
Reputation: 8766
From here, as you are trying to run a docker command, you will need to let it know to the builder in cloudbuild.yaml file. Then you pass the parameters as args:
steps:
- name: gcr.io/cloud-builders/docker
args: ['run', 'gcr.io/$PROJECT_ID//hugo-builder:latest', '-P', '-v .:/src']
Upvotes: 1