Skip to content

Commit

Permalink
Fix docker build relative file path and shellcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kilroy authored and idoru committed Oct 23, 2023
1 parent ea918c5 commit 3cffe86
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ set -o errexit
set -o nounset
set -o pipefail

ROOT=$(cd "$(dirname $0)"/.. && pwd)
ROOT=$(cd "$(dirname "$0")"/.. && pwd)
readonly ROOT

readonly SCRATCH=${SCRATCH:-$(mktemp -d)}
readonly REGISTRY=${REGISTRY:-"$($ROOT/hack/ip.py):5001"}
readonly REGISTRY=${REGISTRY:-"$("$ROOT"/hack/ip.py):5001"}
readonly RELEASE_DATE=${RELEASE_DATE:-$(TZ=UTC date +"%Y-%m-%dT%H:%M:%SZ")}

main() {
readonly RELEASE_VERSION=${RELEASE_VERSION:-"v0.0.0-dev"}
readonly RELEASE_IMAGE=${RELEASE_IMAGE:-$REGISTRY/cartographer:$RELEASE_VERSION}
readonly PREVIOUS_VERSION=${PREVIOUS_VERSION:-$(git_previous_version $RELEASE_VERSION)}
readonly PREVIOUS_VERSION=${PREVIOUS_VERSION:-$(git_previous_version "$RELEASE_VERSION")}

readonly RELEASE_USING_LEVER=${RELEASE_USING_LEVER:-false}
readonly LEVER_COMMIT_REF=${LEVER_COMMIT_REF:-"$(git rev-parse HEAD)"}
readonly LEVER_KUBECONFIG=${LEVER_KUBECONFIG:-""}

show_vars
cd $ROOT
cd "$ROOT"

if [[ $RELEASE_USING_LEVER == true ]]; then
if [[ "$RELEASE_USING_LEVER" == true ]]; then
# Lever build flow
if [[ $REGISTRY == "192.168."* ]]; then
if [[ "$REGISTRY" == "192.168."* ]]; then
echo "REGISTRY must be set to a registry accessible by lever when RELEASE_USING_LEVER is true"
exit 1
fi
if [[ $LEVER_KUBECONFIG == "" ]]; then
if [[ "$LEVER_KUBECONFIG" == "" ]]; then
echo "LEVER_KUBECONFIG must be set when RELEASE_USING_LEVER is true"
exit 1
fi
Expand Down Expand Up @@ -73,12 +73,12 @@ show_vars() {

lever_build_request() {
# Lever build request expects LEVER_KUBECONFIG to be the kubeconfig yaml to access the lever cluster
readonly BUILD_SUFFIX="$(git rev-parse HEAD | head -c 6)-$(echo $RANDOM | shasum | head -c 6; echo)"
BUILD_SUFFIX="$(git rev-parse HEAD | head -c 6)-$(echo $RANDOM | shasum | head -c 6; echo)"
ytt --ignore-unknown-comments -f ./hack/lever_build_request.yaml \
--data-value build_suffix=$BUILD_SUFFIX \
--data-value commit_ref=$LEVER_COMMIT_REF \
--data-value release_image=$RELEASE_IMAGE \
| kubectl --kubeconfig <(printf "${LEVER_KUBECONFIG}") apply -f -
--data-value build_suffix="$BUILD_SUFFIX" \
--data-value commit_ref="$LEVER_COMMIT_REF" \
--data-value release_image="$RELEASE_IMAGE" \
| kubectl --kubeconfig <(printf '%s' "${LEVER_KUBECONFIG}") apply -f -
wait_for_lever_build "cartographer-$BUILD_SUFFIX"
}

Expand All @@ -95,13 +95,13 @@ wait_for_lever_build() {
echo "Waiting for lever build $build_name to complete..."
# Lever build request has a few build statuses with the final status being the aggregate and the one we wait on
while [[ $ready_status != 'False' && $ready_status != 'True' ]]; do
conditions_json=$(kubectl --kubeconfig <(printf "${LEVER_KUBECONFIG}") get request/$build_name -o jsonpath='{.status.conditions}')
components_status=$(echo $conditions_json | jq -r 'map(select(.type == "ComponentsReady"))[0].status')
build_status=$(echo $conditions_json | jq -r 'map(select(.type == "BuildReady"))[0].status')
srp_status=$(echo $conditions_json | jq -r 'map(select(.type == "SRPResourceSubmitted"))[0].status')
ready_status=$(echo $conditions_json | jq -r 'map(select(.type == "Ready"))[0].status')
conditions_json=$(kubectl --kubeconfig <(printf '%s' "${LEVER_KUBECONFIG}") get request/"$build_name" -o jsonpath='{.status.conditions}')
components_status=$(echo "$conditions_json" | jq -r 'map(select(.type == "ComponentsReady"))[0].status')
build_status=$(echo "$conditions_json" | jq -r 'map(select(.type == "BuildReady"))[0].status')
srp_status=$(echo "$conditions_json" | jq -r 'map(select(.type == "SRPResourceSubmitted"))[0].status')
ready_status=$(echo "$conditions_json" | jq -r 'map(select(.type == "Ready"))[0].status')
loading_char=$(printf "%${counter}s")
printf "ComponentsReady: $components_status; BuildReady: $build_status; SRPResourceSubmitted: $srp_status; Ready: $ready_status; ${loading_char// /.}\033[0K\r"
printf "ComponentsReady: %s; BuildReady: %s; SRPResourceSubmitted: %s; Ready: %s; ${loading_char// /.}\033[0K\r" "$components_status" "$build_status" "$srp_status" "$ready_status"
counter=$((counter + 1))
if [[ $counter -gt 3 ]]; then
counter=1
Expand All @@ -111,36 +111,36 @@ wait_for_lever_build() {

if [[ $ready_status == 'False' ]]; then
echo "Lever build $build_name failed"
ready_message=$(echo $conditions_json | jq 'map(select(.type == "Ready"))[0].message')
ready_message=$(echo "$conditions_json" | jq 'map(select(.type == "Ready"))[0].message')
echo "Error: $ready_message"
exit 1
else
# Output here is being parsed by the release pipeline to pass references to package-for-cartographer and catalog
echo "Lever build $build_name succeeded. Image published:"
kubectl --kubeconfig <(printf "${LEVER_KUBECONFIG}") get request/$build_name -o jsonpath='{.status.artifactStatus.images[0].name}'
kubectl --kubeconfig <(printf '%s' "${LEVER_KUBECONFIG}") get request/"$build_name" -o jsonpath='{.status.artifactStatus.images[0].name}'
echo ""
kubectl --kubeconfig <(printf "${LEVER_KUBECONFIG}") get request/$build_name -o jsonpath='{.status.artifactStatus.images[0].image.tag}'
kubectl --kubeconfig <(printf '%s' "${LEVER_KUBECONFIG}") get request/"$build_name" -o jsonpath='{.status.artifactStatus.images[0].image.tag}'
fi
}

build_image() {
# Build the image locally using Docker instead of ko
docker build ../.. -t $RELEASE_IMAGE --build-arg BASE_IMAGE="ubuntu:jammy" --build-arg GOLANG_IMAGE="golang:1.19"
docker push $RELEASE_IMAGE
docker build "$ROOT" -t "$RELEASE_IMAGE" --build-arg BASE_IMAGE="ubuntu:jammy" --build-arg GOLANG_IMAGE="golang:1.19"
docker push "$RELEASE_IMAGE"
}

generate_release() {
mkdir -p ./release
ytt --ignore-unknown-comments -f ./config \
-f ./hack/overlays/webhook-configuration.yaml \
-f ./hack/overlays/component-labels.yaml \
--data-value version=$RELEASE_VERSION \
--data-value controller_image=$RELEASE_IMAGE > ./release/cartographer.yaml
--data-value version="$RELEASE_VERSION" \
--data-value controller_image="$RELEASE_IMAGE" > ./release/cartographer.yaml
}

create_release_notes() {
local changeset
changeset="$(git_changeset $RELEASE_VERSION $PREVIOUS_VERSION)"
changeset="$(git_changeset "$RELEASE_VERSION" "$PREVIOUS_VERSION")"

local assets_checksums
assets_checksums=$(checksums ./release)
Expand All @@ -151,7 +151,7 @@ create_release_notes() {
checksums() {
local assets_directory=$1

pushd $assets_directory &>/dev/null
pushd "$assets_directory" &>/dev/null
find . -name "*" -type f -exec sha256sum {} +
popd &>/dev/null
}
Expand All @@ -160,9 +160,9 @@ git_changeset() {
local current_version=$1
local previous_version=$2

[[ $current_version != v* ]] && current_version=v$current_version
[[ $previous_version != v* ]] && previous_version=v$previous_version
[[ $(git tag -l $current_version) == "" ]] && current_version=HEAD
[[ "$current_version" != v* ]] && current_version="v${current_version}"
[[ "$previous_version" != v* ]] && previous_version="v${previous_version}"
[[ $(git tag -l "$current_version") == "" ]] && current_version=HEAD

git -c log.showSignature=false \
log \
Expand All @@ -177,12 +177,12 @@ git_previous_version() {
local current_version=$1

local version_filter
version_filter=$(printf '^%s$' $current_version)
version_filter=$(printf '^%s$' "$current_version")

[[ $(git tag -l $current_version) == "" ]] && version_filter='.'
[[ $(git tag -l "$current_version") == "" ]] && version_filter='.'

git tag --sort=-v:refname -l |
grep -A30 $version_filter |
grep -A30 "$version_filter" |
grep -E '^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$' |
head -n1
}
Expand Down Expand Up @@ -229,6 +229,8 @@ Thanks to these contributors who contributed to <NEW_TAG>!
%s
```
'
# wokeignore:rule=disable
# shellcheck disable=SC2059
printf "$fmt" "$previous_version" "$changeset" "$checksums"
}

Expand Down

0 comments on commit 3cffe86

Please sign in to comment.