From 1974124855f662f153e9b3135444ea17580e25aa Mon Sep 17 00:00:00 2001 From: trisberg Date: Tue, 10 Jul 2018 12:46:59 -0400 Subject: [PATCH 1/3] Add release.sh script for eventing - creates and publishes `release-eventing.yaml` file --- hack/release.sh | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 hack/release.sh diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 00000000000..e46c167ea2b --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +# Copyright 2018 The Knative 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 pipefail + +source "$(dirname $(readlink -f ${BASH_SOURCE}))/../test/library.sh" + +# Set default GCS/GCR +: ${EVENTING_RELEASE_GCS:="knative-releases"} +: ${EVENTING_RELEASE_GCR:="gcr.io/knative-releases"} +readonly EVENTING_RELEASE_GCS +readonly EVENTING_RELEASE_GCR + +# Local generated yaml file. +readonly OUTPUT_YAML=release-eventing.yaml + +function cleanup() { + restore_override_vars +} + +function banner() { + echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" + echo "@@@@ $1 @@@@" + echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" +} + +# Tag Knative Serving images in the yaml file with a tag. +# Parameters: $1 - yaml file to parse for images. +# $2 - tag to apply. +function tag_knative_images() { + [[ -z $2 ]] && return 0 + echo "Tagging images with $2" + for image in $(grep -o "${EVENTING_RELEASE_GCR}/[a-z\./-]\+@sha256:[0-9a-f]\+" $1); do + gcloud -q container images add-tag ${image} ${image%%@*}:$2 + done +} + +# Copy the given yaml file to the release GCS bucket. +# Parameters: $1 - yaml file to copy. +function publish_yaml() { + gsutil cp $1 gs://${EVENTING_RELEASE_GCS}/latest/ + if (( TAG_RELEASE )); then + gsutil cp $1 gs://${EVENTING_RELEASE_GCS}/previous/${TAG}/ + fi +} + +# Script entry point. + +cd ${EVENTING_ROOT_DIR} +trap cleanup EXIT + +SKIP_TESTS=0 +TAG_RELEASE=0 +DONT_PUBLISH=0 +KO_FLAGS="" + +for parameter in "$@"; do + case $parameter in + --skip-tests) + SKIP_TESTS=1 + shift + ;; + --tag-release) + TAG_RELEASE=1 + shift + ;; + --publish) + DONT_PUBLISH=0 + shift + ;; + --nopublish) + DONT_PUBLISH=1 + KO_FLAGS="-L" + shift + ;; + *) + echo "error: unknown option ${parameter}" + exit 1 + ;; + esac +done + +readonly SKIP_TESTS +readonly TAG_RELEASE +readonly DONT_PUBLISH +readonly KO_FLAGS + +if (( ! SKIP_TESTS )); then + banner "RUNNING RELEASE VALIDATION TESTS" + # Run tests. + ./test/presubmit-tests.sh +fi + +install_ko + +banner " BUILDING THE RELEASE " + +# Set the repository +export KO_DOCKER_REPO=${EVENTING_RELEASE_GCR} +# Build should not try to deploy anything, use a bogus value for cluster. +export K8S_CLUSTER_OVERRIDE=CLUSTER_NOT_SET +export K8S_USER_OVERRIDE=USER_NOT_SET +export DOCKER_REPO_OVERRIDE=DOCKER_NOT_SET + +TAG="" +if (( TAG_RELEASE )); then + commit=$(git describe --tags --always --dirty) + # Like kubernetes, image tag is vYYYYMMDD-commit + TAG="v$(date +%Y%m%d)-${commit}" +fi +readonly TAG + +# If this is a prow job, authenticate against GCR. +(( IS_PROW )) && gcr_auth + +if (( ! DONT_PUBLISH )); then + echo "- Destination GCR: ${EVENTING_RELEASE_GCR}" + echo "- Destination GCS: ${EVENTING_RELEASE_GCS}" +fi + +echo "Building Knative Eventing" +ko resolve ${KO_FLAGS} -f config/ >> ${OUTPUT_YAML} + +tag_knative_images ${OUTPUT_YAML} ${TAG} + +if (( DONT_PUBLISH )); then + echo "New release built successfully" + exit 0 +fi + +echo "Publishing release.yaml" +publish_yaml ${OUTPUT_YAML} + +echo "New release published successfully" From c699eff9ed6ad9688d24a8ed85ff36a618ba0d98 Mon Sep 17 00:00:00 2001 From: trisberg Date: Tue, 10 Jul 2018 14:51:26 -0400 Subject: [PATCH 2/3] Address review comments --- hack/release.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hack/release.sh b/hack/release.sh index e46c167ea2b..f056bc9a98f 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -38,7 +38,7 @@ function banner() { echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" } -# Tag Knative Serving images in the yaml file with a tag. +# Tag Knative Eventing images in the yaml file with a tag. # Parameters: $1 - yaml file to parse for images. # $2 - tag to apply. function tag_knative_images() { @@ -111,10 +111,6 @@ banner " BUILDING THE RELEASE " # Set the repository export KO_DOCKER_REPO=${EVENTING_RELEASE_GCR} -# Build should not try to deploy anything, use a bogus value for cluster. -export K8S_CLUSTER_OVERRIDE=CLUSTER_NOT_SET -export K8S_USER_OVERRIDE=USER_NOT_SET -export DOCKER_REPO_OVERRIDE=DOCKER_NOT_SET TAG="" if (( TAG_RELEASE )); then From c34a6ba80eee4d626a4d88d75776c78ba22a9511 Mon Sep 17 00:00:00 2001 From: trisberg Date: Tue, 10 Jul 2018 17:50:34 -0400 Subject: [PATCH 3/3] Addressing additional review comments --- hack/release.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hack/release.sh b/hack/release.sh index f056bc9a98f..188bd3361be 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -28,10 +28,6 @@ readonly EVENTING_RELEASE_GCR # Local generated yaml file. readonly OUTPUT_YAML=release-eventing.yaml -function cleanup() { - restore_override_vars -} - function banner() { echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" echo "@@@@ $1 @@@@" @@ -61,7 +57,6 @@ function publish_yaml() { # Script entry point. cd ${EVENTING_ROOT_DIR} -trap cleanup EXIT SKIP_TESTS=0 TAG_RELEASE=0 @@ -105,8 +100,6 @@ if (( ! SKIP_TESTS )); then ./test/presubmit-tests.sh fi -install_ko - banner " BUILDING THE RELEASE " # Set the repository @@ -120,9 +113,6 @@ if (( TAG_RELEASE )); then fi readonly TAG -# If this is a prow job, authenticate against GCR. -(( IS_PROW )) && gcr_auth - if (( ! DONT_PUBLISH )); then echo "- Destination GCR: ${EVENTING_RELEASE_GCR}" echo "- Destination GCS: ${EVENTING_RELEASE_GCS}"