control plane images support amd64/arm64 add a workerflow action: docker_cross_build Signed-off-by: JimmyYang20 <yangjin39@huawei.com>tags/v0.4.2
| @@ -29,5 +29,5 @@ jobs: | |||||
| # ${GITHUB_REF} => refs/tags/v0.0.1 | # ${GITHUB_REF} => refs/tags/v0.0.1 | ||||
| # IMAGE_REPO=kubeedge IMAGE_TAG=v0.0.1 | # IMAGE_REPO=kubeedge IMAGE_TAG=v0.0.1 | ||||
| # see https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables | # see https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables | ||||
| make push-all IMAGE_REPO=${GITHUB_REPOSITORY%/*} IMAGE_TAG=${GITHUB_REF#refs/*/} | |||||
| make push-all IMAGE_REPO=$(echo ${GITHUB_REPOSITORY%/*} | tr A-Z a-z) IMAGE_TAG=${GITHUB_REF#refs/*/} | |||||
| working-directory: ./src/github.com/${{ github.repository }} | working-directory: ./src/github.com/${{ github.repository }} | ||||
| @@ -151,3 +151,24 @@ jobs: | |||||
| fetch-depth: 0 | fetch-depth: 0 | ||||
| - run: make images | - run: make images | ||||
| docker_cross_build: | |||||
| runs-on: ubuntu-latest | |||||
| name: docker cross build images for gm/lc/kb | |||||
| steps: | |||||
| - name: Install Go | |||||
| uses: actions/setup-go@v2 | |||||
| with: | |||||
| go-version: 1.14.x | |||||
| - uses: actions/cache@v2 | |||||
| with: | |||||
| path: ~/go/pkg/mod | |||||
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |||||
| - name: Checkout code | |||||
| uses: actions/checkout@v2 | |||||
| with: | |||||
| fetch-depth: 0 | |||||
| - run: make docker-cross-build | |||||
| @@ -16,10 +16,17 @@ GOPATH ?= $(shell go env GOPATH) | |||||
| OUT_DIR ?= _output | OUT_DIR ?= _output | ||||
| OUT_BINPATH := $(OUT_DIR)/bin | OUT_BINPATH := $(OUT_DIR)/bin | ||||
| OUT_IMAGESPATH := $(OUT_DIR)/images | |||||
| IMAGE_REPO ?= kubeedge | IMAGE_REPO ?= kubeedge | ||||
| # the env PLATFORMS defines to generate linux images for amd 64-bit, arm 64-bit and armv7 architectures | |||||
| # the full list of PLATFORMS is linux/amd64,linux/arm64,linux/arm/v7 | |||||
| PLATFORMS ?= linux/amd64,linux/arm64 | |||||
| COMPONENTS ?= gm lc kb | |||||
| IMAGE_TAG ?= v0.3.0 | IMAGE_TAG ?= v0.3.0 | ||||
| GO_LDFLAGS ?='' | |||||
| GO_LDFLAGS ?= "" | |||||
| # set allowDangerousTypes for allowing float | # set allowDangerousTypes for allowing float | ||||
| CRD_OPTIONS ?= "crd:crdVersions=v1,allowDangerousTypes=true" | CRD_OPTIONS ?= "crd:crdVersions=v1,allowDangerousTypes=true" | ||||
| @@ -50,7 +57,7 @@ define BUILD_HELP_INFO | |||||
| endef | endef | ||||
| .PHONY: build all | |||||
| .PHONY: build docker-cross-build all | |||||
| ifeq ($(HELP),y) | ifeq ($(HELP),y) | ||||
| build all: | build all: | ||||
| @echo "$${BUILD_HELP_INFO//TARGET/$@}" | @echo "$${BUILD_HELP_INFO//TARGET/$@}" | ||||
| @@ -59,6 +66,9 @@ else | |||||
| # default target | # default target | ||||
| build: | build: | ||||
| hack/make-rules/build.sh $(WHAT) | hack/make-rules/build.sh $(WHAT) | ||||
| # build multi-platform images and results will be saved in tar packages. | |||||
| docker-cross-build: | |||||
| bash hack/make-rules/cross-build.sh | |||||
| all: verify build | all: verify build | ||||
| @@ -132,18 +142,21 @@ gmimage lcimage kbimage: | |||||
| docker build --build-arg GO_LDFLAGS=${GO_LDFLAGS} -t ${IMAGE_REPO}/sedna-${@:image=}:${IMAGE_TAG} -f build/${@:image=}/Dockerfile . | docker build --build-arg GO_LDFLAGS=${GO_LDFLAGS} -t ${IMAGE_REPO}/sedna-${@:image=}:${IMAGE_TAG} -f build/${@:image=}/Dockerfile . | ||||
| .PHONY: push push-examples push-all | |||||
| push-all: push push-examples | |||||
| .PHONY: push push-examples push-all push-multi-platforms | |||||
| push-all: push-multi-platform-images push-examples | |||||
| # push target pushes sedna-built images | # push target pushes sedna-built images | ||||
| push: images | push: images | ||||
| docker push ${IMAGE_REPO}/sedna-gm:${IMAGE_TAG} | |||||
| docker push ${IMAGE_REPO}/sedna-lc:${IMAGE_TAG} | |||||
| docker push ${IMAGE_REPO}/sedna-kb:${IMAGE_TAG} | |||||
| for target in $(COMPONENTS); do \ | |||||
| docker push ${IMAGE_REPO}/sedna-$$target:${IMAGE_TAG} | |||||
| done | |||||
| bash scripts/storage-initializer/push_image.sh | bash scripts/storage-initializer/push_image.sh | ||||
| push-examples: | push-examples: | ||||
| bash examples/push_image.sh | bash examples/push_image.sh | ||||
| # push multi-platform images | |||||
| push-multi-platform-images: | |||||
| bash hack/make-rules/push.sh | |||||
| .PHONY: e2e | .PHONY: e2e | ||||
| e2e: | e2e: | ||||
| @@ -0,0 +1,90 @@ | |||||
| #!/usr/bin/env bash | |||||
| # Copyright 2021 The KubeEdge 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 -o errexit | |||||
| set -o nounset | |||||
| set -o pipefail | |||||
| sedna::buildx::prepare_env() { | |||||
| # Check whether buildx exists. | |||||
| if ! docker buildx >/dev/null 2>&1; then | |||||
| echo "ERROR: docker buildx not available. Docker 19.03 or higher is required with experimental features enabled" >&2 | |||||
| exit 1 | |||||
| fi | |||||
| # Use tonistiigi/binfmt that is to enable an execution of different multi-architecture containers | |||||
| docker run --privileged --rm tonistiigi/binfmt --install all | |||||
| # Create a new builder which gives access to the new multi-architecture features. | |||||
| builder_instance="sedna-buildx" | |||||
| if ! docker buildx inspect $builder_instance >/dev/null 2>&1; then | |||||
| docker buildx create --use --name $builder_instance --driver docker-container | |||||
| fi | |||||
| docker buildx use $builder_instance | |||||
| } | |||||
| sedna::buildx:generate-dockerfile() { | |||||
| dockerfile=${1} | |||||
| sed "/AS builder/s/FROM/FROM --platform=\$BUILDPLATFORM/g" ${dockerfile} | |||||
| } | |||||
| sedna::buildx::push-multi-platform-images() { | |||||
| sedna::buildx::prepare_env | |||||
| bash scripts/storage-initializer/push_image.sh | |||||
| for component in ${COMPONENTS[@]}; do | |||||
| echo "pushing ${PLATFORMS} image for $component" | |||||
| temp_dockerfile=build/${component}/buildx_dockerfile | |||||
| sedna::buildx:generate-dockerfile build/${component}/Dockerfile > ${temp_dockerfile} | |||||
| docker buildx build --push \ | |||||
| --build-arg GO_LDFLAGS=${GO_LDFLAGS} \ | |||||
| --platform ${PLATFORMS} \ | |||||
| -t ${IMAGE_REPO}/sedna-${component}:${IMAGE_TAG} \ | |||||
| -f ${temp_dockerfile} . | |||||
| rm ${temp_dockerfile} | |||||
| done | |||||
| } | |||||
| sedna::buildx::build-multi-platform-images() { | |||||
| sedna::buildx::prepare_env | |||||
| mkdir -p ${OUT_IMAGESPATH} | |||||
| arch_array=(${PLATFORMS//,/ }) | |||||
| temp_dockerfile=${OUT_IMAGESPATH}/buildx_dockerfile | |||||
| for component in ${COMPONENTS[@]}; do | |||||
| echo "building ${PLATFORMS} image for ${component}" | |||||
| sedna::buildx:generate-dockerfile build/${component}/Dockerfile > ${temp_dockerfile} | |||||
| for arch in ${arch_array[@]}; do | |||||
| dest_tar=${OUT_IMAGESPATH}/${component}-${IMAGE_TAG}-${arch////-}.tar | |||||
| echo "building ${arch} image for ${component} and the image will be saved in ${dest_tar}" | |||||
| docker buildx build -o type=docker,dest=${dest_tar} \ | |||||
| --build-arg GO_LDFLAGS=${GO_LDFLAGS} \ | |||||
| --platform ${arch} \ | |||||
| -t ${IMAGE_REPO}/sedna-${component}:${IMAGE_TAG} \ | |||||
| -f ${temp_dockerfile} . | |||||
| done | |||||
| done | |||||
| rm ${temp_dockerfile} | |||||
| } | |||||
| @@ -22,8 +22,10 @@ set -o pipefail | |||||
| SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | ||||
| SEDNA_OUT_BINPATH="${SEDNA_ROOT}/${OUT_BINPATH:-_output/bin}" | SEDNA_OUT_BINPATH="${SEDNA_ROOT}/${OUT_BINPATH:-_output/bin}" | ||||
| SEDNA_OUT_IMAGEPATH="${SEDNA_ROOT}/${OUT_IMAGESPATH:-_output/images}" | |||||
| readonly SEDNA_GO_PACKAGE="github.com/kubeedge/sedna" | readonly SEDNA_GO_PACKAGE="github.com/kubeedge/sedna" | ||||
| source "${SEDNA_ROOT}/hack/lib/golang.sh" | source "${SEDNA_ROOT}/hack/lib/golang.sh" | ||||
| source "${SEDNA_ROOT}/hack/lib/util.sh" | source "${SEDNA_ROOT}/hack/lib/util.sh" | ||||
| source "${SEDNA_ROOT}/hack/lib/buildx.sh" | |||||
| @@ -0,0 +1,24 @@ | |||||
| #!/usr/bin/env bash | |||||
| # Copyright 2021 The KubeEdge 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 -o errexit | |||||
| set -o nounset | |||||
| set -o pipefail | |||||
| SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | |||||
| source "${SEDNA_ROOT}/hack/lib/init.sh" | |||||
| sedna::buildx::build-multi-platform-images | |||||
| @@ -0,0 +1,24 @@ | |||||
| #!/usr/bin/env bash | |||||
| # Copyright 2021 The KubeEdge 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 -o errexit | |||||
| set -o nounset | |||||
| set -o pipefail | |||||
| SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | |||||
| source "${SEDNA_ROOT}/hack/lib/init.sh" | |||||
| sedna::buildx::push-multi-platform-images | |||||
| @@ -17,4 +17,9 @@ | |||||
| cd "$(dirname "${BASH_SOURCE[0]}")" | cd "$(dirname "${BASH_SOURCE[0]}")" | ||||
| source build_image.sh | source build_image.sh | ||||
| docker push $IMAGE | |||||
| if [ -z "${PLATFORMS:-}" ]; then | |||||
| docker push $IMAGE | |||||
| else | |||||
| docker buildx build --push --platform $PLATFORMS -t $IMAGE --label sedna=scripts . | |||||
| fi | |||||