Skip to content

Commit

Permalink
Merge pull request #2434 from openziti/tidy-and-fix-quickstart-release
Browse files Browse the repository at this point in the history
fix quickstart release
  • Loading branch information
qrkourier authored Sep 24, 2024
2 parents 7a99ace + 25f9120 commit ba59398
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 48 deletions.
49 changes: 28 additions & 21 deletions .github/workflows/release-quickstart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ on:
jobs:
release-quickstart:
name: Release Quickstart Job
# this is only run on the official upstream repo when a PR is merged to the default branch "main" or a release tag
# is pushed; merges to main trigger a quickstart release with a commit SHA suffix featuring the previous ziti binary
# release version, whereas release tag pushes trigger a quickstart release with the same tag name and the same ziti
# binary release version
if: github.repository_owner == 'openziti'
&& (
startsWith(github.ref_name, 'v')
|| (github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'quickstartrelease'))
# this is only run on the official upstream repo when a PR is merged to the
# default branch "main" or a release tag is pushed or for the same
# conditions in a repo fork that overrides the container image repo to push
# to; merges to main trigger a quickstart release with a commit SHA suffix
# featuring the previous ziti binary release version, whereas release tag
# pushes trigger a quickstart release with the same tag name and the same
# ziti binary release version
if: (github.repository_owner == 'openziti' || vars.ZITI_QUICKSTART_IMAGE != '') && (
startsWith(github.ref_name, 'v') || (
github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'quickstartrelease')
)
)
runs-on: ubuntu-latest
env:
ZITI_QUICKSTART_IMAGE: ${{ vars.ZITI_QUICKSTART_IMAGE || 'docker.io/openziti/quickstart' }}
# use github.ref, not github.head_ref, because this workflow should only run on merged PRs in the target/base
# branch context, not the PR source branch
GITHUB_REF: ${{ github.ref }}
# user github.sha, not github.pull_request.head.sha, because this workflow should only run on merged PRs in the
# use github.sha, not github.pull_request.head.sha, because this workflow should only run on merged PRs in the
# target/base branch, not the PR source branch
GITHUB_SHA: ${{ github.sha }}
steps:
Expand Down Expand Up @@ -89,32 +93,32 @@ jobs:
if [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Set output parameters for release tags
echo QUICKSTART_VERSION="${GITHUB_REF_NAME}" | tee -a $GITHUB_OUTPUT
QUICKSTART_VERSION="${GITHUB_REF_NAME}"
elif [[ "${GITHUB_REF_NAME}" =~ ^main$ ]]; then
# compute the latest release version to install in the quickstart image
QUICKSTART_VERSION="$($(go env GOPATH)/bin/ziti-ci -q get-current-version ${ZITI_BASE_VERSION:+--base-version $ZITI_BASE_VERSION})"
# drop the leading 'v', if any
QUICKSTART_VERSION=${QUICKSTART_VERSION#v}
validateSemver "${QUICKSTART_VERSION}"
# Append short SHA to identify quickstart docker images shipped on merge to main
QUICKSTART_VERSION="${QUICKSTART_VERSION}-$(git rev-parse --short ${GITHUB_SHA})"
echo QUICKSTART_VERSION="${QUICKSTART_VERSION}" | tee -a $GITHUB_OUTPUT
else
echo "ERROR: Unexpected GITHUB_REF_NAME=${GITHUB_REF_NAME}" >&2
exit 1
fi
# configure the env var used by the quickstart's Dockerfile to download the correct version of ziti for the
# target architecture of each image build by trimming the hyphenated short sha suffix so that the preceding
# release version of the ziti executable is installed in the quickstart container image
ZITI_OVERRIDE_VERSION=${QUICKSTART_VERSION%-*}
echo ZITI_OVERRIDE_VERSION="${ZITI_OVERRIDE_VERSION}" | tee -a $GITHUB_OUTPUT
# configure the env var used by the quickstart's Dockerfile to
# download the correct version of ziti for the target architecture of
# each image build by trimming the hyphenated short sha suffix so that
# the preceding release version of the ziti executable is installed in
# the quickstart container image; ensure the QUICKSTART_VERSION
# (container image tag) does not have a leading 'v' and the
# ZITI_VERSION_OVERRIDE (GitHub tag ref) does have a leading 'v'
QUICKSTART_VERSION="${QUICKSTART_VERSION#v}"
echo QUICKSTART_VERSION="${QUICKSTART_VERSION}" | tee -a $GITHUB_OUTPUT
echo ZITI_VERSION_OVERRIDE=v${QUICKSTART_VERSION%-*} | tee -a $GITHUB_OUTPUT
# container image tag :latest is published on merge to default branch "main" and on release tags
- name: Configure Quickstart Container
Expand All @@ -137,6 +141,8 @@ jobs:
tags: ${{ steps.tagprep_qs.outputs.DOCKER_TAGS }}
build-args: |
ZITI_VERSION_OVERRIDE=${{ steps.get_version.outputs.ZITI_VERSION_OVERRIDE }}
GITHUB_REPO_OWNER=${{ github.repository_owner }}
GITHUB_REPO_NAME=${{ github.event.repository.name }}
push: true

- name: Configure Python
Expand All @@ -146,6 +152,7 @@ jobs:
python --version
- name: Deploy the CloudFront Function for get.openziti.io
if: github.repository_owner == 'openziti'
shell: bash
run: python ./dist/cloudfront/get.openziti.io/deploy-cloudfront-function.py
env:
Expand Down
2 changes: 1 addition & 1 deletion dist/dist-packages/linux/openziti-router/bootstrap.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# this is the ziti-controller.service bootstrapping inputs file where answers are recorded for generating a
# this is the ziti-router.service bootstrapping inputs file where answers are recorded for generating a
# configuration
#

Expand Down
4 changes: 2 additions & 2 deletions quickstart/docker/createLocalImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ fi

# optionally, configure ZITI_VERSION for pushLatestDocker.sh
if [[ -n "${ZITI_VERSION_OVERRIDE:-}" && -n "${ZITI_VERSION:-}" ]]; then
echo "WARN: both ZITI_VERSION and ZITI_VERSION_OVERRIDE are set, overriding $ZITI_VERSION with $ZITI_OVERRIDE_VERSION" >&2
echo "WARN: both ZITI_VERSION and ZITI_VERSION_OVERRIDE are set, overriding $ZITI_VERSION with $ZITI_VERSION_OVERRIDE" >&2
export ZITI_VERSION="${ZITI_VERSION_OVERRIDE#v}"
elif [[ -n "${ZITI_VERSION_OVERRIDE:-}" ]]; then
echo "INFO: ZITI_VERSION_OVERRIDE is set, setting ZITI_VERSION=${ZITI_OVERRIDE_VERSION#v}"
echo "INFO: ZITI_VERSION_OVERRIDE is set, setting ZITI_VERSION=${ZITI_VERSION_OVERRIDE#v}"
export ZITI_VERSION="${ZITI_VERSION_OVERRIDE#v}"
elif [[ -n "${ZITI_VERSION:-}" ]]; then
echo "INFO: ZITI_VERSION is set, using ZITI_VERSION=${ZITI_VERSION#v}"
Expand Down
4 changes: 4 additions & 0 deletions quickstart/docker/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ FROM ubuntu:rolling AS fetch-ziti-bins
# optional arg to specify which version to fetch when local "ziti-bin" directory is not present
ARG ZITI_VERSION_OVERRIDE
ARG DEBIAN_FRONTEND=noninteractive
ARG GITHUB_REPO_OWNER=openziti
ARG GITHUB_REPO_NAME=ziti
ENV GITHUB_REPO_OWNER=${GITHUB_REPO_OWNER}
ENV GITHUB_REPO_NAME=${GITHUB_REPO_NAME}

RUN apt-get update \
&& apt-get --yes install \
Expand Down
10 changes: 7 additions & 3 deletions quickstart/docker/image/fetch-ziti-bins.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace

# this script is executed during the docker build, after the build context has been copied to /docker.build.context

dest="${1}"
ZITI_BIN_DIR="${1}"

if [ -d /docker.build.context/ziti-bin ]; then
mv /docker.build.context/ziti-bin/ "${dest}"
mv /docker.build.context/ziti-bin/ "${ZITI_BIN_DIR}"
else
source /docker.build.context/ziti-cli-functions.sh
getZiti
mv "${ZITI_BIN_DIR}" "${dest}"
fi
33 changes: 19 additions & 14 deletions quickstart/docker/image/ziti-cli-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ASCI_BLUE='\033[00;34m'
ASCI_PURPLE='\033[00;35m'
ZITIx_EXPRESS_COMPLETE=""

: "${GITHUB_REPO_OWNER:=openziti}"
: "${GITHUB_REPO_NAME:=ziti}"

function WHITE {
echo "${ASCI_WHITE}${1-}${ASCI_RESTORE}"
}
Expand Down Expand Up @@ -245,7 +248,7 @@ function _check_env_variable() {
_error=true
fi
else
echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") "
echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}") "
return 1
fi
done
Expand Down Expand Up @@ -647,7 +650,7 @@ function getZiti {
getLatestZitiVersion # sets ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION
default_path="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"
echo -en "The path for ziti binaries has not been set, use the default (${default_path})? (Y/n) "
read -r reply
read -r reply || true
if [[ -z "${reply}" || ${reply} =~ [yY] ]]; then
echo "INFO: using the default path ${default_path}"
ZITI_BIN_DIR="${default_path}"
Expand All @@ -667,17 +670,14 @@ function getZiti {
return 1
fi
else
_check_env_variable ZITI_BINARIES_FILE ZITI_BINARIES_VERSION
retVal=$?
if [[ "${retVal}" != 0 ]]; then
return 1
fi

# Check if an error occurred while trying to pull desired version (happens with incorrect version or formatting issue)
if ! _verify_ziti_version_exists; then
echo -e " * $(RED "ERROR: The version of ziti requested (${ZITI_VERSION_OVERRIDE}) could not be found for OS (${ZITI_OSTYPE}) and architecture (${ZITI_ARCH}). Please check these details and try again. The version should follow the format \"vx.x.x\".") "
return 1
fi
if ! _check_env_variable ZITI_BINARIES_FILE ZITI_BINARIES_VERSION; then
return 1
fi
fi

# Where to store the ziti binaries zip
Expand All @@ -686,7 +686,7 @@ function getZiti {
if ! test -f "${ZITI_BIN_DIR}/ziti"; then
# Make the directory
echo -e "No existing binary found, creating the ZITI_BIN_DIR directory ($(BLUE "${ZITI_BIN_DIR}"))"
mkdir -p "${ZITI_BIN_DIR}"
mkdir -p "${ZITI_BIN_DIR}/ziti-extract"
retVal=$?
if [[ "${retVal}" != 0 ]]; then
echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR})")"
Expand All @@ -706,7 +706,7 @@ function getZiti {
unset ZITI_BIN_DIR
_set_ziti_bin_dir
# Make the directory
mkdir -p "${ZITI_BIN_DIR}"
mkdir -p "${ZITI_BIN_DIR}/ziti-extract"
retVal=$?
if [[ "${retVal}" != 0 ]]; then
echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")"
Expand Down Expand Up @@ -737,12 +737,17 @@ function getZiti {
fi

# Get the download link
zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}"
zitidl="https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}"
echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ziti_binaries_file_abspath}")"
curl -Ls "${zitidl}" -o "${ziti_binaries_file_abspath}"

# Unzip the files
tar -xf "${ziti_binaries_file_abspath}" --directory "${ZITI_BIN_DIR}"
tar -xf "${ziti_binaries_file_abspath}" --directory "${ZITI_BIN_DIR}/ziti-extract"
if [ -d "${ZITI_BIN_DIR}/ziti-extract/ziti" ]; then
mv "${ZITI_BIN_DIR}/ziti-extract/ziti/ziti" "${ZITI_BIN_DIR}/ziti"
else
mv "${ZITI_BIN_DIR}/ziti-extract/ziti" "${ZITI_BIN_DIR}/ziti"
fi

# Cleanup
rm "${ziti_binaries_file_abspath}" # Remove zip
Expand Down Expand Up @@ -1137,7 +1142,7 @@ function getLatestZitiVersion {

_detect_architecture

ziti_latest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/latest)
ziti_latest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/latest)
ZITI_BINARIES_FILE=$(printf "%s" "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name')
ZITI_BINARIES_VERSION=$(printf "%s" "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.tag_name')
}
Expand Down Expand Up @@ -1494,7 +1499,7 @@ function _verify_ziti_version_exists {

_detect_architecture

ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")"
ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/tags/"${ZITI_VERSION_OVERRIDE}")"
ZITI_BINARIES_FILE=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name')
ZITI_BINARIES_VERSION=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.tag_name')

Expand Down
17 changes: 11 additions & 6 deletions quickstart/docker/pushLatestDocker.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env bash
set -eo pipefail

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
: "${ZITI_QUICKSTART_IMAGE:=openziti/quickstart}"

if [ -z "${ZITI_VERSION}" ]; then
if [ -z "${ZITI_VERSION:-}" ]; then
DOCKER_IMAGE_ROOT="$(realpath ${SCRIPT_DIR}/image)"
v=$(source "${DOCKER_IMAGE_ROOT}/ziti-cli-functions.sh"; getLatestZitiVersion > /dev/null 2>&1; echo ${ZITI_BINARIES_VERSION})
ZITI_VERSION=$(echo "${v}" | sed -e 's/^v//')
echo "ZITI_VERSION=${ZITI_VERSION}"
fi

if [ -z "${ZITI_VERSION}" ]; then
if [ -z "${ZITI_VERSION:-}" ]; then
echo "ZITI_VERSION was not set and auto-detection failed."
exit 1
fi
Expand All @@ -21,7 +26,7 @@ if [ -z "${IMAGE_TAG}" ]; then
echo "image tag name was not provided, using default '${IMAGE_TAG}'"
fi

if [ "local" == "${1}" ]; then
if [ "local" == "${1-}" ]; then
echo "LOADING LOCALLY instead of pushing to dockerhub"
_BUILDX_PLATFORM=""
_BUILDX_ACTION="--load"
Expand All @@ -36,6 +41,6 @@ docker buildx create \

eval docker buildx build "${_BUILDX_PLATFORM}" "${SCRIPT_DIR}/image" \
--build-arg ZITI_VERSION_OVERRIDE="v${ZITI_VERSION}" \
--tag "openziti/quickstart:${ZITI_VERSION}" \
--tag "openziti/quickstart:${IMAGE_TAG}" \
--tag "${ZITI_QUICKSTART_IMAGE}:${ZITI_VERSION}" \
--tag "${ZITI_QUICKSTART_IMAGE}:${IMAGE_TAG}" \
"${_BUILDX_ACTION}"
2 changes: 1 addition & 1 deletion quickstart/test/compose-test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if [[ -n "${ZITI_QUICK_DIR:-}" ]]; then
if [[ -x "${ZITI_QUICK_DIR:-}/docker/createLocalImage.sh" ]]; then
(
cd "${ZITI_QUICK_DIR}/docker"
unset ZITI_VERSION ZITI_OVERRIDE_VERSION # always build the local source
unset ZITI_VERSION ZITI_VERSION_OVERRIDE # always build the local source
./createLocalImage.sh --build "${ZITI_QUICK_TAG}"
)
else
Expand Down

0 comments on commit ba59398

Please sign in to comment.