Skip to content

Commit

Permalink
ci: add build/release script
Browse files Browse the repository at this point in the history
  • Loading branch information
gszr committed Sep 12, 2019
1 parent 8cd67fc commit 23f31d9
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 20 deletions.
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
155 changes: 148 additions & 7 deletions tools/distros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,153 @@

GOOS=( darwin linux )
GOARCH=( amd64 )
DISTRIBUTIONS=(debian:linux ubuntu:linux rhel:linux centos:linux darwin:darwin)

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"

BINTRAY_ENDPOINT="https://api.bintray.com/"
BINTRAY_SUBJECT="kong"
BINTRAY_REPOSITORY="kuma-tests"


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_err() {
msg_red $@
exit 1
}


function create_tarball {
local system=$1
local arch=$2

local dest_dir=build/kuma-$system-$arch
rm -rf $dest_dir
cp -r tools/template $dest_dir

cp build/artifacts-$system-$arch/kuma-cp/kuma-cp $dest_dir/bin
cp build/artifacts-$system-$arch/kuma-dp/kuma-dp $dest_dir/bin
cp build/artifacts-$system-$arch/kumactl/kumactl $dest_dir/bin
cp build/artifacts-$system-$arch/kuma-injector/kuma-injector $dest_dir/bin
cp build/artifacts-$system-$arch/kuma-tcp-echo/kuma-tcp-echo $dest_dir/bin

tar -czf build/artifacts-$system-$arch/kuma-$system-$arch.tar.gz -C $dest_dir .
}


function package {
# create binaries and tarballs with all binaries
for os in "${GOOS[@]}"; do
for arch in "${GOARCH[@]}"; do

msg_green "**** Packaging Kuma for $os-$arch... ****"
msg_green

make GOOS=$os GOARCH=$arch build
create_tarball $os $arch
done
done

msg_green
msg_green "**** Success, Kuma is built! ****"
}


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-$system-$arch.tar.gz"
[ ! -f "$artifact" ] && msg_red "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_red "Success! :)" && continue
done
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)
[ -z "$BINTRAY_USERNAME" ] && msg_err "BINTRAY_USERNAME required by --release"
[ -z "$BINTRAY_API_KEY" ] && msg_err "BINTRAY_API_KEY required by --release"
op="release"
;;
--version)
KUMA_VERSION=$2
shift
;;
*)
usage
break
;;
esac
shift
done

[ -z "$KUMA_VERSION" ] && msg_err "Error: --release requires --version"

case $op in
package)
package
;;
release)
release
;;
esac
}

main $@

3 changes: 2 additions & 1 deletion LICENSE → tools/template/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2019 Kong Inc.
Copyright 2019-2020 Kong Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -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/template/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

63 changes: 63 additions & 0 deletions tools/template/conf/kuma-cp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Environment Type, can be either "kubernetes" or "universal"
environment: universal # ENV: KUMA_ENVIRONMENT

# Resource Store configuration
store:
# Type of Store used in the Control Plane. Can be either "kubernetes", "postgres" or "memory"
type: memory # ENV: KUMA_STORE_TYPE

# # Postgres Store configuration (used when store.type=postgres)
# postgres:
# # Host of the Postgres DB
# host: postgres.host # ENV: KUMA_STORE_POSTGRES_HOST
# # Port of the Postgres DB
# port: 5432 # ENV: KUMA_STORE_POSTGRES_PORT
# # User of the Postgres DB
# user: konvoy # ENV: KUMA_STORE_POSTGRES_USER
# # Password of the Postgres DB
# password: konvoy # ENV: KUMA_STORE_POSTGRES_PASSWORD
# # Database name of the Postgres DB
# dbName: konvoy # ENV: KUMA_STORE_POSTGRES_DB_NAME
# # Connection Timeout to the DB in seconds
# connectionTimeout: 10 # ENV: KUMA_STORE_POSTGRES_CONNECTION_TIMEOUT

# Configuration of Bootstrap Server, which provides bootstrap config to Dataplanes
bootstrapServer:
# Port of Server that provides bootstrap configuration for dataplanes
port: 5682 # ENV: KUMA_BOOTSTRAP_SERVER_PORT
# Parameters of bootstrap configuration
params:
# Port of Envoy Admin
adminPort: 9901 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_PORT
# Host of XDS Server
xdsHost: localhost # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
# Port of XDS Server
xdsPort: 5678 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT

# Envoy SDS server configuration
sdsServer:
# Port of GRPC server that Envoy connects to
grpcPort: 5677 # ENV: KUMA_SDS_SERVER_GRPC_PORT
# TlsCertFile defines a path to a file with PEM-encoded TLS cert.
tlsCertFile: # ENV: KUMA_SDS_SERVER_TLS_CERT_FILE
# TlsKeyFile defines a path to a file with PEM-encoded TLS key.
tlsKeyFile: # ENV: KUMA_SDS_SERVER_TLS_KEY_FILE

# Envoy XDS server configuration
xdsServer:
# Port of GRPC server that Envoy connects to
grpcPort: 5678 # ENV: KUMA_XDS_SERVER_GRPC_PORT
# Port of Diagnostic Server for checking health and readiness of the Control Plane
diagnosticsPort: 5680 # ENV: KUMA_XDS_SERVER_DIAGNOSTICS_PORT
# Interval for re-genarting configuration for Dataplanes connected to the Control Plane
dataplaneConfigurationRefreshInterval: 1s # ENV: KUMA_XDS_SERVER_DATAPLANE_CONFIGURATION_REFRESH_INTERVAL
# Interval for flushing status of Dataplanes connected to the Control Plane
dataplaneStatusFlushInterval: 1s # ENV: KUMA_XDS_SERVER_DATAPLANE_STATUS_FLUSH_INTERVAL

# API Server configuration
apiServer:
# Port of the API Server
port: 5681 # ENV: KUMA_API_SERVER_PORT
# If true, then API Server will operate in read only mode (serving GET requests)
readOnly: false # ENV: KUMA_API_SERVER_READ_ONLY

0 comments on commit 23f31d9

Please sign in to comment.