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

refactor build.yaml to speed up build process #18

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
456 changes: 456 additions & 0 deletions .build/build.v2.yaml

Large diffs are not rendered by default.

166 changes: 0 additions & 166 deletions .build/build2.yaml

This file was deleted.

16 changes: 8 additions & 8 deletions make/patches/patch-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

set -e

sed -i 's/$(DOCKERBUILD) -f/docker buildx build --platform linux\/arm64 --output=type=docker -f/g' "make/photon/Makefile"
#sed -i 's/$(DOCKERBUILD) -f/docker buildx build --platform linux\/arm64 --output=type=docker -f/g' "make/photon/Makefile"

sed -i 's/$(DOCKERCMD) build/$(DOCKERCMD) buildx build --platform linux\/arm64 --progress plain --output=type=registry/' "make/photon/Makefile"
#sed -i 's/$(DOCKERCMD) build/$(DOCKERCMD) buildx build --platform linux\/arm64 --progress plain --output=type=registry/' "make/photon/Makefile"
echo "ARM64 after change make/photon/Makefile is "
cat make/photon/Makefile

#sed -i 's/VERSIONTAG=alauda-v2.2.3-${BUILD_NUMBER}-amd64/VERSIONTAG=alauda-v2.2.3-${BUILD_NUMBER}-arm64/g' "Makefile"

sed -i 's/--rm/--rm --env CGO_ENABLED=0 --env GOOS=linux --env GOARCH=arm64/g' "Makefile"
# build base
sed -i 's/$(DOCKERBUILD)/docker buildx build --platform linux\/arm64 --progress plain --output=type=registry/g' "Makefile"
#sed -i 's/$(DOCKERBUILD)/docker buildx build --platform linux\/arm64 --progress plain --output=type=registry/g' "Makefile"
sed -i 's/docker push/echo /g' "Makefile"
echo "ARM64 after change Makefile is "
cat Makefile
Expand Down Expand Up @@ -51,8 +51,8 @@ sed -i 's#amd64_c448c6ec#arm64_c448c6ec#g' "Makefile"
# exporter build
sed -i 's/GOARCH=amd64/GOARCH=arm64/g' "make/photon/exporter/Dockerfile"

DOCKER_BUILD_KIT=1 DOCKER_CLI_EXPERIMENTAL=enabled docker run --rm --privileged build-harbor.alauda.cn/3rdparty/docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
DOCKER_BUILD_KIT=1 DOCKER_CLI_EXPERIMENTAL=enabled docker run --rm --privileged build-harbor.alauda.cn/3rdparty/multiarch/qemu-user-static --reset -p yes

docker context create builder-arm
docker buildx create builder-arm --driver-opt network=host --platform linux/arm64 --use
#DOCKER_BUILD_KIT=1 DOCKER_CLI_EXPERIMENTAL=enabled docker run --rm --privileged build-harbor.alauda.cn/3rdparty/docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
#DOCKER_BUILD_KIT=1 DOCKER_CLI_EXPERIMENTAL=enabled docker run --rm --privileged build-harbor.alauda.cn/3rdparty/multiarch/qemu-user-static --reset -p yes
#
#docker context create builder-arm
#docker buildx create builder-arm --driver-opt network=host --platform linux/arm64 --use
60 changes: 34 additions & 26 deletions make/photon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ _build_log:
_build_trivy_adapter:
@if [ "$(TRIVYFLAG)" = "true" ] ; then \
$(call _build_base,$(TRIVY_ADAPTER),$(DOCKERFILEPATH_TRIVY_ADAPTER)) ; \
rm -rf $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary && mkdir -p $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary ; \
mkdir -p $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary ; \
echo "Downloading Trivy scanner $(TRIVYVERSION)..." ; \
$(call _extract_archive, $(TRIVY_DOWNLOAD_URL), $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary/) ; \
if [ "$(BUILDBIN)" != "true" ] ; then \
echo "Downloading Trivy adapter $(TRIVYADAPTERVERSION)..." ; \
$(call _extract_archive, $(TRIVY_ADAPTER_DOWNLOAD_URL), $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary/) ; \
else \
echo "Building Trivy adapter $(TRIVYADAPTERVERSION) from sources..." ; \
cd $(DOCKERFILEPATH_TRIVY_ADAPTER) && $(DOCKERFILEPATH_TRIVY_ADAPTER)/builder.sh $(TRIVYADAPTERVERSION) && cd - ; \
if [ ! "$(SKIP_BUILDBIN)" ] ; then \
if [ "$(BUILDBIN)" != "true" ] ; then \
echo "Downloading Trivy adapter $(TRIVYADAPTERVERSION)..." ; \
$(call _extract_archive, $(TRIVY_ADAPTER_DOWNLOAD_URL), $(DOCKERFILEPATH_TRIVY_ADAPTER)/binary/) ; \
else \
echo "Building Trivy adapter $(TRIVYADAPTERVERSION) from sources..." ; \
cd $(DOCKERFILEPATH_TRIVY_ADAPTER) && $(DOCKERFILEPATH_TRIVY_ADAPTER)/builder.sh $(TRIVYADAPTERVERSION) && cd - ; \
fi ; \
fi ; \
echo "Building Trivy adapter container for photon..." ; \
$(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) \
Expand All @@ -187,12 +189,14 @@ _build_trivy_adapter:

