diff --git a/.gitignore b/.gitignore index 765047a5a3..9d16ffcd4c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ sonobuoy* # Bazel directories cluster-provision/gocli/bazel-* + +# Artifacts after releasing +kubevirtci.tar.gz diff --git a/automation/release.sh b/automation/release.sh new file mode 100755 index 0000000000..4b062b42cf --- /dev/null +++ b/automation/release.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +set -euxo pipefail + +workdir=$(mktemp -d) +ARTIFACTS=${ARTIFACTS:-/tmp} +base_images=(centos8) +k8s_providers=(1.17 1.18) + +end() { + rm -rf $workdir +} +trap end EXIT + + +function get_latest_digest_suffix() { + local provider=$1 + local latest_digest=$(docker run alexeiled/skopeo skopeo inspect docker://docker.io/kubevirtci/$provider:latest | docker run -i imega/jq -r -c .Digest) + echo "@$latest_digest" +} + + +function build_and_publish_base_images() { + #TODO: Discover what base images need to be build + for base_image in $base_images; do + pushd cluster-provision/$base_image + ./build.sh + ./publish.sh + popd + done +} + +function provision_and_publish_providers() { + #TODO: Discover what providers need to be build + for k8s_provider in $k8s_providers; do + pushd cluster-provision/k8s/$k8s_provider + ../provision.sh + ../publish.sh + popd + done +} + +build_and_publish_base_images + +provision_and_publish_providers + +pushd cluster-provision/gocli + make cli \ + K8S118SUFFIX="$(get_latest_digest_suffix k8s-1.18)" \ + K8S117SUFFIX="$(get_latest_digest_suffix k8s-1.17)" \ + K8S116SUFFIX="$(get_latest_digest_suffix k8s-1.16)" \ + K8S115SUFFIX="$(get_latest_digest_suffix k8s-1.15)" \ + K8S114SUFFIX="$(get_latest_digest_suffix k8s-1.14)" +popd + +# Create kubevirtci dir inside the tarball +mkdir $workdir/kubevirtci + +# Install cluster-up +cp -rf cluster-up/* $workdir/kubevirtci + +# Install gocli +cp -f cluster-provision/gocli/build/cli $workdir/kubevirtci + +# Create the tarball +tar -C $workdir -cvzf $ARTIFACTS/kubevirtci.tar.gz . + +# Install github-release tool +# TODO: Vendor this +export GO111MODULE=on +export GOFLAGS="" +go get github.com/github-release/github-release@v0.8.1 + +# Create the release +tag=$(date +%s) +org=kubevirt + +git tag $tag + +# To pass user/password from automations, idea is taken from [1] +# [1] https://stackoverflow.com/questions/8536732/can-i-hold-git-credentials-in-environment-variables +git config credential.helper '!f() { sleep 1; echo "username=${GITHUB_USER}"; echo "password=${GITHUB_TOKEN}"; }; f' + + +git push https://github.com/$org/kubevirtci $tag +github-release release \ + -u $org \ + -r kubevirtci \ + --tag $tag \ + --name $tag \ + --description "Follow instructions at kubevirtci.tar.gz README" + +# Upload tarball +github-release upload \ + -u $org \ + -r kubevirtci \ + --name kubevirtci.tar.gz \ + --tag $tag\ + --file $ARTIFACTS/kubevirtci.tar.gz + + diff --git a/cluster-provision/centos7/build.sh b/cluster-provision/centos7/build.sh index 0e75a469f6..d08c0e6c4d 100755 --- a/cluster-provision/centos7/build.sh +++ b/cluster-provision/centos7/build.sh @@ -4,4 +4,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" centos_version="$(cat $DIR/version | tr -d '\n')" -docker build --build-arg centos_version=$centos_version . -t kubevirtci/centos:$centos_version +docker build --build-arg centos_version=$centos_version . -t kubevirtci/centos7 diff --git a/cluster-provision/centos7/publish.sh b/cluster-provision/centos7/publish.sh index f9f4759551..91bee32e53 100755 --- a/cluster-provision/centos7/publish.sh +++ b/cluster-provision/centos7/publish.sh @@ -1,8 +1,4 @@ #!/bin/bash -e -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -centos_version="$(cat $DIR/version | tr -d '\n')" - -docker tag kubevirtci/centos:$centos_version docker.io/kubevirtci/centos:$centos_version -docker push docker.io/kubevirtci/centos:$centos_version +docker tag kubevirtci/centos7 docker.io/kubevirtci/centos7 +docker push docker.io/kubevirtci/centos7 diff --git a/cluster-provision/centos8/build.sh b/cluster-provision/centos8/build.sh index 0e75a469f6..6ce545261e 100755 --- a/cluster-provision/centos8/build.sh +++ b/cluster-provision/centos8/build.sh @@ -4,4 +4,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" centos_version="$(cat $DIR/version | tr -d '\n')" -docker build --build-arg centos_version=$centos_version . -t kubevirtci/centos:$centos_version +docker build --build-arg centos_version=$centos_version . -t kubevirtci/centos8 diff --git a/cluster-provision/centos8/publish.sh b/cluster-provision/centos8/publish.sh index f9f4759551..79cd7406b6 100755 --- a/cluster-provision/centos8/publish.sh +++ b/cluster-provision/centos8/publish.sh @@ -2,7 +2,5 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -centos_version="$(cat $DIR/version | tr -d '\n')" - -docker tag kubevirtci/centos:$centos_version docker.io/kubevirtci/centos:$centos_version -docker push docker.io/kubevirtci/centos:$centos_version +docker tag kubevirtci/centos8 docker.io/kubevirtci/centos8 +docker push docker.io/kubevirtci/centos8 diff --git a/cluster-provision/gocli/Makefile b/cluster-provision/gocli/Makefile index 259a81b32d..62cf5e825f 100644 --- a/cluster-provision/gocli/Makefile +++ b/cluster-provision/gocli/Makefile @@ -1,5 +1,13 @@ SHELL := /bin/bash + +K8S118SUFFIX ?= :latest +K8S117SUFFIX ?= :latest +K8S116SUFFIX ?= :latest +K8S115SUFFIX ?= :latest +K8S114SIFFUX ?= :latest + + BIN_DIR = $(CURDIR)/build GO ?= go @@ -13,7 +21,15 @@ all: container-run .PHONY: gocli cli: fmt - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o $(BIN_DIR)/cli ./cmd/cli + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build \ + -ldflags "\ + -X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.K8S118SUFFIX=$(K8S118SUFFIX)'\ + -X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.K8S117SUFFIX=$(K8S117SUFFIX)'\ + -X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.K8S116SUFFIX=$(K8S116SUFFIX)'\ + -X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.K8S115SUFFIX=$(K8S115SUFFIX)'\ + -X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.K8S114SUFFIX=$(K8S114SUFFIX)'\ + " \ + -o $(BIN_DIR)/cli ./cmd/cli .PHONY: fmt fmt: diff --git a/cluster-provision/gocli/cmd/run.go b/cluster-provision/gocli/cmd/run.go index 14db7e02c8..11606896ee 100644 --- a/cluster-provision/gocli/cmd/run.go +++ b/cluster-provision/gocli/cmd/run.go @@ -23,6 +23,7 @@ import ( "kubevirt.io/kubevirtci/cluster-provision/gocli/cmd/utils" "kubevirt.io/kubevirtci/cluster-provision/gocli/docker" + "kubevirt.io/kubevirtci/cluster-provision/gocli/images" ) const proxySettings = ` @@ -72,6 +73,7 @@ func NewRunCommand() *cobra.Command { run.Flags().Bool("enable-ceph", false, "enables dynamic storage provisioning using Ceph") run.Flags().String("docker-proxy", "", "sets network proxy for docker daemon") run.Flags().String("container-registry", "docker.io", "the registry to pull cluster container from") + run.Flags().String("container-org", "kubevirtci", "the organization at the registry to pull the container from") return run } @@ -163,6 +165,11 @@ func run(cmd *cobra.Command, args []string) (err error) { return err } + containerOrg, err := cmd.Flags().GetString("container-org") + if err != nil { + return err + } + cli, err := client.NewEnvClient() if err != nil { return err @@ -185,8 +192,21 @@ func run(cmd *cobra.Command, args []string) (err error) { done <- fmt.Errorf("Interrupt received, clean up") }() + clusterImage := cluster + + // Check if default shas has to be used + clusterSuffix, found := images.SuffixByProvider[cluster] + if found { + if len(clusterSuffix) == 0 { + return fmt.Errorf("Empty Suffix for %s provider", cluster) + } + clusterImage = fmt.Sprintf("%s/%s%s", containerOrg, cluster, clusterSuffix) + } else { + clusterImage = path.Join(containerOrg, cluster) + } + if len(containerRegistry) > 0 { - imageRef := path.Join(containerRegistry, cluster) + imageRef := path.Join(containerRegistry, clusterImage) fmt.Printf("Download the image %s\n", imageRef) err = docker.ImagePull(cli, ctx, imageRef, types.ImagePullOptions{}) if err != nil { @@ -196,7 +216,7 @@ func run(cmd *cobra.Command, args []string) (err error) { // Start dnsmasq dnsmasq, err := cli.ContainerCreate(ctx, &container.Config{ - Image: cluster, + Image: clusterImage, Env: []string{ fmt.Sprintf("NUM_NODES=%d", nodes), fmt.Sprintf("NUM_SECONDARY_NICS=%d", secondaryNics), @@ -416,7 +436,7 @@ func run(cmd *cobra.Command, args []string) (err error) { volumes <- vol.Name node, err := cli.ContainerCreate(ctx, &container.Config{ - Image: cluster, + Image: clusterImage, Env: []string{ fmt.Sprintf("NODE_NUM=%s", nodeNum), }, diff --git a/cluster-provision/gocli/images/images.go b/cluster-provision/gocli/images/images.go new file mode 100644 index 0000000000..13c1340188 --- /dev/null +++ b/cluster-provision/gocli/images/images.go @@ -0,0 +1,20 @@ +package images + +var ( + K8S118SUFFIX = "" + K8S117SUFFIX = "" + K8S116SUFFIX = "" + K8S115SUFFIX = "" + K8S114SUFFIX = "" + SuffixByProvider map[string]string +) + +func init() { + SuffixByProvider = map[string]string{ + "k8s-1.18": K8S118SUFFIX, + "k8s-1.17": K8S117SUFFIX, + "k8s-1.16": K8S116SUFFIX, + "k8s-1.15": K8S115SUFFIX, + "k8s-1.14": K8S114SUFFIX, + } +} diff --git a/cluster-provision/k8s/1.14/base b/cluster-provision/k8s/1.14/base index 5d669c35e3..4dc5d3e003 100644 --- a/cluster-provision/k8s/1.14/base +++ b/cluster-provision/k8s/1.14/base @@ -1 +1 @@ -centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a +centos7:latest diff --git a/cluster-provision/k8s/1.15/base b/cluster-provision/k8s/1.15/base index 5d669c35e3..4dc5d3e003 100644 --- a/cluster-provision/k8s/1.15/base +++ b/cluster-provision/k8s/1.15/base @@ -1 +1 @@ -centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a +centos7:latest diff --git a/cluster-provision/k8s/1.16/base b/cluster-provision/k8s/1.16/base index 5d669c35e3..4dc5d3e003 100644 --- a/cluster-provision/k8s/1.16/base +++ b/cluster-provision/k8s/1.16/base @@ -1 +1 @@ -centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a +centos7:latest diff --git a/cluster-provision/k8s/1.17/base b/cluster-provision/k8s/1.17/base index 55efa708d2..61091e1fb4 100644 --- a/cluster-provision/k8s/1.17/base +++ b/cluster-provision/k8s/1.17/base @@ -1 +1 @@ -centos@sha256:6822c8300b50695896333b53dd5e2aafe9f69ba51b1c89d529740a7f601f6b1b +centos8:latest diff --git a/cluster-provision/k8s/1.18/base b/cluster-provision/k8s/1.18/base index 55efa708d2..61091e1fb4 100644 --- a/cluster-provision/k8s/1.18/base +++ b/cluster-provision/k8s/1.18/base @@ -1 +1 @@ -centos@sha256:6822c8300b50695896333b53dd5e2aafe9f69ba51b1c89d529740a7f601f6b1b +centos8:latest diff --git a/cluster-up/cluster/ephemeral-provider-common.sh b/cluster-up/cluster/ephemeral-provider-common.sh index 8bbed465c2..bc5ebcfcc3 100644 --- a/cluster-up/cluster/ephemeral-provider-common.sh +++ b/cluster-up/cluster/ephemeral-provider-common.sh @@ -2,13 +2,18 @@ set -e -source ${KUBEVIRTCI_PATH}/cluster/images.sh +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" if [ "${KUBEVIRTCI_RUNTIME}" = "podman" ]; then _cli="pack8s" else - _cli_container="${KUBEVIRTCI_GOCLI_CONTAINER:-kubevirtci/${IMAGES[gocli]}}" - _cli="docker run --privileged --net=host --rm ${USE_TTY} -v /var/run/docker.sock:/var/run/docker.sock ${_cli_container}" + _cli="$KUBEVIRTCI_PATH/cli" + # If this is not kubevirtci release tarball build gocli and use, it will + # Use :latest providers + if [ ! -f $_cli ]; then + make -C $KUBEVIRTCI_PATH/../cluster-provision/gocli cli + _cli="$KUBEVIRTCI_PATH/../cluster-provision/gocli/build/cli" + fi fi function _main_ip() { @@ -36,7 +41,7 @@ function _registry_volume() { } function _add_common_params() { - local params="--nodes ${KUBEVIRT_NUM_NODES} --memory ${KUBEVIRT_MEMORY_SIZE} --cpu 6 --secondary-nics ${KUBEVIRT_NUM_SECONDARY_NICS} --random-ports --background --prefix $provider_prefix --registry-volume $(_registry_volume) kubevirtci/${image} ${KUBEVIRT_PROVIDER_EXTRA_ARGS}" + local params="--nodes ${KUBEVIRT_NUM_NODES} --memory ${KUBEVIRT_MEMORY_SIZE} --cpu 6 --secondary-nics ${KUBEVIRT_NUM_SECONDARY_NICS} --random-ports --background --prefix $provider_prefix --registry-volume $(_registry_volume) $KUBEVIRT_PROVIDER ${KUBEVIRT_PROVIDER_EXTRA_ARGS}" if [[ $TARGET =~ windows.* ]] && [ -n "$WINDOWS_NFS_DIR" ]; then params=" --nfs-data $WINDOWS_NFS_DIR $params" elif [[ $TARGET =~ os-.* ]] && [ -n "$RHEL_NFS_DIR" ]; then diff --git a/cluster-up/cluster/images.sh b/cluster-up/cluster/images.sh deleted file mode 100644 index bda87aadb2..0000000000 --- a/cluster-up/cluster/images.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -e - -declare -A IMAGES -IMAGES[gocli]="gocli@sha256:0cec3163e5f8b050f129fa795b76c20cb1eb27c91564c63663160b095064a1f9" -if [ -z $KUBEVIRTCI_PROVISION_CHECK ]; then - IMAGES[k8s-fedora-1.17.0]="k8s-fedora-1.17.0@sha256:aebf67b8b1b499c721f4d98a7ab9542c680553a14cbc144d1fa701fe611f3c0d" - IMAGES[k8s-1.18]="k8s-1.18@sha256:fcf196a188cdb600d35e594b26b39804106e4ad263deea012a8a9a863232c4e4" - IMAGES[k8s-1.17]="k8s-1.17@sha256:789c57e011101c1ba3840809898c17a7e108a20c95a12f6a713ea1d98fa0a19c" - IMAGES[k8s-1.16]="k8s-1.16@sha256:1e153fb62c9a30ce6bc6ddc1af21bb28a56b780ec93ab15e113d729bf664469a" - IMAGES[k8s-1.15]="k8s-1.15@sha256:c58cb9d79968590f24e070bc2517088d44fa2f83ba73e989a7e0f690ad08460b" - IMAGES[k8s-1.14]="k8s-1.14@sha256:46e449b292dcb420f0944cac0a7a5c667c6f19bba2a4192737380e8e77f27ed0" -fi -export IMAGES - -image="${IMAGES[$KUBEVIRT_PROVIDER]:-${KUBEVIRT_PROVIDER}${IMAGE_SUFFIX}:latest}" -export image