Skip to content

Commit

Permalink
alpha: add rpms to sdk
Browse files Browse the repository at this point in the history
To create an early-access version of twoliter build variant, we need
an SDK that contains the Bottlerocket rpms. This script and Dockerfile
creates it.
  • Loading branch information
webern committed Oct 6, 2023
1 parent 09734ab commit 2a54bb3
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
4 changes: 4 additions & 0 deletions local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# The Local Directory

This directory is for scripts involved with building and testing Twoliter.
14 changes: 14 additions & 0 deletions local/alpha-sdk.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG SDK
ARG TARGET_GOARCH

FROM $SDK
FROM --platform=linux/${TARGET_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
141 changes: 141 additions & 0 deletions local/alpha-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/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 <<EOF
Usage: $0 --bottlerocket-dir DIR [--variant VARIANT] [--arch ARCH] --sdk-version SDK_VERSION [--sdk-name SDK_NAME] [ --sdk-registry SDK_REGISTRY ] [-h]
--bottlerocket-dir The directory of the Bottlerocket checkout that we will build.
--variant The Bottlerocket variant that we will build.
--sdk-version The version of the Bottlerocket SDK to use when building packages
and to use as the base for the Twoliter alpha-sdk. For example if
the SDK version is v0.50.0 then --sdk-version should be the same
(i.e. with the v prefix).
--sdk-name The name prefix of the SDK. For example, in this following string
'bottlerocket' is the SDK name:
public.ecr.aws/bottlerocket/bottlerocket-sdk-x86_64:v0.50.0
Note that the suffix '-sdk' is assumed and added to the name,
which is just 'bottlerocket'
--sdk-registry The namespace or Docker registry where the SDK is found. For
example, in the following string 'public.ecr.aws' is the
registry:
public.ecr.aws/bottlerocket/bottlerocket-sdk-x86_64:v0.50.0
--alpha-sdk-tag The tag to give the Docker image that this script produces.
-h, --help show this help text
EOF
}

usage_error() {
>&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 ;;
--tag)
shift; tag=$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 ${bottlerocket_dir} ]] || usage_error 'required: --sdk-version'

variant="${variant:=aws-k8s-1.27}"
sdk_name="${sdk_name:=bottlerocket-sdk}"
sdk_registry="${sdk_registry:=public.ecr.aws/bottlerocket}"
tag_repo="${tag:=twoliter.alpha/bottlerocket-sdk}"
sdk_repo="${sdk_registry}/${sdk_name}"

cd "${bottlerocket_dir}"

cargo make \
-e "BUILDSYS_VARIANT=${variant}" \
-e "BUILDSYS_ARCH=x86_64" \
build-variant

cargo make \
-e "BUILDSYS_VARIANT=${variant}" \
-e "BUILDSYS_ARCH=aarch64" \
build-variant



for target_arch in x86_64 aarch64
do
for host_arch in x86_64 arm64
do
sdk="${sdk_repo}-${target_arch}:${sdk_version}"
tag="${tag_repo}-${target_arch}:${sdk_version}-${host_arch}"
echo "creating image ${tag}"
docker build \
--tag "${tag}" \
--build-arg "SDK=${sdk}" \
--build-arg "TARGET_GOARCH=${host_arch}" \
--file "${script_dir}/alpha-sdk.dockerfile" \
"${bottlerocket_dir}"
done
done

# TODO - combine platforms into a multiarch image

0 comments on commit 2a54bb3

Please sign in to comment.