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

add support for docker manifest #651

Merged
merged 1 commit into from
Dec 5, 2021
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
add support for docker manifest
  • Loading branch information
zhanglifang@chinatelecom.cn committed Dec 3, 2021
commit 6fe12347cc5bd6285385d3c6e56e67812e1b77ec
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ e2e:

e2e-tests:
bash hack/run-e2e-tests.sh

# create multi-arch manifest
manifest:
bash hack/make-rules/release-manifest.sh

# push generated manifest during 'make manifest'
push_manifest:
bash hack/make-rules/push-manifest.sh
16 changes: 16 additions & 0 deletions hack/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ canonicalize_target() {
host_platform() {
echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)"
}

# Parameters
# $1: binary_name
get_component_name() {
local yurt_component_name
if [[ $1 =~ yurtctl ]]
then
yurt_component_name="yurtctl-servant"
elif [[ $1 =~ yurt-node-servant ]];
then
yurt_component_name="node-servant"
else
yurt_component_name=${binary_name}
fi
echo $yurt_component_name
}
1 change: 1 addition & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ TAG=$GIT_VERSION
source "${YURT_ROOT}/hack/lib/common.sh"
source "${YURT_ROOT}/hack/lib/build.sh"
source "${YURT_ROOT}/hack/lib/release-images.sh"
source "${YURT_ROOT}/hack/lib/release-manifest.sh"
9 changes: 3 additions & 6 deletions hack/lib/release-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ readonly region=${REGION:-us}
# $1: component name
# $2: arch
function get_image_name {
# If ${GIT_COMMIT} is not at a tag, add commit to the image tag.
# If ${GIT_COMMIT} is not at a tag, add commit to the image tag.
if [[ -z $(git tag --points-at ${GIT_COMMIT}) ]]; then
yurt_component_image="${REPO}/$1:${TAG}-$2-$(echo ${GIT_COMMIT} | cut -c 1-7)"
else
Expand All @@ -59,6 +59,7 @@ function get_image_name {
echo ${yurt_component_image}
}


function build_multi_arch_binaries() {
local docker_run_opts=(
"-i"
Expand Down Expand Up @@ -108,12 +109,10 @@ function build_docker_image() {
local docker_build_path=${DOCKER_BUILD_BASE_IDR}/${SUPPORTED_OS}/${arch}
local docker_file_path=${docker_build_path}/Dockerfile.${binary_name}-${arch}
mkdir -p ${docker_build_path}

local yurt_component_name
local yurt_component_name=$(get_component_name $binary_name)
local base_image
if [[ ${binary} =~ yurtctl ]]
then
yurt_component_name="yurtctl-servant"
case $arch in
amd64)
base_image="amd64/alpine:3.9"
Expand All @@ -134,7 +133,6 @@ ADD ${binary_name} /usr/local/bin/yurtctl
EOF
elif [[ ${binary} =~ yurt-node-servant ]];
then
yurt_component_name="node-servant"
case $arch in
amd64)
base_image="amd64/alpine:3.9"
Expand All @@ -157,7 +155,6 @@ RUN chmod +x /usr/local/bin/entry.sh
ADD ${binary_name} /usr/local/bin/node-servant
EOF
else
yurt_component_name=${binary_name}
base_image="k8s.gcr.io/debian-iptables-${arch}:v11.0.2"
cat <<EOF > "${docker_file_path}"
FROM ${base_image}
Expand Down
65 changes: 65 additions & 0 deletions hack/lib/release-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# Copyright 2020 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


# Parameters
# $1: component name
function get_manifest_name() {
# If ${GIT_COMMIT} is not at a tag, add commit to the image tag.
if [[ -z $(git tag --points-at ${GIT_COMMIT}) ]]; then
yurt_component_manifest="${REPO}/$1:${TAG}-$(echo ${GIT_COMMIT} | cut -c 1-7)"
else
yurt_component_manifest="${REPO}/$1:${TAG}"
fi
echo ${yurt_component_manifest}
}

function build_docker_manifest() {
# Always clean first
rm -Rf ${DOCKER_BUILD_BASE_IDR}
mkdir -p ${DOCKER_BUILD_BASE_IDR}

for binary in "${bin_targets_process_servant[@]}"; do
local binary_name=$(get_output_name $binary)
local yurt_component_name=$(get_component_name $binary_name)
local yurt_component_manifest=$(get_manifest_name $yurt_component_name)
echo ${yurt_component_manifest} >> ${DOCKER_BUILD_BASE_IDR}/manifest.list
# Remove existing manifest.
docker manifest rm ${yurt_component_manifest} || true
for arch in ${target_arch[@]}; do
case $arch in
amd64)
;;
arm64)
;;
arm)
;;
*)
echo unknown arch $arch
exit 1
esac
yurt_component_image=$(get_image_name ${yurt_component_name} ${arch})
docker manifest create ${yurt_component_manifest} --amend ${yurt_component_image}
docker manifest annotate ${yurt_component_manifest} ${yurt_component_image} --os ${SUPPORTED_OS} --arch ${arch}
done
done
}

push_manifest() {
cat ${DOCKER_BUILD_BASE_IDR}/manifest.list | xargs -I % sh -c 'echo pushing manifest %; docker manifest push --purge %; echo'
}
23 changes: 23 additions & 0 deletions hack/make-rules/push-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Copyright 2020 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

YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${YURT_ROOT}/hack/lib/init.sh"
export DOCKER_CLI_EXPERIMENTAL=enabled

push_manifest
23 changes: 23 additions & 0 deletions hack/make-rules/release-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Copyright 2020 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

YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
source "${YURT_ROOT}/hack/lib/init.sh"
export DOCKER_CLI_EXPERIMENTAL=enabled

build_docker_manifest