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

Add scripts for pushing CI builds to community owned infra #119

Merged
merged 3 commits into from
Mar 25, 2021
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
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# get the repo root and output path
REPO_ROOT:=$(shell pwd)
export REPO_ROOT
OUT_DIR=$(REPO_ROOT)/bin
OUT_DIR?=$(REPO_ROOT)/bin
INSTALL?=install
# make install will place binaries here
# the default path attempts to mimic go install
Expand Down Expand Up @@ -71,9 +71,22 @@ install-tester-%:
$(INSTALL) -d $(INSTALL_DIR)
$(INSTALL) $(OUT_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/$(BINARY_NAME)

install-all: TESTERS := $(wildcard kubetest2-tester-*)
install-all: DEPLOYERS := $(filter-out $(TESTERS), $(wildcard kubetest2-*))
install-all: TESTER_TARGETS := $(subst kubetest2-tester-,install-tester-, $(TESTERS))
install-all: DEPLOYER_TARGETS := $(subst kubetest2-,install-deployer-, $(DEPLOYERS))
install-all: install
$(MAKE) -j $(DEPLOYER_TARGETS) $(TESTER_TARGETS)

quick-verify: install install-deployer-kind install-tester-exec
kubetest2 kind --up --down --test=exec -- kubectl get all -A

ci-binaries:
./hack/build/ci-binaries.sh

push-ci-binaries:
./hack/ci/push-binaries/push-binaries.sh

# cleans the output directory
clean-output:
rm -rf $(OUT_DIR)/
Expand Down Expand Up @@ -103,4 +116,4 @@ unit:
verify:
$(MAKE) -j lint shellcheck unit tidy boilerplate

.PHONY: build-all install install-deployer-% install-tester-% quick-verify clean-output clean verify lint shellcheck
.PHONY: build-all install install-deployer-% install-tester-% install-all ci-binaries push-ci-binaries quick-verify clean-output clean verify lint shellcheck
42 changes: 42 additions & 0 deletions hack/build/ci-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2021 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
set -o xtrace

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}" &> /dev/null
source hack/build/setup-go.sh

make clean

OS_ARCHES=(
linux_amd64
darwin_amd64
)

build_os_arch() {
os="$(echo "$1" | cut -d '_' -f 1)"
arch="$(echo "$1" | cut -d '_' -f 2)"
make install-all GOOS="${os}" GOARCH="${arch}" OUT_DIR="${REPO_ROOT}/bin/${os}/${arch}"
}

export -f build_os_arch

# NOTE: disable SC2016 because we _intend_ for these to evaluate later
# shellcheck disable=SC2016
printf '%s\0' "${OS_ARCHES[@]}" | xargs -0 -n 1 -P "${PARALLELISM:-0}" bash -c 'build_os_arch $0'
55 changes: 55 additions & 0 deletions hack/ci/push-binaries/push-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Copyright 2021 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
set -o xtrace

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}" &> /dev/null


# pass through git details from prow / image builder
if [ -n "${PULL_BASE_SHA:-}" ]; then
export COMMIT="${PULL_BASE_SHA:?}"
else
COMMIT="$(git rev-parse --short HEAD 2>/dev/null)"
export COMMIT
fi

# we upload here
BUCKET="${BUCKET:-k8s-staging-kubetest2}"
export BUCKET

# under each of these
VERSIONS=(
latest
"${COMMIT}"
)

# build the ci binaries
make ci-binaries

gcs_upload_version() {
echo "uploading CI binaries to gs://${BUCKET}/$1/ ..."
gsutil -m cp -P -r "${REPO_ROOT}/bin" "gs://${BUCKET}/$1/"
}

export -f gcs_upload_version

# NOTE: disable SC2016 because we _intend_ for these to evaluate later
# shellcheck disable=SC2016
printf '%s\0' "${VERSIONS[@]}" | xargs -0 -n 1 -P "${PARALLELISM:-0}" bash -c 'gcs_upload_version $0'