diff --git a/Makefile b/Makefile index d88a0c420..10ba54ef2 100644 --- a/Makefile +++ b/Makefile @@ -175,3 +175,6 @@ 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 + +build/image/multiarch: + docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t zlangbert/flux: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..cf80f7c43 --- /dev/null +++ b/docker/Dockerfile.build @@ -0,0 +1,74 @@ +# 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/fluxd + +# build final image +# +FROM alpine:3.10 + +WORKDIR /home/flux + +RUN apk add --no-cache openssh-client ca-certificates tini 'git>=2.12.0' 'gnutls>=3.6.7' gnupg gawk socat +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing git-secret + +# 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/fluxd /usr/local/bin/ +COPY ./docker/kubeconfig /root/.kube/config +COPY --from=builder /workspace/build/kubectl /usr/local/bin/ + +# These are pretty static +LABEL maintainer="Flux CD " \ + org.opencontainers.image.title="flux" \ + org.opencontainers.image.description="The GitOps operator for Kubernetes" \ + org.opencontainers.image.url="https://github.com/fluxcd/flux" \ + org.opencontainers.image.source="git@github.com:fluxcd/flux" \ + org.opencontainers.image.vendor="Flux CD" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.name="flux" \ + org.label-schema.description="The GitOps operator for Kubernetes" \ + org.label-schema.url="https://github.com/fluxcd/flux" \ + org.label-schema.vcs-url="git@github.com:fluxcd/flux" \ + org.label-schema.vendor="Flux CD" + +ENTRYPOINT [ "/sbin/tini", "--", "fluxd" ] + +# Get the kubeyaml binary (files) and put them on the path +COPY --from=quay.io/squaremo/kubeyaml:0.7.0 /usr/lib/kubeyaml /usr/lib/kubeyaml/ +ENV PATH=/bin:/usr/bin:/usr/local/bin:/usr/lib/kubeyaml + +# Create minimal nsswitch.conf file to prioritize the usage of /etc/hosts over DNS queries. +# This resolves the conflict between: +# * fluxd using netgo for static compilation. netgo reads nsswitch.conf to mimic glibc, +# defaulting to prioritize DNS queries over /etc/hosts if nsswitch.conf is missing: +# https://github.com/golang/go/issues/22846 +# * Alpine not including a nsswitch.conf file. Since Alpine doesn't use glibc +# (it uses musl), maintainers argue that the need of nsswitch.conf is a Go bug: +# https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-354316460 +RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf + +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"