_build_chart_server:
@if [ "$(CHARTFLAG)" = "true" ] ; then \
$(call _build_base,$(CHARTSERVER),$(DOCKERFILEPATH_CHART_SERVER)); \
if [ "$(BUILDBIN)" != "true" ] ; then \
rm -rf $(DOCKERFILEPATH_CHART_SERVER)/binary && mkdir -p $(DOCKERFILEPATH_CHART_SERVER)/binary && \
$(call _get_binary, $(CHARTURL), $(DOCKERFILEPATH_CHART_SERVER)/binary/chartm); \
else \
cd $(DOCKERFILEPATH_CHART_SERVER) && $(DOCKERFILEPATH_CHART_SERVER)/builder $(GOBUILDIMAGE) $(CHART_SERVER_CODE_BASE) $(CHARTMUSEUM_SRC_TAG) $(CHART_SERVER_MAIN_PATH) $(CHART_SERVER_BIN_NAME) && cd - ; \
$(call _build_base,$(CHARTSERVER),$(DOCKERFILEPATH_CHART_SERVER)); \
if [ ! "$(SKIP_BUILDBIN)" ] ; then \
if [ "$(BUILDBIN)" != "true" ] ; then \
rm -rf $(DOCKERFILEPATH_CHART_SERVER)/binary && mkdir -p $(DOCKERFILEPATH_CHART_SERVER)/binary && \
$(call _get_binary, $(CHARTURL), $(DOCKERFILEPATH_CHART_SERVER)/binary/chartm); \
else \
cd $(DOCKERFILEPATH_CHART_SERVER) && $(DOCKERFILEPATH_CHART_SERVER)/builder $(GOBUILDIMAGE) $(CHART_SERVER_CODE_BASE) $(CHARTMUSEUM_SRC_TAG) $(CHART_SERVER_MAIN_PATH) $(CHART_SERVER_BIN_NAME) && cd - ; \
fi ; \
fi ; \
echo "building chartmuseum container for photon..." ; \
$(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_CHART_SERVER)/$(DOCKERFILENAME_CHART_SERVER) -t $(DOCKERIMAGENAME_CHART_SERVER):$(VERSIONTAG) . ; \
Expand All @@ -210,12 +214,14 @@ _build_notary:
@if [ "$(NOTARYFLAG)" = "true" ] ; then \
$(call _build_base,$(NOTARYSERVER),$(DOCKERFILEPATH_NOTARYSERVER)) ; \
$(call _build_base,$(NOTARYSIGNER),$(DOCKERFILEPATH_NOTARYSIGNER)) ; \
if [ "$(BUILDBIN)" != "true" ] ; then \
rm -rf $(DOCKERFILEPATH_NOTARY)/binary && mkdir -p $(DOCKERFILEPATH_NOTARY)/binary && \
$(call _get_binary, $(NOTARYURL), $(DOCKERFILEPATH_NOTARY)/binary-bundle.tgz); \
cd $(DOCKERFILEPATH_NOTARY) && tar -zvxf binary-bundle.tgz && cd - ; \
else \
cd $(DOCKERFILEPATH_NOTARY) && $(DOCKERFILEPATH_NOTARY)/builder $(NOTARYVERSION) $(NOTARYMIGRATEVERSION) && cd - ; \
if [ ! "$(SKIP_BUILDBIN)" ] ; then \
if [ "$(BUILDBIN)" != "true" ] ; then \
rm -rf $(DOCKERFILEPATH_NOTARY)/binary && mkdir -p $(DOCKERFILEPATH_NOTARY)/binary && \
$(call _get_binary, $(NOTARYURL), $(DOCKERFILEPATH_NOTARY)/binary-bundle.tgz); \
cd $(DOCKERFILEPATH_NOTARY) && tar -zvxf binary-bundle.tgz && cd - ; \
else \
cd $(DOCKERFILEPATH_NOTARY) && $(DOCKERFILEPATH_NOTARY)/builder $(NOTARYVERSION) $(NOTARYMIGRATEVERSION) && cd - ; \
fi ; \
fi ; \
echo "building notary container for photon..."; \
chmod 655 $(DOCKERFILEPATH_NOTARY)/binary/notary-signer && $(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_NOTARYSIGNER)/$(DOCKERFILENAME_NOTARYSIGNER) -t $(DOCKERIMAGENAME_NOTARYSIGNER):$(VERSIONTAG) . ; \
Expand All @@ -226,11 +232,13 @@ _build_notary:

_build_registry:
@$(call _build_base,$(REGISTRY),$(DOCKERFILEPATH_REG))
@if [ "$(BUILDBIN)" != "true" ] ; then \
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 - ; \
@if [ ! "$(SKIP_BUILDBIN)" ] ; then \
if [ "$(BUILDBIN)" != "true" ] ; then \
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 - ; \
fi ; \
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 All @@ -240,7 +248,6 @@ _build_registryctl:
@$(call _build_base,$(REGISTRYCTL),$(DOCKERFILEPATH_REGISTRYCTL))
@echo "building registry controller for photon..."
@$(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_REGISTRYCTL)/$(DOCKERFILENAME_REGISTRYCTL) -t $(DOCKERIMAGENAME_REGISTRYCTL):$(VERSIONTAG) .
@rm -rf $(DOCKERFILEPATH_REG)/binary
@echo "Done."

