From b5a5b1f12ba6575403ce82dad52487fcc16a4b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Thu, 26 Oct 2023 13:26:44 +0200 Subject: [PATCH 1/5] fix: build in the image to get an arm64 binary --- Dockerfile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 79e6c5a..614b1d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,19 +4,27 @@ FROM debian:stable-slim AS mirrorbits ## and the risk of a breaking behavior is evaluated as low # hadolint ignore=DL3008 RUN apt-get update && \ - apt-get install --no-install-recommends -y tar curl ca-certificates && \ + apt-get install --no-install-recommends -y tar curl ca-certificates git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +ARG go_version=1.21.3 +RUN mkdir -p /tmp/tools/ && \ + curl -L "https://go.dev/dl/go${go_version}.linux-$(dpkg --print-architecture).tar.gz" --output /tmp/tools/go.tar.gz && \ + tar -C /tmp/tools/ -xzf /tmp/tools/go.tar.gz + ARG mirrorbits_version=v0.5.1 -RUN mkdir /mirrorbits && \ - curl -L https://github.com/etix/mirrorbits/releases/download/${mirrorbits_version}/mirrorbits-${mirrorbits_version}.tar.gz -O && \ - tar xvzf /mirrorbits-${mirrorbits_version}.tar.gz -C / +ARG mirrorbits_current_commit=9189dc7 +# hadolint ignore=DL3003 +RUN git clone https://github.com/etix/mirrorbits /tmp/tools/mirrorbits && \ + cd /tmp/tools/mirrorbits && \ + git checkout "${mirrorbits_current_commit}" && \ + /tmp/tools/go/bin/go build ARG tini_version=v0.19.0 -RUN curl --silent --show-error --output /mirrorbits/tini --location \ +RUN curl --silent --show-error --output /tmp/tools/tini --location \ "https://github.com/krallin/tini/releases/download/${tini_version}/tini-$(dpkg --print-architecture)" && \ - chmod +x /mirrorbits/tini + chmod +x /tmp/tools/tini FROM debian:stable-slim @@ -51,11 +59,11 @@ USER mirrorbits COPY config/mirrorbits.conf /etc/mirrorbits/mirrorbits.conf -COPY --from=mirrorbits /mirrorbits/tini /bin/tini +COPY --from=mirrorbits /tmp/tools/tini /bin/tini -COPY --from=mirrorbits /mirrorbits/mirrorbits /usr/bin/mirrorbits +COPY --from=mirrorbits /tmp/tools/mirrorbits/mirrorbits /usr/bin/mirrorbits -COPY --from=mirrorbits /mirrorbits/templates /usr/share/mirrorbits/templates +COPY --from=mirrorbits /tmp/tools/mirrorbits/templates /usr/share/mirrorbits/templates LABEL io.jenkins-infra.tools="mirrorbits,tini" LABEL io.jenkins-infra.tools.mirrorbits.version="${mirrorbits_version}" From f3eb869ce1107f6716e7d07047e525f90abc2a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Tue, 9 Jul 2024 16:47:15 +0200 Subject: [PATCH 2/5] use golang:1.11 as base image for building mirrorbits --- Dockerfile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 614b1d4..adff4f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:stable-slim AS mirrorbits +FROM golang:1.11 AS build ## (DL3008)Ignore lint error about apt pinned packages, as we always want the latest version of these tools ## and the risk of a breaking behavior is evaluated as low @@ -25,8 +25,8 @@ ARG tini_version=v0.19.0 RUN curl --silent --show-error --output /tmp/tools/tini --location \ "https://github.com/krallin/tini/releases/download/${tini_version}/tini-$(dpkg --print-architecture)" && \ chmod +x /tmp/tools/tini - -FROM debian:stable-slim + +FROM debian:stable-slim AS mirrorbits EXPOSE 8080 @@ -59,11 +59,9 @@ USER mirrorbits COPY config/mirrorbits.conf /etc/mirrorbits/mirrorbits.conf -COPY --from=mirrorbits /tmp/tools/tini /bin/tini - -COPY --from=mirrorbits /tmp/tools/mirrorbits/mirrorbits /usr/bin/mirrorbits - -COPY --from=mirrorbits /tmp/tools/mirrorbits/templates /usr/share/mirrorbits/templates +COPY --from=build /tmp/tools/tini /bin/tini +COPY --from=build /tmp/tools/mirrorbits/mirrorbits /usr/bin/mirrorbits +COPY --from=build /tmp/tools/mirrorbits/templates /usr/share/mirrorbits/templates LABEL io.jenkins-infra.tools="mirrorbits,tini" LABEL io.jenkins-infra.tools.mirrorbits.version="${mirrorbits_version}" From 486820c96cd32112ca8dbb0bd983005a72d29b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Tue, 9 Jul 2024 16:47:40 +0200 Subject: [PATCH 3/5] regroup labels --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index adff4f6..14ddd46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,8 +33,6 @@ EXPOSE 8080 ARG tini_version=v0.19.0 ARG mirrorbits_version=v0.5.1 -LABEL repository="https://github.com/olblak/mirrorbits" - ## (DL3008)Ignore lint error about apt pinned packages, as we always want the latest version of these tools ## and the risk of a breaking behavior is evaluated as low # hadolint ignore=DL3008 @@ -63,9 +61,11 @@ COPY --from=build /tmp/tools/tini /bin/tini COPY --from=build /tmp/tools/mirrorbits/mirrorbits /usr/bin/mirrorbits COPY --from=build /tmp/tools/mirrorbits/templates /usr/share/mirrorbits/templates -LABEL io.jenkins-infra.tools="mirrorbits,tini" -LABEL io.jenkins-infra.tools.mirrorbits.version="${mirrorbits_version}" -LABEL io.jenkins-infra.tools.tini.version="${tini_version}" +LABEL \ + io.jenkins-infra.tools="mirrorbits,tini" \ + io.jenkins-infra.tools.mirrorbits.version="${mirrorbits_version}" \ + io.jenkins-infra.tools.tini.version="${tini_version}" \ + repository="https://github.com/jenkins-infra/docker-mirrorbits" ENTRYPOINT [ "/bin/tini","--" ] From 987c855ad2f928575c2f4906f3072cbec8921ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Tue, 9 Jul 2024 16:49:06 +0200 Subject: [PATCH 4/5] wip --- Dockerfile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14ddd46..faa234b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,23 +3,28 @@ FROM golang:1.11 AS build ## (DL3008)Ignore lint error about apt pinned packages, as we always want the latest version of these tools ## and the risk of a breaking behavior is evaluated as low # hadolint ignore=DL3008 -RUN apt-get update && \ - apt-get install --no-install-recommends -y tar curl ca-certificates git && \ +RUN apt-get -qq update && \ + apt-get install --no-install-recommends -y libgeoip-dev tar curl ca-certificates git unzip && \ apt-get clean && \ + curl --location --silent --show-error --fail https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-aarch_64.zip --output /tmp/protoc.zip && \ + unzip /tmp/protoc.zip -d "$HOME"/protoc && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -ARG go_version=1.21.3 -RUN mkdir -p /tmp/tools/ && \ - curl -L "https://go.dev/dl/go${go_version}.linux-$(dpkg --print-architecture).tar.gz" --output /tmp/tools/go.tar.gz && \ - tar -C /tmp/tools/ -xzf /tmp/tools/go.tar.gz +ENV GOBIN="$GOPATH/bin" +ENV PROTOCBIN="$HOME/protoc/bin" +ENV PATH="$PATH:$PROTOCBIN:$GOBIN" +ENV GO111MODULE="on" ARG mirrorbits_version=v0.5.1 ARG mirrorbits_current_commit=9189dc7 # hadolint ignore=DL3003 -RUN git clone https://github.com/etix/mirrorbits /tmp/tools/mirrorbits && \ - cd /tmp/tools/mirrorbits && \ - git checkout "${mirrorbits_current_commit}" && \ - /tmp/tools/go/bin/go build +RUN git clone https://github.com/etix/mirrorbits "${GOPATH}/src/mirrorbits" && \ + cd "${GOPATH}/src/mirrorbits" && \ + git checkout "${mirrorbits_version}" + +# WIP +WORKDIR "${GOPATH}/src/mirrorbits" +RUN go build ARG tini_version=v0.19.0 RUN curl --silent --show-error --output /tmp/tools/tini --location \ From a343ef6a4cf02fd08f63a69d79d2f9b59bd84550 Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Tue, 20 Aug 2024 11:43:24 +0200 Subject: [PATCH 5/5] fixup: change mirrorbits source reference to use protoc code and vendored deps + Go 1.23.0 + multi-stage fixes Signed-off-by: Damien Duportal --- Dockerfile | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index faa234b..617097c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,38 @@ -FROM golang:1.11 AS build +FROM golang:1.23.0 AS build ## (DL3008)Ignore lint error about apt pinned packages, as we always want the latest version of these tools ## and the risk of a breaking behavior is evaluated as low # hadolint ignore=DL3008 RUN apt-get -qq update && \ - apt-get install --no-install-recommends -y libgeoip-dev tar curl ca-certificates git unzip && \ + apt-get install --no-install-recommends -y libgeoip-dev tar curl ca-certificates git unzip zlib1g-dev && \ apt-get clean && \ - curl --location --silent --show-error --fail https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-aarch_64.zip --output /tmp/protoc.zip && \ - unzip /tmp/protoc.zip -d "$HOME"/protoc && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -ENV GOBIN="$GOPATH/bin" -ENV PROTOCBIN="$HOME/protoc/bin" -ENV PATH="$PATH:$PROTOCBIN:$GOBIN" -ENV GO111MODULE="on" +# 955a8b2e1aacea1cae06396a64afbb531ceb36d4 introduced go modules (for Go >= 1.11) and commited the generated code from protoc +# v0.5.1 tag is a bit older (but without these 2 majors elements): https://github.com/etix/mirrorbits/commit/e83e56ac6496a3643d18a731324bd266f75f7b32 commit +# Diff: https://github.com/etix/mirrorbits/compare/e83e56ac6496a3643d18a731324bd266f75f7b32..955a8b2e1aacea1cae06396a64afbb531ceb36d4 +ARG mirrorbits_version=955a8b2e1aacea1cae06396a64afbb531ceb36d4 + +WORKDIR "/mirrorbits" -ARG mirrorbits_version=v0.5.1 -ARG mirrorbits_current_commit=9189dc7 # hadolint ignore=DL3003 -RUN git clone https://github.com/etix/mirrorbits "${GOPATH}/src/mirrorbits" && \ - cd "${GOPATH}/src/mirrorbits" && \ +RUN git clone https://github.com/etix/mirrorbits ./ && \ git checkout "${mirrorbits_version}" -# WIP -WORKDIR "${GOPATH}/src/mirrorbits" -RUN go build +# Do not call parent target (dependencies are vendorized) but we still want the proper LDFLAGS +RUN sed -i 's/^build:.*/build:/g' Makefile && \ + make build ARG tini_version=v0.19.0 -RUN curl --silent --show-error --output /tmp/tools/tini --location \ +RUN curl --silent --show-error --output ./tini --location \ "https://github.com/krallin/tini/releases/download/${tini_version}/tini-$(dpkg --print-architecture)" && \ - chmod +x /tmp/tools/tini - -FROM debian:stable-slim AS mirrorbits + chmod a+x ./tini -EXPOSE 8080 +FROM debian:stable-slim AS mirrorbits +# Repeat ARGS for labels ARG tini_version=v0.19.0 -ARG mirrorbits_version=v0.5.1 +ARG mirrorbits_version=955a8b2e1aacea1cae06396a64afbb531ceb36d4 ## (DL3008)Ignore lint error about apt pinned packages, as we always want the latest version of these tools ## and the risk of a breaking behavior is evaluated as low @@ -62,9 +58,9 @@ USER mirrorbits COPY config/mirrorbits.conf /etc/mirrorbits/mirrorbits.conf -COPY --from=build /tmp/tools/tini /bin/tini -COPY --from=build /tmp/tools/mirrorbits/mirrorbits /usr/bin/mirrorbits -COPY --from=build /tmp/tools/mirrorbits/templates /usr/share/mirrorbits/templates +COPY --from=build /mirrorbits/tini /bin/tini +COPY --from=build /mirrorbits/bin/mirrorbits /usr/bin/mirrorbits +COPY --from=build /mirrorbits/templates /usr/share/mirrorbits/templates LABEL \ io.jenkins-infra.tools="mirrorbits,tini" \ @@ -72,6 +68,8 @@ LABEL \ io.jenkins-infra.tools.tini.version="${tini_version}" \ repository="https://github.com/jenkins-infra/docker-mirrorbits" +EXPOSE 8080 3390 + ENTRYPOINT [ "/bin/tini","--" ] CMD [ "/usr/bin/mirrorbits","daemon","--config","/etc/mirrorbits/mirrorbits.conf" ]