Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update build script, integrate with circleci #250

Merged
merged 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -390,9 +396,12 @@ workflows:
- example/minikube:
requires:
- build
- images/push:
- release:
requires:
- images
- check
- build
- test
- integration
filters:
branches:
ignore: /.*/
Expand Down
13 changes: 1 addition & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
$(GO_RUN) ./app/kuma-dp/main.go run --log-level=debug
13 changes: 0 additions & 13 deletions tools/distros.sh

This file was deleted.

202 changes: 202 additions & 0 deletions tools/releases/distros.sh
Original file line number Diff line number Diff line change
@@ -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 $@

1 change: 1 addition & 0 deletions LICENSE → tools/releases/templates/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

18 changes: 18 additions & 0 deletions tools/releases/templates/README
Original file line number Diff line number Diff line change
@@ -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