_build_redis:
Expand All @@ -257,7 +264,7 @@ _build_standalone_db_migrator:
_compile_and_build_exporter:
@$(call _build_base,$(EXPORTER),$(DOCKERFILEPATH_EXPORTER))
@echo "compiling and building image for exporter..."
@$(DOCKERCMD) build --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) --build-arg build_image=$(GOBUILDIMAGE) -f ${DOCKERFILEPATH_EXPORTER}/${DOCKERFILENAME_EXPORTER} -t $(DOCKERIMAGENAME_EXPORTER):$(VERSIONTAG) .
$(DOCKERBUILD_WITH_PULL_PARA) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) --build-arg build_image=$(GOBUILDIMAGE) -f ${DOCKERFILEPATH_EXPORTER}/${DOCKERFILENAME_EXPORTER} -t $(DOCKERIMAGENAME_EXPORTER):$(VERSIONTAG) .
@echo "Done."

define _extract_archive
Expand All @@ -271,6 +278,7 @@ define _get_binary
endef

define _build_base
set -x; \
if [ "$(BUILD_BASE)" = "true" ] ; then \
echo "building base image for $(1)...";\
if [ -n "$(REGISTRYUSER)" ] && [ -n "$(REGISTRYPASSWORD)" ] ; then \
Expand Down
4 changes: 4 additions & 0 deletions make/photon/chartserver/builder
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ cp *.patch binary/

docker run -i --rm -v $cur/binary:/go/bin --name golang_code_builder $GOLANG_IMAGE /bin/bash /go/bin/compile.sh $GIT_PATH $CODE_VERSION $MAIN_GO_PATH $BIN_NAME

if [ ! -f "binary/chartm" ]; then
exit 1
fi

#Clear
#docker rm -f golang_code_builder
7 changes: 4 additions & 3 deletions make/photon/chartserver/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ VERSION="$2"
MAIN_GO_PATH="$3"
BIN_NAME="$4"

set -e

#Get the source code
git clone $GIT_PATH src_code
git clone --depth=1 -b $VERSION $GIT_PATH src_code
ls
SRC_PATH=$(pwd)/src_code
set -e

#Checkout the released tag branch
cd $SRC_PATH
git checkout tags/$VERSION -b $VERSION
#git checkout tags/$VERSION -b $VERSION

#Patch
for p in $(ls /go/bin/*.patch); do
Expand Down
4 changes: 2 additions & 2 deletions make/photon/notary/binary.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN test -n "$MIGRATE_VERSION"
ENV NOTARYPKG github.com/theupdateframework/notary
ENV MIGRATEPKG github.com/golang-migrate/migrate

RUN git clone -b $NOTARY_VERSION https://github.com/theupdateframework/notary.git /go/src/${NOTARYPKG}
RUN git clone --depth=1 -b $NOTARY_VERSION https://github.com/theupdateframework/notary.git /go/src/${NOTARYPKG}
WORKDIR /go/src/${NOTARYPKG}

RUN go install -tags pkcs11 \
Expand All @@ -17,7 +17,7 @@ RUN go install -tags pkcs11 \
-ldflags "-w -X ${NOTARYPKG}/version.GitCommit=`git rev-parse --short HEAD` -X ${NOTARYPKG}/version.NotaryVersion=`cat NOTARY_VERSION`" ${NOTARYPKG}/cmd/notary-signer
RUN cp -r /go/src/${NOTARYPKG}/migrations/ /

RUN git clone -b $MIGRATE_VERSION https://github.com/golang-migrate/migrate /go/src/${MIGRATEPKG}
RUN git clone --depth=1 -b $MIGRATE_VERSION https://github.com/golang-migrate/migrate /go/src/${MIGRATEPKG}
WORKDIR /go/src/${MIGRATEPKG}

ENV DATABASES="postgres mysql redshift cassandra spanner cockroachdb"
Expand Down
8 changes: 3 additions & 5 deletions make/photon/registry/builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set +e
set -ex

if [ -z $1 ]; then
error "Please set the 'version' variable"
Expand All @@ -9,8 +9,6 @@ fi

VERSION="$1"

set -e

# the temp folder to store binary file...
mkdir -p binary
rm -rf binary/registry || true
Expand All @@ -20,12 +18,12 @@ 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 --depth=1 -b $VERSION https://github.com/distribution/distribution.git $TEMP

# add patch 2815
echo 'add patch https://github.com/distribution/distribution/pull/2815 ...'
cd $TEMP
curl -O -L https://github.com/distribution/distribution/pull/2815.patch
curl -O -L --retry 3 -f https://github.com/distribution/distribution/pull/2815.patch
git apply 2815.patch

# add patch redis
Expand Down
Loading
Loading