From 29e73d7d656699325bce8c593411f90b305e8c9b Mon Sep 17 00:00:00 2001 From: Zach Langbert Date: Sun, 8 Dec 2019 15:48:26 -0800 Subject: [PATCH] multiarch docker build --- Makefile | 4 +++ docker/Dockerfile.build | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 docker/Dockerfile.build diff --git a/Makefile b/Makefile index 0e028e558..291658c82 100644 --- a/Makefile +++ b/Makefile @@ -149,3 +149,7 @@ test-docs: build-docs serve-docs: build-docs @echo Stating docs website on http://localhost:${DOCS_PORT}/_build/html/index.html @docker run -i -p ${DOCS_PORT}:8000 -e USER_ID=$$UID flux-docs + +.PHONY: build.image.multiarch +build.image.multiarch: + docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t zlangbert/flux-helm-operator:latest-multiarch -f docker/Dockerfile.build . --push \ No newline at end of file diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build new file mode 100644 index 000000000..8bbf3e745 --- /dev/null +++ b/docker/Dockerfile.build @@ -0,0 +1,65 @@ +# builder image +# +FROM --platform=$BUILDPLATFORM golang:1.13.5-buster as builder + +ARG BUILDPLATFORM +ARG TARGETPLATFORM +ARG TARGETARCH +RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" + +WORKDIR /workspace +COPY . . + +RUN make ARCH=$TARGETARCH build/kubectl build/helm3 build/helm-operator + +# build final image +# +FROM alpine:3.10 + +WORKDIR /home/flux + +RUN apk add --no-cache openssh-client ca-certificates tini 'git>=2.12.0' socat + +# Add git hosts to known hosts file so we can use +# StrickHostKeyChecking with git+ssh +ADD ./docker/known_hosts.sh /home/flux/known_hosts.sh +RUN sh /home/flux/known_hosts.sh /etc/ssh/ssh_known_hosts && \ + rm /home/flux/known_hosts.sh + +# Add default SSH config, which points at the private key we'll mount +COPY ./docker/ssh_config /etc/ssh/ssh_config + +COPY --from=builder /workspace/build/kubectl /usr/local/bin/ +# The Helm client is included as a convenience for troubleshooting +COPY --from=builder /workspace/build/helm3 /usr/local/bin/ + +# These are pretty static +LABEL maintainer="Flux CD " \ + org.opencontainers.image.title="flux-helm-operator" \ + org.opencontainers.image.description="The Helm operator for Kubernetes" \ + org.opencontainers.image.url="https://github.com/fluxcd/helm-operator" \ + org.opencontainers.image.source="git@github.com:fluxcd/helm-operator" \ + org.opencontainers.image.vendor="Flux CD" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.name="flux-helm-operator" \ + org.label-schema.description="The Helm operator for Kubernetes" \ + org.label-schema.url="https://github.com/fluxcd/helm-operator" \ + org.label-schema.vcs-url="git@github.com:fluxcd/helm-operator" \ + org.label-schema.vendor="Flux CD" + +ENTRYPOINT [ "/sbin/tini", "--", "helm-operator" ] + +ENV HELM_HOME=/var/fluxd/helm +COPY ./docker/helm-repositories.yaml /var/fluxd/helm/repository/repositories.yaml +RUN mkdir -p /var/fluxd/helm/repository/cache/ + +COPY --from=builder /workspace/build/helm-operator /usr/local/bin/ + +ARG BUILD_DATE +ARG VCS_REF + +# These will change for every build +LABEL org.opencontainers.image.revision="$VCS_REF" \ + org.opencontainers.image.created="$BUILD_DATE" \ + org.label-schema.vcs-ref="$VCS_REF" \ + org.label-schema.build-date="$BUILD_DATE"