Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # syntax=docker/dockerfile:1
  2. ARG GO_VERSION=1.20.8
  3. ARG ALPINE_VERSION=3.18
  4. ARG XX_VERSION=1.2.1
  5. FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
  6. FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
  7. COPY --from=xx / /
  8. RUN apk add --no-cache bash coreutils file git
  9. ENV GO111MODULE=auto
  10. ENV CGO_ENABLED=0
  11. WORKDIR /go/src/github.com/docker/distribution
  12. FROM base AS version
  13. ARG PKG="github.com/docker/distribution"
  14. RUN --mount=target=. \
  15. VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
  16. echo "-X ${PKG}/version.Version=${VERSION#v} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \
  17. echo -n "${VERSION}" | tee /tmp/.version;
  18. FROM base AS build
  19. ARG TARGETPLATFORM
  20. ARG LDFLAGS="-s -w"
  21. ARG BUILDTAGS="include_oss,include_gcs"
  22. RUN --mount=type=bind,target=/go/src/github.com/docker/distribution,rw \
  23. --mount=type=cache,target=/root/.cache/go-build \
  24. --mount=target=/go/pkg/mod,type=cache \
  25. --mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
  26. set -x ; xx-go build -tags "${BUILDTAGS}" -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \
  27. && xx-verify --static /usr/bin/registry
  28. FROM scratch AS binary
  29. COPY --from=build /usr/bin/registry /
  30. FROM base AS releaser
  31. ARG TARGETOS
  32. ARG TARGETARCH
  33. ARG TARGETVARIANT
  34. WORKDIR /work
  35. RUN --mount=from=binary,target=/build \
  36. --mount=type=bind,target=/src \
  37. --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \
  38. VERSION=$(cat /tmp/.version) \
  39. && mkdir -p /out \
  40. && cp /build/registry /src/README.md /src/LICENSE . \
  41. && tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz" * \
  42. && sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz.sha256"
  43. FROM scratch AS artifact
  44. COPY --from=releaser /out /
  45. FROM alpine:${ALPINE_VERSION}
  46. RUN apk add --no-cache ca-certificates
  47. COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml
  48. COPY --from=binary /registry /bin/registry
  49. VOLUME ["/var/lib/registry"]
  50. EXPOSE 5000
  51. ENTRYPOINT ["registry"]
  52. CMD ["serve", "/etc/docker/registry/config.yml"]