diff --git a/make/photon/Makefile b/make/photon/Makefile index 0dc0678cc09..2c279d42ff6 100644 --- a/make/photon/Makefile +++ b/make/photon/Makefile @@ -178,10 +178,10 @@ _build_registry: rm -rf $(DOCKERFILEPATH_REG)/binary && mkdir -p $(DOCKERFILEPATH_REG)/binary && \ $(call _get_binary, $(REGISTRYURL), $(DOCKERFILEPATH_REG)/binary/registry); \ else \ - cd $(DOCKERFILEPATH_REG) && $(DOCKERFILEPATH_REG)/builder $(REGISTRY_SRC_TAG) $(DISTRIBUTION_SRC) && cd - ; \ + $(DOCKERFILEPATH_REG)/builder $(REGISTRY_SRC_TAG) $(DISTRIBUTION_SRC) ; \ fi @echo "building registry container for photon..." - @chmod 655 $(DOCKERFILEPATH_REG)/binary/registry && $(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_REG)/$(DOCKERFILENAME_REG) -t $(DOCKERIMAGENAME_REG):$(VERSIONTAG) . + @chmod 655 $(DOCKERFILEPATH_REG)/binary/registry && DOCKER_BUILDKIT=1 $(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_REG)/$(DOCKERFILENAME_REG) -t $(DOCKERIMAGENAME_REG):$(VERSIONTAG) . @echo "Done." _build_registryctl: diff --git a/make/photon/registry/Dockerfile b/make/photon/registry/Dockerfile index f6565ff386e..f2e3873309d 100644 --- a/make/photon/registry/Dockerfile +++ b/make/photon/registry/Dockerfile @@ -2,11 +2,11 @@ ARG harbor_base_image_version ARG harbor_base_namespace FROM ${harbor_base_namespace}/harbor-registry-base:${harbor_base_image_version} -COPY ./make/photon/common/install_cert.sh /home/harbor -COPY ./make/photon/registry/entrypoint.sh /home/harbor -COPY ./make/photon/registry/binary/registry /usr/bin/registry_DO_NOT_USE_GC - -RUN chown -R harbor:harbor /etc/pki/tls/certs \ +RUN --mount=type=bind,source=make/photon,target=/root \ + chown -R harbor:harbor /etc/pki/tls/certs \ + && cp /root/common/install_cert.sh /home/harbor \ + && cp /root/registry/entrypoint.sh /home/harbor \ + && cp /root/registry/binary/registry /usr/bin/registry_DO_NOT_USE_GC \ && chown harbor:harbor /home/harbor/entrypoint.sh && chmod u+x /home/harbor/entrypoint.sh \ && chown harbor:harbor /home/harbor/install_cert.sh && chmod u+x /home/harbor/install_cert.sh \ && chown harbor:harbor /usr/bin/registry_DO_NOT_USE_GC && chmod u+x /usr/bin/registry_DO_NOT_USE_GC diff --git a/make/photon/registry/Dockerfile.binary b/make/photon/registry/Dockerfile.binary index 0098691bef3..ab353b1d234 100644 --- a/make/photon/registry/Dockerfile.binary +++ b/make/photon/registry/Dockerfile.binary @@ -1,4 +1,4 @@ -FROM golang:1.22.3 +FROM golang:1.22.3 AS build ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution ENV BUILDTAGS include_oss include_gcs @@ -7,4 +7,7 @@ ENV GO111MODULE auto WORKDIR $DISTRIBUTION_DIR COPY . $DISTRIBUTION_DIR -RUN CGO_ENABLED=0 make PREFIX=/go clean binaries +RUN CGO_ENABLED=0 make clean bin/registry + +FROM scratch +COPY --from=build /go/src/github.com/docker/distribution/bin/registry / diff --git a/make/photon/registry/builder b/make/photon/registry/builder index 0c254cbf7bb..ecb31e9e829 100755 --- a/make/photon/registry/builder +++ b/make/photon/registry/builder @@ -1,9 +1,9 @@ #!/bin/bash -set +e +set -e if [ -z $1 ]; then - error "Please set the 'version' variable" + echo "Please set the 'version' variable" exit 1 fi @@ -15,36 +15,24 @@ fi VERSION="$1" DISTRIBUTION_SRC="$2" -set -e - # the temp folder to store binary file... mkdir -p binary rm -rf binary/registry || true cd `dirname $0` -cur=$PWD # the temp folder to store distribution source code... TEMP=`mktemp -d ${TMPDIR-/tmp}/distribution.XXXXXX` -git clone -b $VERSION $DISTRIBUTION_SRC $TEMP +git clone -b $VERSION --depth 1 $DISTRIBUTION_SRC $TEMP # add patch redis cd $TEMP -git apply $cur/redis.patch -cd $cur +git apply ~-/redis.patch +cd - echo 'build the registry binary ...' -cp Dockerfile.binary $TEMP -docker build -f $TEMP/Dockerfile.binary -t registry-golang $TEMP - -echo 'copy the registry binary to local...' -ID=$(docker create registry-golang) -docker cp $ID:/go/src/github.com/docker/distribution/bin/registry binary/registry - -docker rm -f $ID -docker rmi -f registry-golang +DOCKER_BUILDKIT=1 docker build -f Dockerfile.binary -o binary/ $TEMP echo "Build registry binary success, then to build photon image..." -cd $cur cp $TEMP/cmd/registry/config-example.yml config.yml rm -rf $TEMP