-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] improve image build efficiency (#1191)
* improve image build efficiency Signed-off-by: Congrool <[email protected]> * use original dockerfiles for image release Signed-off-by: Congrool <[email protected]> --------- Signed-off-by: Congrool <[email protected]>
- Loading branch information
Showing
16 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -103,26 +103,18 @@ lint: install-golint ## Run go lint against code. | |||||||||||||||||||||||
$(GOLINT_BIN) run -v | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Build the docker images only one arch(specify arch by TARGET_PLATFORMS env) | ||||||||||||||||||||||||
# otherwise the platform of host will be used. | ||||||||||||||||||||||||
# e.g. | ||||||||||||||||||||||||
# - build linux/amd64 docker images: | ||||||||||||||||||||||||
# $# make docker-build TARGET_PLATFORMS=linux/amd64 | ||||||||||||||||||||||||
# - build linux/arm64 docker images: | ||||||||||||||||||||||||
# $# make docker-build TARGET_PLATFORMS=linux/arm64 | ||||||||||||||||||||||||
docker-build: docker-build-yurthub docker-build-yurt-controller-manager docker-build-yurt-tunnel-server docker-build-yurt-tunnel-agent docker-build-node-servant | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
docker-build-yurthub: | ||||||||||||||||||||||||
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
docker-build-yurt-controller-manager: | ||||||||||||||||||||||||
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
docker-build-yurt-tunnel-server: | ||||||||||||||||||||||||
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
docker-build-yurt-tunnel-agent: | ||||||||||||||||||||||||
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
docker-build-node-servant: | ||||||||||||||||||||||||
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION} | ||||||||||||||||||||||||
# - build a specific image: | ||||||||||||||||||||||||
# $# make docker-build WHAT=yurthub | ||||||||||||||||||||||||
# - build with proxy, maybe useful for Chinese users | ||||||||||||||||||||||||
# $# REGION=cn make docker-build | ||||||||||||||||||||||||
docker-build: | ||||||||||||||||||||||||
TARGET_PLATFORMS=${TARGET_PLATFORMS} hack/make-rules/image_build.sh $(WHAT) | ||||||||||||||||||||||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Congrool
Author
Member
|
readonly IMAGE_TARGETS=( | |
yurt-controller-manager | |
yurt-tunnel-agent | |
yurt-tunnel-server | |
yurt-node-servant | |
yurthub | |
) | |
http_proxy=${http_proxy:-} | |
https_proxy=${https_proxy:-} | |
targets=${@:-${IMAGE_TARGETS[@]}} |
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
Congrool
Mar 4, 2024
•
edited
Loading
Author
Member
edited
If WHAT
is not specified, all images will be built.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# multi-arch image building for yurt-node-servant | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.14 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/* | ||
COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-node-servant /usr/local/bin/node-servant | ||
COPY hack/lib/node-servant-entry.sh /usr/local/bin/entry.sh | ||
RUN chmod +x /usr/local/bin/entry.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# multi-arch image building for yurt-controller-manager | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.14 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/* | ||
COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager | ||
ENTRYPOINT ["/usr/local/bin/yurt-controller-manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# multi-arch image building for yurt-tunnel-agent | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.14 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/* | ||
COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent | ||
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-agent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# multi-arch image building for yurt-tunnel-server | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.14 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat iptables ip6tables conntrack-tools && update-ca-certificates && rm /var/cache/apk/* | ||
COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server | ||
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# multi-arch image building for yurthub | ||
|
||
FROM --platform=${TARGETPLATFORM} alpine:3.14 | ||
ARG TARGETOS TARGETARCH MIRROR_REPO | ||
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \ | ||
apk add ca-certificates bash libc6-compat iptables ip6tables && update-ca-certificates && rm /var/cache/apk/* | ||
COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub | ||
ENTRYPOINT ["/usr/local/bin/yurthub"] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2023 The OpenYurt Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -x | ||
set -e | ||
|
||
YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | ||
source "${YURT_ROOT}/hack/lib/init.sh" | ||
source "${YURT_ROOT}/hack/lib/build.sh" | ||
|
||
readonly IMAGE_TARGETS=( | ||
yurt-controller-manager | ||
yurt-tunnel-agent | ||
yurt-tunnel-server | ||
yurt-node-servant | ||
yurthub | ||
) | ||
|
||
http_proxy=${http_proxy:-} | ||
https_proxy=${https_proxy:-} | ||
targets=${@:-${IMAGE_TARGETS[@]}} | ||
REGION=${REGION:-} | ||
IMAGE_REPO=${IMAGE_REPO:-"openyurt"} | ||
IMAGE_TAG=${IMAGE_TAG:-$(get_image_tag)} | ||
DOCKER_BUILD_ARGS="" | ||
BUILD_BASE_IMAGE="golang:1.17.1" | ||
BUILD_GOPROXY=$(go env GOPROXY) | ||
GOPROXY_CN="https://goproxy.cn" | ||
APKREPO_MIRROR_CN="mirrors.aliyun.com" | ||
|
||
if [ "${REGION}" == "cn" ]; then | ||
BUILD_GOPROXY=${GOPROXY_CN} | ||
DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg MIRROR_REPO=${APKREPO_MIRROR_CN}" | ||
fi | ||
|
||
if [[ ! -z ${http_proxy} ]]; then | ||
DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg http_proxy=${http_proxy}" | ||
fi | ||
|
||
if [[ ! -z ${https_proxy} ]]; then | ||
DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg https_proxy=${https_proxy}" | ||
fi | ||
|
||
if [[ ! -z ${TARGET_PLATFORMS} ]]; then | ||
IFS="/" read -r TARGETOS TARGETARCH <<< "${TARGET_PLATFORMS}" | ||
else | ||
echo "TARGET_PLATFORMS should be specified" | ||
exit -1 | ||
fi | ||
|
||
# build binaries within docker container | ||
|
||
# It uses the following two lines: | ||
# --env GOCACHE=/tmp/ | ||
# --user $(id -u ${USER}):$(id -g ${USER}) | ||
# to enable the docker container to build binaries with the | ||
# same user:group as the current user:group of host. | ||
docker run \ | ||
--rm --name openyurt-build \ | ||
--mount type=bind,dst=/build/,src=${YURT_ROOT} \ | ||
--workdir=/build/ \ | ||
--env GOPROXY=${BUILD_GOPROXY} \ | ||
--env GOOS=${TARGETOS} \ | ||
--env GOARCH=${TARGETARCH} \ | ||
--env GOCACHE=/tmp/ \ | ||
--user $(id -u ${USER}):$(id -g ${USER}) \ | ||
${BUILD_BASE_IMAGE} \ | ||
./hack/make-rules/build.sh ${targets[@]} | ||
|
||
# build images | ||
for image in ${targets[@]}; do | ||
# The image name and binary name of node-servant | ||
# are not same. So we have to this translation. | ||
if [[ ${image} == "yurt-node-servant" ]]; then | ||
image="node-servant" | ||
fi | ||
|
||
docker buildx build \ | ||
--no-cache \ | ||
--load ${DOCKER_BUILD_ARGS} \ | ||
--platform ${TARGET_PLATFORMS} \ | ||
--file ${YURT_ROOT}/hack/dockerfiles/build/Dockerfile.${image} \ | ||
--tag ${IMAGE_REPO}/${image}:${IMAGE_TAG} \ | ||
${YURT_ROOT} | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can you explain how to understand $(WHAT)?