Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify registry build #20622

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/photon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ _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) && cd - ; \
$(DOCKERFILEPATH_REG)/builder $(REGISTRY_SRC_TAG) ; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean the builder script cannot be executed in the location of $(DOCKERFILEPATH_REG)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.
The builder script can be executed in the location of $(DOCKERFILEPATH_REG), but it also can be executed in any other location, so it need not to cd to $(DOCKERFILEPATH_REG).

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) .
Expand Down
11 changes: 3 additions & 8 deletions make/photon/registry/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ 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 \
&& 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
COPY --link --chown=10000:10000 --chmod=755 ./make/photon/common/install_cert.sh /home/harbor/
COPY --link --chown=10000:10000 --chmod=744 ./make/photon/registry/entrypoint.sh /home/harbor/
kariya-mitsuru marked this conversation as resolved.
Show resolved Hide resolved
COPY --link --chown=10000:10000 --chmod=755 ./make/photon/registry/binary/registry /usr/bin/registry_DO_NOT_USE_GC

HEALTHCHECK CMD curl --fail -s http://localhost:5000 || curl -k --fail -s https://localhost:5443 || exit 1

Expand Down
3 changes: 2 additions & 1 deletion make/photon/registry/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ FROM photon:5.0
RUN tdnf install -y shadow >> /dev/null \
&& tdnf clean all \
&& mkdir -p /etc/registry \
&& groupadd -r -g 10000 harbor && useradd --no-log-init -m -g 10000 -u 10000 harbor
&& groupadd -r -g 10000 harbor && useradd --no-log-init -m -g 10000 -u 10000 harbor \
&& chown -R harbor:harbor /etc/pki/tls/certs
kariya-mitsuru marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions make/photon/registry/Dockerfile.binary
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PREFIX variable is not used anywhere, which leads to confusion.
Therefore, I think it is better to remove it.

COPY --from=build /go/src/github.com/docker/distribution/bin/registry /
24 changes: 6 additions & 18 deletions make/photon/registry/builder
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
#!/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

VERSION="$1"

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 https://github.com/distribution/distribution.git $TEMP
git clone -b $VERSION --depth 1 https://github.com/distribution/distribution.git $TEMP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary to specify the depth here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --depth 1 is not specified, then the entire history of all the commits to the $VERSION will be cloned, which is unnecessary and is wasteful in terms of transfer amount and processing time (and very painful for a poor environment like mine).
By specifying --depth 1, only the commits specified by $VERSION can be retrieved.


# add patch redis
cd $TEMP
git apply $cur/redis.patch
cd $cur
git apply ~-/redis.patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it support all the linux OS versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
It is supported by all currently used bash.

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 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
Loading