From c3d71e32c88a9dcd50ea5f320123ff96e7b12160 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 7 Sep 2017 20:58:52 +0000 Subject: [PATCH] Deploy release for each branch update. Signed-off-by: Lantao Liu --- .travis.yml | 7 +++++-- Makefile | 5 +++++ hack/push.sh | 40 ++++++++++++++++++++++++++++++++++++++++ hack/test-e2e-node.sh | 16 ++++++++-------- hack/test-utils.sh | 26 ++++++++++++++++++-------- 5 files changed, 76 insertions(+), 18 deletions(-) create mode 100755 hack/push.sh diff --git a/.travis.yml b/.travis.yml index 6024cc29f..aea15291c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,14 +50,12 @@ jobs: - make .gitvalidation - make verify - make binaries - - make release go: 1.8.x - script: - make install.tools - make .gitvalidation - make verify - make binaries - - make release go: tip - stage: Test script: @@ -76,3 +74,8 @@ jobs: - make install.deps - UPLOAD_LOG=true make test-e2e-node go: 1.8.x + - stage: Deploy + script: + - test "${TRAVIS_PULL_REQUEST}" != "false" && exit 0 || true + - make push + go: 1.8.x diff --git a/Makefile b/Makefile index d3ca165d4..27a118732 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ help: @echo " * 'binaries' - Build cri-containerd" @echo " * 'static-binaries - Build static cri-containerd" @echo " * 'release' - Build release tarball" + @echo " * 'push' - Push release tarball to GCS" @echo " * 'test' - Test cri-containerd" @echo " * 'test-cri' - Test cri-containerd with cri validation test" @echo " * 'test-e2e-node' - Test cri-containerd with Kubernetes node e2e test" @@ -99,6 +100,9 @@ $(BUILD_DIR)/$(TARBALL): $(BUILD_DIR)/cri-containerd hack/versions release: $(BUILD_DIR)/$(TARBALL) +push: $(BUILD_DIR)/$(TARBALL) + @@BUILD_DIR=$(BUILD_DIR) TARBALL=$(TARBALL) ./hack/push.sh + .PHONY: install.deps install.deps: @@ -129,6 +133,7 @@ install.tools: .install.gitvalidation .install.gometalinter binaries \ static-binaries \ release \ + push \ boiler \ clean \ default \ diff --git a/hack/push.sh b/hack/push.sh new file mode 100755 index 000000000..e0e5027a5 --- /dev/null +++ b/hack/push.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright 2017 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 + +source $(dirname "${BASH_SOURCE[0]}")/test-utils.sh + +DEPLOY_BUCKET=${DEPLOY_BUCKET:-"cri-containerd-staging"} +BUILD_DIR=${BUILD_DIR:-"_output"} +TARBALL=${TARBALL:-"cri-containerd.tar.gz"} + +release_tar=${ROOT}/${BUILD_DIR}/${TARBALL} +if [ ! -e ${release_tar} ]; then + echo "Release tarball is not built" + exit 1 +fi + +if ! gsutil ls "gs://${DEPLOY_BUCKET}" > /dev/null; then + create_ttl_bucket ${DEPLOY_BUCKET} +fi + +# TODO(random-liu): Add checksum for the tarball. +gsutil cp ${release_tar} "gs://${DEPLOY_BUCKET}/" +echo "Release tarball is uploaded to: + https://storage.googleapis.com/${DEPLOY_BUCKET}/${TARBALL}" diff --git a/hack/test-e2e-node.sh b/hack/test-e2e-node.sh index bc871e941..fcdf23ab1 100755 --- a/hack/test-e2e-node.sh +++ b/hack/test-e2e-node.sh @@ -41,14 +41,14 @@ sudo iptables-save > ${ORIGINAL_RULES} # Update ip firewall # We need to add rules to accept all TCP/UDP/ICMP packets. if sudo iptables -L INPUT | grep "Chain INPUT (policy DROP)" > /dev/null; then - sudo iptables -A INPUT -w -p TCP -j ACCEPT - sudo iptables -A INPUT -w -p UDP -j ACCEPT - sudo iptables -A INPUT -w -p ICMP -j ACCEPT + sudo iptables -A INPUT -w -p TCP -j ACCEPT + sudo iptables -A INPUT -w -p UDP -j ACCEPT + sudo iptables -A INPUT -w -p ICMP -j ACCEPT fi if sudo iptables -L FORWARD | grep "Chain FORWARD (policy DROP)" > /dev/null; then - sudo iptables -A FORWARD -w -p TCP -j ACCEPT - sudo iptables -A FORWARD -w -p UDP -j ACCEPT - sudo iptables -A FORWARD -w -p ICMP -j ACCEPT + sudo iptables -A FORWARD -w -p TCP -j ACCEPT + sudo iptables -A FORWARD -w -p UDP -j ACCEPT + sudo iptables -A FORWARD -w -p ICMP -j ACCEPT fi # For multiple GOPATHs, keep the first one only @@ -85,8 +85,8 @@ rm ${ORIGINAL_RULES} UPLOAD_LOG_PATH=cri-containerd_test-e2e-node if ${UPLOAD_LOG}; then if [ -z "${VERSION}" ]; then - echo "VERSION is not set" - exit 1 + echo "VERSION is not set" + exit 1 fi upload_logs_to_gcs "${UPLOAD_LOG_PATH}" "${VERSION}-$(date +%Y%m%d-%H%M%S)" "${REPORT_DIR}" fi diff --git a/hack/test-utils.sh b/hack/test-utils.sh index 2f94764b2..a3a58cb33 100644 --- a/hack/test-utils.sh +++ b/hack/test-utils.sh @@ -62,17 +62,27 @@ upload_logs_to_gcs() { local -r dir=$2 local -r result=$3 if ! gsutil ls "gs://${bucket}" > /dev/null; then - gsutil mb "gs://${bucket}" - gsutil -m acl ch -g all:R "gs://${bucket}" - gsutil defacl set public-read "gs://${bucket}" - local -r bucket_rule=$(mktemp) - # Set 30 day TTL for logs inside the bucket. - echo '{"rule": [{"action": {"type": "Delete"},"condition": {"age": 30}}]}' > ${bucket_rule} - gsutil lifecycle set "${bucket_rule}" "gs://${bucket}" - rm "${bucket_rule}" + create_ttl_bucket ${bucket} fi local -r upload_log_path=${bucket}/${dir} gsutil cp -r "${REPORT_DIR}" "gs://${upload_log_path}" echo "Test logs are uploaed to: http://gcsweb.k8s.io/gcs/${upload_log_path}/" } + +# create_ttl_bucket create a public bucket in which all objects +# have a default TTL (30 days). +# Var set: +# 1. Bucket: gcs bucket name. +create_ttl_bucket() { + local -r bucket=$1 + gsutil mb "gs://${bucket}" + local -r bucket_rule=$(mktemp) + # Set 30 day TTL for logs inside the bucket. + echo '{"rule": [{"action": {"type": "Delete"},"condition": {"age": 30}}]}' > ${bucket_rule} + gsutil lifecycle set "${bucket_rule}" "gs://${bucket}" + rm "${bucket_rule}" + + gsutil -m acl ch -g all:R "gs://${bucket}" + gsutil defacl set public-read "gs://${bucket}" +}