...

Text file src/github.com/docker/distribution/Dockerfile

Documentation: github.com/docker/distribution

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

View as plain text