Skip to content

Commit

Permalink
Merge commit 'cc9ecdf477fc871a898f5690a721f14884673682'
Browse files Browse the repository at this point in the history
  • Loading branch information
ci-robot committed Jul 22, 2020
2 parents 74fb303 + cc9ecdf commit 606e105
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ sonobuoy*

# Bazel directories
cluster-provision/gocli/bazel-*

# Artifacts after releasing
kubevirtci.tar.gz
101 changes: 101 additions & 0 deletions automation/release.sh
Original file line number Diff line number Diff line change
@@ -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/[email protected]

# 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


2 changes: 1 addition & 1 deletion cluster-provision/centos7/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions cluster-provision/centos7/publish.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cluster-provision/centos8/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions cluster-provision/centos8/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 17 additions & 1 deletion cluster-provision/gocli/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
SHELL := /bin/bash


K8S118SUFFIX ?= :latest
K8S117SUFFIX ?= :latest
K8S116SUFFIX ?= :latest
K8S115SUFFIX ?= :latest
K8S114SIFFUX ?= :latest


BIN_DIR = $(CURDIR)/build
GO ?= go

Expand All @@ -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:
Expand Down
26 changes: 23 additions & 3 deletions cluster-provision/gocli/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
},
Expand Down
20 changes: 20 additions & 0 deletions cluster-provision/gocli/images/images.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 1 addition & 1 deletion cluster-provision/k8s/1.14/base
Original file line number Diff line number Diff line change
@@ -1 +1 @@
centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a
centos7:latest
2 changes: 1 addition & 1 deletion cluster-provision/k8s/1.15/base
Original file line number Diff line number Diff line change
@@ -1 +1 @@
centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a
centos7:latest
2 changes: 1 addition & 1 deletion cluster-provision/k8s/1.16/base
Original file line number Diff line number Diff line change
@@ -1 +1 @@
centos@sha256:4f105ae5eb0aa3bb034fa24591ea80bf67701b1bc6449d40aa1bec33bc6a4e9a
centos7:latest
2 changes: 1 addition & 1 deletion cluster-provision/k8s/1.17/base
Original file line number Diff line number Diff line change
@@ -1 +1 @@
centos@sha256:6822c8300b50695896333b53dd5e2aafe9f69ba51b1c89d529740a7f601f6b1b
centos8:latest
2 changes: 1 addition & 1 deletion cluster-provision/k8s/1.18/base
Original file line number Diff line number Diff line change
@@ -1 +1 @@
centos@sha256:6822c8300b50695896333b53dd5e2aafe9f69ba51b1c89d529740a7f601f6b1b
centos8:latest
13 changes: 9 additions & 4 deletions cluster-up/cluster/ephemeral-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions cluster-up/cluster/images.sh

This file was deleted.

0 comments on commit 606e105

Please sign in to comment.