From 713f9b1b270d3f3ffb704e3a2b8bcd50000aac95 Mon Sep 17 00:00:00 2001 From: Guilherme Salazar Date: Wed, 11 Sep 2019 15:28:25 -0700 Subject: [PATCH 1/2] ci: add build/release script --- Makefile | 13 +- tools/distros.sh | 13 -- tools/releases/distros.sh | 202 ++++++++++++++++++++ LICENSE => tools/releases/templates/LICENSE | 1 + tools/releases/templates/README | 18 ++ 5 files changed, 222 insertions(+), 25 deletions(-) delete mode 100755 tools/distros.sh create mode 100755 tools/releases/distros.sh rename LICENSE => tools/releases/templates/LICENSE (99%) create mode 100644 tools/releases/templates/README diff --git a/Makefile b/Makefile index b98f9c217462..c03a88a4c764 100644 --- a/Makefile +++ b/Makefile @@ -383,17 +383,6 @@ build/kuma-injector: ## Dev: Build `kuma-injector` binary build/kuma-tcp-echo: ## Dev: Build `kuma-tcp-echo` binary $(GO_BUILD) -o ${BUILD_ARTIFACTS_DIR}/kuma-tcp-echo/kuma-tcp-echo ./app/kuma-tcp-echo/main.go -build/artifact-tarball: build - mkdir ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cp ${BUILD_ARTIFACTS_DIR}/kuma-cp/kuma-cp ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cp ${BUILD_ARTIFACTS_DIR}/kuma-dp/kuma-dp ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cp $(BUILD_ARTIFACTS_DIR)/kumactl/kumactl ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cp ${BUILD_ARTIFACTS_DIR}/kuma-injector/kuma-injector ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cp $(BUILD_ARTIFACTS_DIR)/kuma-tcp-echo/kuma-tcp-echo ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - cd ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - tar -czf ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH}.tar.gz -C ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} . - rm -rf ${BUILD_ARTIFACTS_DIR}/kuma-${GOOS}-${GOARCH} - run/k8s: fmt vet ## Dev: Run Control Plane locally in Kubernetes mode KUBECONFIG=$(KIND_KUBECONFIG) make crd/upgrade -C pkg/plugins/resources/k8s/native KUBECONFIG=$(KIND_KUBECONFIG) \ @@ -581,4 +570,4 @@ run/kuma-dp: ## Dev: Run `kuma-dp` locally KUMA_DATAPLANE_MESH=$(EXAMPLE_DATAPLANE_MESH) \ KUMA_DATAPLANE_NAME=$(EXAMPLE_DATAPLANE_NAME) \ KUMA_DATAPLANE_ADMIN_PORT=$(ENVOY_ADMIN_PORT) \ - $(GO_RUN) ./app/kuma-dp/main.go run --log-level=debug \ No newline at end of file + $(GO_RUN) ./app/kuma-dp/main.go run --log-level=debug diff --git a/tools/distros.sh b/tools/distros.sh deleted file mode 100755 index dac92d82bc3a..000000000000 --- a/tools/distros.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -GOOS=( darwin linux ) -GOARCH=( amd64 ) - -for os in "${GOOS[@]}" -do - for arch in "${GOARCH[@]}" - do - make GOOS=$os GOARCH=$arch build/artifact-tarball - curl -T build/artifacts-$os-$arch/kuma-$os-$arch.tar.gz -u $BINTRAY_USERNAME:$BINTRAY_API_KEY "https://api.bintray.com/content/kong/kuma/$os/$RELEASE_TAG-$arch/kuma-$RELEASE_TAG-$os-$arch.tar.gz?publish=1&override=1" - done -done diff --git a/tools/releases/distros.sh b/tools/releases/distros.sh new file mode 100755 index 000000000000..212fc25c8561 --- /dev/null +++ b/tools/releases/distros.sh @@ -0,0 +1,202 @@ +#!/usr/bin/env bash + +set -e + +GOARCH=( amd64 ) + +# first component is the distribution name, second is the system - must map to +# valid $GOOS values +DISTRIBUTIONS=(debian:linux ubuntu:linux rhel:linux centos:linux darwin:darwin) + + +BINTRAY_ENDPOINT="https://api.bintray.com/" +BINTRAY_SUBJECT="kong" +BINTRAY_REPOSITORY="kuma" + + +function msg_green { + builtin echo -en "\033[1;32m" + echo "$@" + builtin echo -en "\033[0m" +} + + +function msg_red() { + builtin echo -en "\033[1;31m" >&2 + echo "$@" >&2 + builtin echo -en "\033[0m" >&2 +} + + +function msg_yellow() { + builtin echo -en "\033[1;33m" + echo "$@" + builtin echo -en "\033[0m" +} + + +function msg() { + builtin echo -en "\033[1m" + echo "$@" + builtin echo -en "\033[0m" +} + + +function msg_err() { + msg_red $@ + exit 1 +} + + +function get_envoy() { + local distro=$1 + + local status=$(curl -L -o build/envoy-$distro -u $BINTRAY_USERNAME:$BINTRAY_API_KEY \ + --write-out %{http_code} --silent --output /dev/null \ + "https://kong.bintray.com/envoy/envoy-1.11.0-$distro") + + [ "$status" -ne "200" ] && msg_err "Error: failed downloading Envoy" +} + + +function create_tarball { + local system=$1 + local arch=$2 + local distro=$3 + + local dest_dir=build/kuma-$distro-$arch + + rm -rf $dest_dir + mkdir $dest_dir + mkdir $dest_dir/bin + mkdir $dest_dir/conf + + get_envoy $distro + chmod 755 build/envoy-$distro + + cp -p build/envoy-$distro $dest_dir/bin/envoy + cp -p build/artifacts-$system-$arch/kuma-cp/kuma-cp $dest_dir/bin + cp -p build/artifacts-$system-$arch/kuma-dp/kuma-dp $dest_dir/bin + cp -p build/artifacts-$system-$arch/kumactl/kumactl $dest_dir/bin + cp -p build/artifacts-$system-$arch/kuma-tcp-echo/kuma-tcp-echo $dest_dir/bin + cp -p pkg/config/app/kuma-cp/kuma-cp.defaults.yaml $dest_dir/conf/kuma-cp.conf + + cp tools/releases/templates/* $dest_dir + + tar -czf build/artifacts-$system-$arch/kuma-$distro-$arch.tar.gz -C $dest_dir . +} + + +function package { + for os in "${DISTRIBUTIONS[@]}"; do + local distro=$(echo "$os" | awk '{split($0,parts,":"); print parts[1]}') + local system=$(echo "$os" | awk '{split($0,parts,":"); print parts[2]}') + + for arch in "${GOARCH[@]}"; do + + msg ">>> Packaging Kuma for $distro ($system-$arch)..." + msg + + make GOOS=$system GOARCH=$arch BUILD_INFO_GIT_TAG=$KUMA_VERSION BUILD_INFO_GIT_COMMIT=$KUMA_COMMIT build + create_tarball $system $arch $distro + + msg + msg_green "... success!" + msg + done + done +} + + +function create_bintray_package { + local package_name=$1 + local creation_status="$(curl --write-out %{http_code} --silent --output /dev/null \ + -XPOST -H 'Content-Type: application/json' -u $BINTRAY_USERNAME:$BINTRAY_API_KEY\ + -d '{"name":"'"$package_name"'"}' \ + $BINTRAY_ENDPOINT/packages/$BINTRAY_SUBJECT/$BINTRAY_REPOSITORY)" + [ "$creation_status" -eq "409" ] && return + [ "$creation_status" -ne "201" ] && msg_err "Error: could not create package $package_name" +} + + +function release { + for os in "${DISTRIBUTIONS[@]}"; do + local distro=$(echo "$os" | awk '{split($0,parts,":"); print parts[1]}') + local system=$(echo "$os" | awk '{split($0,parts,":"); print parts[2]}') + + for arch in "${GOARCH[@]}"; do + local artifact="build/artifacts-$system-$arch/kuma-$distro-$arch.tar.gz" + [ ! -f "$artifact" ] && msg_yellow "Package '$artifact' not found, skipping..." && continue + + msg_green "Releasing Kuma for '$os', '$arch'..." + + local package_status="$(curl --write-out %{http_code} --silent --output /dev/null \ + -u $BINTRAY_USERNAME:$BINTRAY_API_KEY \ + $BINTRAY_ENDPOINT/content/$BINTRAY_SUBJECT/$BINTRAY_REPOSITORY/$distro)" + [[ "$package_status" -eq "404" ]] && create_bintray_package "$distro" + + local upload_status=$(curl -T $artifact \ + --write-out %{http_code} --silent --output /dev/null \ + -u $BINTRAY_USERNAME:$BINTRAY_API_KEY \ + "$BINTRAY_ENDPOINT/content/$BINTRAY_SUBJECT/$BINTRAY_REPOSITORY/$distro/$KUMA_VERSION-$arch/kuma-$KUMA_VERSION-$distro-$arch.tar.gz?publish=1") + + [ "$upload_status" -eq "409" ] && msg_red "Error: package for '$os', '$arch' already exists" && continue + [ "$upload_status" -ne "201" ] && msg_red "Error: could not upload package for '$os', '$arch' :(" && continue + [ "$upload_status" -eq "201" ] && msg_green "Success! :)" && continue + done + done +} + + +function usage { + echo "Usage: $0 [--package|--release]" + exit 0 +} + + +function main { + while [[ $# -gt 0 ]]; do + flag=$1 + case $flag in + --help) + usage + ;; + --package) + op="package" + ;; + --release) + op="release" + ;; + --version) + KUMA_VERSION=$2 + shift + ;; + --sha) + KUMA_COMMIT=$2 + shift + ;; + *) + usage + break + ;; + esac + shift + done + + [ -z "$BINTRAY_USERNAME" ] && msg_err "BINTRAY_USERNAME required" + [ -z "$BINTRAY_API_KEY" ] && msg_err "BINTRAY_API_KEY required" + [ -z "$KUMA_VERSION" ] && msg_err "Error: --version required" + + case $op in + package) + package + ;; + release) + release + ;; + esac +} + + +main $@ + diff --git a/LICENSE b/tools/releases/templates/LICENSE similarity index 99% rename from LICENSE rename to tools/releases/templates/LICENSE index 2de93c9206b9..367d2ed05485 100644 --- a/LICENSE +++ b/tools/releases/templates/LICENSE @@ -200,3 +200,4 @@ 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. + diff --git a/tools/releases/templates/README b/tools/releases/templates/README new file mode 100644 index 000000000000..83297d6477fc --- /dev/null +++ b/tools/releases/templates/README @@ -0,0 +1,18 @@ +Welcome to Kuma! + +=============================================================================== + +This folder contains your download of Kuma: +├── LICENSE +├── README +├── bin +│ ├── envoy +│ ├── kuma-cp +│ ├── kuma-dp +│ ├── kuma-tcp-echo +│ └── kumactl +└── conf + └── kuma-cp.conf + +The official documentation can be found at https://kuma.io + From ace94a047569f9ce885080f80e1ddb6d1e64716e Mon Sep 17 00:00:00 2001 From: Guilherme Salazar Date: Wed, 11 Sep 2019 15:29:05 -0700 Subject: [PATCH 2/2] ci: integrate build script with ci --- .circleci/config.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70cd1413c132..01d064e085bc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -329,13 +329,19 @@ jobs: - run: name: Verify kumactl workflow command: make kumactl/example/minikube - images/push: - <<: *vm-executor-defaults + release: + <<: *go-defaults steps: - checkout + - restore_cache: + keys: + - go.mod/{{ checksum "go.sum" }} - run: - name: Push Docker images - command: make images/push BINTRAY_USERNAME=$BINTRAY_USERNAME BINTRAY_API_KEY=$BINTRAY_API_KEY KUMA_VERSION=$CIRCLE_TAG + name: Build packages + command: ./tools/releases/distros.sh --package --version $CIRCLE_TAG --sha $CIRCLE_SHA1 + - run: + name: Push Packages + command: ./tools/releases/distros.sh --release --version $CIRCLE_TAG # # Below, the tag filter needs to be in all jobs @@ -390,9 +396,12 @@ workflows: - example/minikube: requires: - build - - images/push: + - release: requires: - - images + - check + - build + - test + - integration filters: branches: ignore: /.*/