-
Notifications
You must be signed in to change notification settings - Fork 291
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
Adds image automated build #189
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:master
from
claudiubelu:adds-image-promoter
Jun 2, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,4 @@ | ||
linux/amd64=us.gcr.io/k8s-artifacts-prod/build-image/debian-base-amd64:v2.1.0 | ||
windows/amd64/1809=mcr.microsoft.com/windows/nanoserver:1809 | ||
windows/amd64/1903=mcr.microsoft.com/windows/nanoserver:1903 | ||
windows/amd64/1909=mcr.microsoft.com/windows/nanoserver:1909 |
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,3 @@ | ||
windows/amd64/1809=mcr.microsoft.com/windows/servercore:1809 | ||
windows/amd64/1903=mcr.microsoft.com/windows/servercore:1903 | ||
windows/amd64/1909=mcr.microsoft.com/windows/servercore:1909 |
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,30 @@ | ||
# Copyright 2020 The Kubernetes 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. | ||
|
||
REGISTRY?=docker.io/deislabs | ||
IMAGE_NAME=driver | ||
IMAGE_VERSION?=v0.0.11 | ||
IMAGE_TAG=$(REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION) | ||
export | ||
|
||
DOCKER_CLI_EXPERIMENTAL = enabled | ||
|
||
build-and-push: | ||
bash -x ./build.sh build_and_push | ||
|
||
manifest: build-and-push | ||
bash -x ./build.sh manifest | ||
|
||
.PHONY: build-and-push manifest | ||
|
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,148 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 The Kubernetes 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 | ||
|
||
TASK=$1 | ||
|
||
pushd `dirname "$0"` | ||
|
||
LDFLAGS="-X sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store.vendorVersion=${IMAGE_VERSION} -extldflags '-static'" | ||
|
||
# Returns list of all supported architectures from the BASEIMAGE file | ||
listOsArchs() { | ||
cut -d "=" -f 1 BASEIMAGE | ||
} | ||
|
||
splitOsArch() { | ||
os_arch=$1 | ||
|
||
if [[ $os_arch =~ .*/.*/.* ]]; then | ||
# for Windows, we have to support both LTS and SAC channels, so we're building multiple Windows images. | ||
# the format for this case is: OS/ARCH/OS_VERSION. | ||
os_name=$(echo "$os_arch" | cut -d "/" -f 1) | ||
arch=$(echo "$os_arch" | cut -d "/" -f 2) | ||
os_version=$(echo "$os_arch" | cut -d "/" -f 3) | ||
suffix="$os_name-$arch-$os_version" | ||
elif [[ $os_arch =~ .*/.* ]]; then | ||
os_name=$(echo "$os_arch" | cut -d "/" -f 1) | ||
arch=$(echo "$os_arch" | cut -d "/" -f 2) | ||
suffix="$os_name-$arch" | ||
else | ||
echo "The BASEIMAGE file is not properly formatted. Expected entries to start with 'os/arch', found '${os_arch}' instead." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Returns baseimage need to used in Dockerfile for any given architecture | ||
getBaseImage() { | ||
os_arch=$1 | ||
file=${2:-BASEIMAGE} | ||
grep "${os_arch}=" "${file}" | cut -d= -f2 | ||
} | ||
|
||
docker_version_check() { | ||
# The reason for this version check is even though "docker manifest" command is available in 18.03, it does | ||
# not work properly in that version. So we insist on 18.06.0 or higher. | ||
# docker buildx has been introduced in 19.03, so we need to make sure we have it. | ||
docker_version=$(docker version --format '{{.Client.Version}}' | cut -d"-" -f1) | ||
if [[ ${docker_version} != 19.03.0 && ${docker_version} < 19.03.0 ]]; then | ||
echo "Minimum docker version 19.03.0 is required for using docker buildx: ${docker_version}]" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# This function will build and push the image for all the architectures mentioned in BASEIMAGE file. | ||
build_and_push() { | ||
docker_version_check | ||
|
||
docker buildx create --name img-builder --use | ||
trap "docker buildx rm img-builder" EXIT | ||
|
||
os_archs=$(listOsArchs) | ||
for os_arch in ${os_archs}; do | ||
splitOsArch "${os_arch}" | ||
|
||
echo "Building / pushing image for OS/ARCH: ${os_arch}..." | ||
|
||
dockerfile_name="Dockerfile" | ||
if [[ "$os_name" = "windows" ]]; then | ||
dockerfile_name="windows.Dockerfile" | ||
fi | ||
|
||
BASEIMAGE=$(getBaseImage "${os_arch}") | ||
|
||
# We only have BASEIMAGE_CORE for Windows images. | ||
BASEIMAGE_CORE=$(getBaseImage "${os_arch}" "BASEIMAGE_CORE") || true | ||
|
||
# NOTE(claudiub): docker buildx works for Windows images as long as it doesn't have to | ||
# execute RUN commands inside the Windows image. | ||
docker buildx build --no-cache --pull --push --platform "${os_name}/${arch}" -t "${IMAGE_TAG}-${suffix}" \ | ||
--build-arg BASEIMAGE="${BASEIMAGE}" --build-arg BASEIMAGE_CORE="${BASEIMAGE_CORE}" \ | ||
--build-arg TARGETARCH="${arch}" --build-arg TARGETOS="${os_name}" --build-arg LDFLAGS="${LDFLAGS}" \ | ||
-f "${dockerfile_name}" .. | ||
done | ||
} | ||
|
||
ensure_manifest_tool() { | ||
if ! [[ -x "$(command -v manifest-tool)" ]]; then | ||
wget "https://github.com/estesp/manifest-tool/releases/download/v1.0.2/manifest-tool-linux-amd64" -O /usr/bin/manifest-tool | ||
chmod +x /usr/bin/manifest-tool | ||
fi | ||
} | ||
|
||
# This function will create and push the manifest list for the image | ||
manifest() { | ||
ensure_manifest_tool | ||
|
||
echo "Building manifest list .yaml file for ${IMAGE_TAG}" | ||
echo "image: ${IMAGE_TAG}" > manifest.yaml | ||
echo "manifests:" >> manifest.yaml | ||
trap "rm manifest.yaml" EXIT | ||
|
||
os_archs=$(listOsArchs) | ||
for os_arch in ${os_archs}; do | ||
splitOsArch "${os_arch}" | ||
|
||
echo " | ||
- image: ${IMAGE_TAG}-${suffix} | ||
platform: | ||
architecture: ${arch} | ||
os: ${os_name}" >> manifest.yaml | ||
|
||
# For Windows images, we also need to include the "os.version" in the manifest list, so the Windows node | ||
# can pull the proper image it needs. | ||
if [[ "$os_name" = "windows" ]]; then | ||
BASEIMAGE=$(getBaseImage "${os_arch}") | ||
# Getting the full OS version from the original image. The manifest-tool output looks like: | ||
# 1 - OS Vers: 10.0.17763.1217 | ||
full_version=$(manifest-tool inspect ${BASEIMAGE} | grep 'OS Vers' | head -n 1 | awk '{print $5}') || true | ||
|
||
# manifest-tool handles osversion as os.version | ||
echo " osversion: ${full_version}" >> manifest.yaml | ||
fi | ||
done | ||
|
||
echo "Manifest list .yaml file:" | ||
cat manifest.yaml | ||
|
||
manifest-tool push from-spec manifest.yaml | ||
} | ||
|
||
shift | ||
eval "${TASK}" |
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,26 @@ | ||
# See https://cloud.google.com/cloud-build/docs/build-config | ||
|
||
# this must be specified in seconds. If omitted, defaults to 600s (10 mins) | ||
timeout: 1200s | ||
# this prevents errors if you don't use both _GIT_TAG and _PULL_BASE_REF, | ||
# or any new substitutions added in the future. | ||
options: | ||
substitution_option: ALLOW_LOOSE | ||
steps: | ||
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20200422-b25d964' | ||
entrypoint: make | ||
dir: ./docker | ||
env: | ||
- DOCKER_CLI_EXPERIMENTAL=enabled | ||
- TAG=$_GIT_TAG | ||
- BASE_REF=$_PULL_BASE_REF | ||
- REGISTRY=gcr.io/k8s-staging-csi-secrets-store | ||
args: | ||
- manifest | ||
substitutions: | ||
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and | ||
# can be used as a substitution | ||
_GIT_TAG: '12345' | ||
# _PULL_BASE_REF will contain the ref that was pushed to to trigger this build - | ||
# a branch like 'master' or 'release-0.2', or a tag like 'v0.2'. | ||
_PULL_BASE_REF: 'master' |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no
docker/
dir?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I moved some things on rebase (there was a merge conflict). Because of some recent changes, I had to rewrite some bits of the building process, and I moved everything in the root directory.
I still prefer having the docker folder. The reason is because we're configuring the Image Promoter to build the image when changes to files in the
docker/.*
are being made (for example, you'd trigger the builder on an image version bump). Having everything on the root directory would mean that the builder would be triggered on every PR, which is unnecessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claudiubelu I'm just wondering if we can make it more architecture natural so that we can build other platforms as well like arm, ppc64le and s390x as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, in the
build.sh
below.As I mentioned before, I've made a separate
docker/Makefile
which is going to be used by the Image Builder / Promoter. This target is still being used for testing, and is called in thisMakefile
. This only builds thelinux/amd64
image, which is sufficient for testing, while mine builds all images, which takes a lot more time, especially due to the Windows images.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool