From 5a35b937540ba0c04e78c7799b382a3e72b307b6 Mon Sep 17 00:00:00 2001 From: Congrool Date: Fri, 3 Feb 2023 20:05:49 +0800 Subject: [PATCH 1/2] improve image build efficiency Signed-off-by: Congrool --- Makefile | 24 ++--- ...t-node-servant => Dockerfile.node-servant} | 8 +- .../Dockerfile.yurt-controller-manager | 8 +- hack/dockerfiles/Dockerfile.yurt-tunnel-agent | 8 +- .../dockerfiles/Dockerfile.yurt-tunnel-server | 8 +- hack/dockerfiles/Dockerfile.yurthub | 8 +- hack/lib/build.sh | 1 - hack/lib/common.sh | 11 +++ hack/make-rules/build.sh | 4 + hack/make-rules/image_build.sh | 98 +++++++++++++++++++ hack/make-rules/local-up-openyurt.sh | 2 +- 11 files changed, 127 insertions(+), 53 deletions(-) rename hack/dockerfiles/{Dockerfile.yurt-node-servant => Dockerfile.node-servant} (53%) create mode 100755 hack/make-rules/image_build.sh diff --git a/Makefile b/Makefile index ecaf0d6dae4..cbd3ecd6584 100644 --- a/Makefile +++ b/Makefile @@ -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) # Build and Push the docker images with multi-arch docker-push: docker-push-yurthub docker-push-yurt-controller-manager docker-push-yurt-tunnel-server docker-push-yurt-tunnel-agent docker-push-node-servant diff --git a/hack/dockerfiles/Dockerfile.yurt-node-servant b/hack/dockerfiles/Dockerfile.node-servant similarity index 53% rename from hack/dockerfiles/Dockerfile.yurt-node-servant rename to hack/dockerfiles/Dockerfile.node-servant index a563597cd6f..3bfdc35c4ef 100644 --- a/hack/dockerfiles/Dockerfile.yurt-node-servant +++ b/hack/dockerfiles/Dockerfile.node-servant @@ -1,15 +1,9 @@ # multi-arch image building for yurt-node-servant -FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder -ADD . /build -ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO -WORKDIR /build/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-node-servant /usr/local/bin/node-servant +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 \ No newline at end of file diff --git a/hack/dockerfiles/Dockerfile.yurt-controller-manager b/hack/dockerfiles/Dockerfile.yurt-controller-manager index bd4d8d8d461..953e19c768f 100644 --- a/hack/dockerfiles/Dockerfile.yurt-controller-manager +++ b/hack/dockerfiles/Dockerfile.yurt-controller-manager @@ -1,14 +1,8 @@ # multi-arch image building for yurt-controller-manager -FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder -ADD . /build -ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO -WORKDIR /build/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager +COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager ENTRYPOINT ["/usr/local/bin/yurt-controller-manager"] \ No newline at end of file diff --git a/hack/dockerfiles/Dockerfile.yurt-tunnel-agent b/hack/dockerfiles/Dockerfile.yurt-tunnel-agent index f6bf70b616c..27e98f9c656 100644 --- a/hack/dockerfiles/Dockerfile.yurt-tunnel-agent +++ b/hack/dockerfiles/Dockerfile.yurt-tunnel-agent @@ -1,14 +1,8 @@ # multi-arch image building for yurt-tunnel-agent -FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder -ADD . /build -ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO -WORKDIR /build/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent +COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent ENTRYPOINT ["/usr/local/bin/yurt-tunnel-agent"] \ No newline at end of file diff --git a/hack/dockerfiles/Dockerfile.yurt-tunnel-server b/hack/dockerfiles/Dockerfile.yurt-tunnel-server index 2e7d09083ea..435cf1f96ac 100644 --- a/hack/dockerfiles/Dockerfile.yurt-tunnel-server +++ b/hack/dockerfiles/Dockerfile.yurt-tunnel-server @@ -1,14 +1,8 @@ # multi-arch image building for yurt-tunnel-server -FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder -ADD . /build -ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO -WORKDIR /build/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server +COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server ENTRYPOINT ["/usr/local/bin/yurt-tunnel-server"] diff --git a/hack/dockerfiles/Dockerfile.yurthub b/hack/dockerfiles/Dockerfile.yurthub index 6b0b099459d..773ec904a9c 100644 --- a/hack/dockerfiles/Dockerfile.yurthub +++ b/hack/dockerfiles/Dockerfile.yurthub @@ -1,14 +1,8 @@ # multi-arch image building for yurthub -FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder -ADD . /build -ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO -WORKDIR /build/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub +COPY ./_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub ENTRYPOINT ["/usr/local/bin/yurthub"] \ No newline at end of file diff --git a/hack/lib/build.sh b/hack/lib/build.sh index 489c6d1ac90..68837583800 100644 --- a/hack/lib/build.sh +++ b/hack/lib/build.sh @@ -39,7 +39,6 @@ build_binaries() { fi local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR}) - rm -rf ${target_bin_dir} mkdir -p ${target_bin_dir} cd ${target_bin_dir} for binary in "${targets[@]}"; do diff --git a/hack/lib/common.sh b/hack/lib/common.sh index 07ed4371a0f..fc50ab105f6 100644 --- a/hack/lib/common.sh +++ b/hack/lib/common.sh @@ -100,4 +100,15 @@ get_maintained_versions() { fi done echo $versions +} + +get_image_tag() { + tag=$(git describe --abbrev=0 --tags) + commit=$(git rev-parse HEAD) + + if $(git tag --points-at ${commit}); then + echo ${tag}-$(echo ${commit} | cut -c 1-7) + else + echo ${tag} + fi } \ No newline at end of file diff --git a/hack/make-rules/build.sh b/hack/make-rules/build.sh index 7cddd634ae7..2ca0179a872 100755 --- a/hack/make-rules/build.sh +++ b/hack/make-rules/build.sh @@ -30,4 +30,8 @@ readonly YURT_ALL_TARGETS=( yurt-tunnel-agent ) +# clean old binaries at GOOS and GOARCH +# eg. _output/local/bin/linux/amd64 +rm -rf $(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR}) + build_binaries "$@" diff --git a/hack/make-rules/image_build.sh b/hack/make-rules/image_build.sh new file mode 100755 index 00000000000..64bc633b2e7 --- /dev/null +++ b/hack/make-rules/image_build.sh @@ -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/Dockerfile.${image} \ + --tag ${IMAGE_REPO}/${image}:${IMAGE_TAG} \ + ${YURT_ROOT} +done \ No newline at end of file diff --git a/hack/make-rules/local-up-openyurt.sh b/hack/make-rules/local-up-openyurt.sh index 64441f4375f..bcb9dbd40f2 100755 --- a/hack/make-rules/local-up-openyurt.sh +++ b/hack/make-rules/local-up-openyurt.sh @@ -120,7 +120,7 @@ function local_up_openyurt { } function cleanup { - rm -rf ${YURT_ROOT}/_output + rm -rf "$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})/yurtctl" kind delete clusters ${CLUSTER_NAME} } From df13bfad237a341a31d55286c6d1fd4657cb6290 Mon Sep 17 00:00:00 2001 From: Congrool Date: Tue, 7 Feb 2023 11:17:56 +0800 Subject: [PATCH 2/2] use original dockerfiles for image release Signed-off-by: Congrool --- Makefile | 10 +++++----- .../{ => build}/Dockerfile.node-servant | 0 .../Dockerfile.yurt-controller-manager | 0 .../{ => build}/Dockerfile.yurt-tunnel-agent | 0 .../{ => build}/Dockerfile.yurt-tunnel-server | 0 hack/dockerfiles/{ => build}/Dockerfile.yurthub | 0 hack/dockerfiles/release/Dockerfile.node-servant | 15 +++++++++++++++ .../release/Dockerfile.yurt-controller-manager | 14 ++++++++++++++ .../release/Dockerfile.yurt-tunnel-agent | 14 ++++++++++++++ .../release/Dockerfile.yurt-tunnel-server | 14 ++++++++++++++ hack/dockerfiles/release/Dockerfile.yurthub | 14 ++++++++++++++ hack/make-rules/image_build.sh | 2 +- 12 files changed, 77 insertions(+), 6 deletions(-) rename hack/dockerfiles/{ => build}/Dockerfile.node-servant (100%) rename hack/dockerfiles/{ => build}/Dockerfile.yurt-controller-manager (100%) rename hack/dockerfiles/{ => build}/Dockerfile.yurt-tunnel-agent (100%) rename hack/dockerfiles/{ => build}/Dockerfile.yurt-tunnel-server (100%) rename hack/dockerfiles/{ => build}/Dockerfile.yurthub (100%) create mode 100644 hack/dockerfiles/release/Dockerfile.node-servant create mode 100644 hack/dockerfiles/release/Dockerfile.yurt-controller-manager create mode 100644 hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent create mode 100644 hack/dockerfiles/release/Dockerfile.yurt-tunnel-server create mode 100644 hack/dockerfiles/release/Dockerfile.yurthub diff --git a/Makefile b/Makefile index cbd3ecd6584..afcd15d5f8f 100644 --- a/Makefile +++ b/Makefile @@ -130,16 +130,16 @@ docker-buildx-builder: docker run --rm --privileged tonistiigi/binfmt --install all docker-push-yurthub: docker-buildx-builder - docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION} + docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION} docker-push-yurt-controller-manager: docker-buildx-builder - docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION} + docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION} docker-push-yurt-tunnel-server: docker-buildx-builder - docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION} + docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION} docker-push-yurt-tunnel-agent: docker-buildx-builder - docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION} + docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION} docker-push-node-servant: docker-buildx-builder - docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION} + docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/release/Dockerfile.node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION} diff --git a/hack/dockerfiles/Dockerfile.node-servant b/hack/dockerfiles/build/Dockerfile.node-servant similarity index 100% rename from hack/dockerfiles/Dockerfile.node-servant rename to hack/dockerfiles/build/Dockerfile.node-servant diff --git a/hack/dockerfiles/Dockerfile.yurt-controller-manager b/hack/dockerfiles/build/Dockerfile.yurt-controller-manager similarity index 100% rename from hack/dockerfiles/Dockerfile.yurt-controller-manager rename to hack/dockerfiles/build/Dockerfile.yurt-controller-manager diff --git a/hack/dockerfiles/Dockerfile.yurt-tunnel-agent b/hack/dockerfiles/build/Dockerfile.yurt-tunnel-agent similarity index 100% rename from hack/dockerfiles/Dockerfile.yurt-tunnel-agent rename to hack/dockerfiles/build/Dockerfile.yurt-tunnel-agent diff --git a/hack/dockerfiles/Dockerfile.yurt-tunnel-server b/hack/dockerfiles/build/Dockerfile.yurt-tunnel-server similarity index 100% rename from hack/dockerfiles/Dockerfile.yurt-tunnel-server rename to hack/dockerfiles/build/Dockerfile.yurt-tunnel-server diff --git a/hack/dockerfiles/Dockerfile.yurthub b/hack/dockerfiles/build/Dockerfile.yurthub similarity index 100% rename from hack/dockerfiles/Dockerfile.yurthub rename to hack/dockerfiles/build/Dockerfile.yurthub diff --git a/hack/dockerfiles/release/Dockerfile.node-servant b/hack/dockerfiles/release/Dockerfile.node-servant new file mode 100644 index 00000000000..a563597cd6f --- /dev/null +++ b/hack/dockerfiles/release/Dockerfile.node-servant @@ -0,0 +1,15 @@ +# multi-arch image building for yurt-node-servant + +FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder +ADD . /build +ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO +WORKDIR /build/ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_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 \ No newline at end of file diff --git a/hack/dockerfiles/release/Dockerfile.yurt-controller-manager b/hack/dockerfiles/release/Dockerfile.yurt-controller-manager new file mode 100644 index 00000000000..bd4d8d8d461 --- /dev/null +++ b/hack/dockerfiles/release/Dockerfile.yurt-controller-manager @@ -0,0 +1,14 @@ +# multi-arch image building for yurt-controller-manager + +FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder +ADD . /build +ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO +WORKDIR /build/ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager +ENTRYPOINT ["/usr/local/bin/yurt-controller-manager"] \ No newline at end of file diff --git a/hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent b/hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent new file mode 100644 index 00000000000..f6bf70b616c --- /dev/null +++ b/hack/dockerfiles/release/Dockerfile.yurt-tunnel-agent @@ -0,0 +1,14 @@ +# multi-arch image building for yurt-tunnel-agent + +FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder +ADD . /build +ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO +WORKDIR /build/ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent +ENTRYPOINT ["/usr/local/bin/yurt-tunnel-agent"] \ No newline at end of file diff --git a/hack/dockerfiles/release/Dockerfile.yurt-tunnel-server b/hack/dockerfiles/release/Dockerfile.yurt-tunnel-server new file mode 100644 index 00000000000..2e7d09083ea --- /dev/null +++ b/hack/dockerfiles/release/Dockerfile.yurt-tunnel-server @@ -0,0 +1,14 @@ +# multi-arch image building for yurt-tunnel-server + +FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder +ADD . /build +ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO +WORKDIR /build/ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server +ENTRYPOINT ["/usr/local/bin/yurt-tunnel-server"] diff --git a/hack/dockerfiles/release/Dockerfile.yurthub b/hack/dockerfiles/release/Dockerfile.yurthub new file mode 100644 index 00000000000..6b0b099459d --- /dev/null +++ b/hack/dockerfiles/release/Dockerfile.yurthub @@ -0,0 +1,14 @@ +# multi-arch image building for yurthub + +FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder +ADD . /build +ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO +WORKDIR /build/ +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/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 --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub +ENTRYPOINT ["/usr/local/bin/yurthub"] \ No newline at end of file diff --git a/hack/make-rules/image_build.sh b/hack/make-rules/image_build.sh index 64bc633b2e7..15f9a9c9ee4 100755 --- a/hack/make-rules/image_build.sh +++ b/hack/make-rules/image_build.sh @@ -92,7 +92,7 @@ for image in ${targets[@]}; do --no-cache \ --load ${DOCKER_BUILD_ARGS} \ --platform ${TARGET_PLATFORMS} \ - --file ${YURT_ROOT}/hack/dockerfiles/Dockerfile.${image} \ + --file ${YURT_ROOT}/hack/dockerfiles/build/Dockerfile.${image} \ --tag ${IMAGE_REPO}/${image}:${IMAGE_TAG} \ ${YURT_ROOT} done \ No newline at end of file