diff --git a/local/README.md b/local/README.md new file mode 100644 index 000000000..3f870ea53 --- /dev/null +++ b/local/README.md @@ -0,0 +1,4 @@ + +# The Local Directory + +This directory is for scripts involved with building and testing Twoliter. diff --git a/local/alpha-sdk.dockerfile b/local/alpha-sdk.dockerfile new file mode 100644 index 000000000..3d2c2ba10 --- /dev/null +++ b/local/alpha-sdk.dockerfile @@ -0,0 +1,14 @@ +ARG SDK +ARG HOST_GOARCH + +FROM $SDK +FROM --platform=linux/${HOST_GOARCH} $SDK + +COPY build/rpms/ /twoliter/alpha/build/rpms/ +#COPY sbkeys/generate-local-sbkeys /twoliter/alpha/sbkeys/generate-local-sbkeys +#COPY sbkeys/generate-aws-sbkeys /twoliter/alpha/sbkeys/generate-aws-sbkeys +COPY sources/logdog/conf/current /twoliter/alpha/sources/logdog/conf/current +COPY sources/models/src/variant /twoliter/alpha/sources/models/src/variant +COPY LICENSE-APACHE /twoliter/alpha/licenses/LICENSE-APACHE +COPY LICENSE-MIT /twoliter/alpha/licenses/LICENSE-MIT +COPY COPYRIGHT /twoliter/alpha/licenses/COPYRIGHT diff --git a/local/alpha-sdk.sh b/local/alpha-sdk.sh new file mode 100755 index 000000000..57d28756f --- /dev/null +++ b/local/alpha-sdk.sh @@ -0,0 +1,155 @@ +#!/usr/bin/env bash + +# The Alpha milestone (i.e. preceding Beta) represents a version of Twoliter that can build a +# customized variant before Kits have been implemented. See: +# - https://github.com/bottlerocket-os/twoliter/issues/74 +# - https://github.com/bottlerocket-os/twoliter/issues/56 +# +# This script builds a bottlerocket variant, then copies certain contents of the Bottlerocket build +# directory into a layer added to the SDK. Twoliter's build variant command will expect these to be +# available in the SDK at `/twoliter/alpha` until Kits have been implemented. + +# The directory this script is located in. +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# +# Common error handling +# + +exit_trap_cmds=() + +on_exit() { + exit_trap_cmds+=( "$1" ) +} + +run_exit_trap_cmds() { + for cmd in "${exit_trap_cmds[@]}"; do + eval "${cmd}" + done +} + +trap run_exit_trap_cmds EXIT + +warn() { + >&2 echo "Warning: $*" +} + +bail() { + if [[ $# -gt 0 ]]; then + >&2 echo "Error: $*" + fi + exit 1 +} + +usage() { + cat <&2 usage + bail "$1" +} + +# +# Parse arguments +# + +while [[ $# -gt 0 ]]; do + case $1 in + --bottlerocket-dir) + shift; bottlerocket_dir=$1 ;; + --variant) + shift; variant=$1 ;; + --sdk-version) + shift; sdk_version=$1 ;; + --sdk-name) + shift; sdk_name=$1 ;; + --sdk-registry) + shift; sdk_registry=$1 ;; + --alpha-registry) + shift; alpha_registry=$1 ;; + --alpha-name) + shift; alpha_name=$1 ;; + --alpha-version) + shift; alpha_version=$1 ;; + -h|--help) + usage; exit 0 ;; + *) + usage_error "Invalid option '$1'" ;; + esac + shift +done + +set -e + +[[ -n ${bottlerocket_dir} ]] || usage_error 'required: --bottlerocket-dir' +[[ -n ${sdk_version} ]] || usage_error 'required: --sdk-version' +[[ -n ${alpha_registry} ]] || usage_error 'required: --alpha-registry' +[[ -n ${alpha_version} ]] || usage_error 'required: --alpha-version' + +variant="${variant:=aws-k8s-1.27}" +sdk_name="${sdk_name:=bottlerocket-sdk}" +sdk_registry="${sdk_registry:=public.ecr.aws/bottlerocket}" +sdk_repo="${sdk_registry}/${sdk_name}" +alpha_name="${alpha_name:=twoliter-alpha-sdk}" + +cd "${bottlerocket_dir}" + +for target_arch in x86_64 aarch64 +do + + cargo make \ + -e "BUILDSYS_VARIANT=${variant}" \ + -e "BUILDSYS_ARCH=${target_arch}" \ + build-variant + + for host_arch in amd64 arm64 + do + sdk="${sdk_repo}-${target_arch}:${sdk_version}" + tag="${alpha_registry}/${alpha_name}-${target_arch}:${alpha_version}-${host_arch}" + echo "creating image ${tag}" + docker build \ + --tag "${tag}" \ + --build-arg "SDK=${sdk}" \ + --build-arg "HOST_GOARCH=${host_arch}" \ + --file "${script_dir}/alpha-sdk.dockerfile" \ + "${bottlerocket_dir}" + docker push "${tag}" + done + + arm_host="${alpha_registry}/${alpha_name}-${target_arch}:${alpha_version}-arm64" + amd_host="${alpha_registry}/${alpha_name}-${target_arch}:${alpha_version}-amd64" + multiarch="${alpha_registry}/${alpha_name}-${target_arch}:${alpha_version}" + + echo "creating multiarch manifest ${multiarch}" + docker manifest create "${multiarch}" "${arm_host}" "${amd_host}" + echo "pushing multiarch manifest ${multiarch}" + docker manifest push "${multiarch}" + +done