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

Twoliter build variant alpha #96

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target/
**/target/
.ignore/
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.
10 changes: 10 additions & 0 deletions local/alpha-sdk.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG SDK
FROM $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
131 changes: 131 additions & 0 deletions local/alpha-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/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.
--arch The target architecture that we will build Bottlerocket for.
Defaults to this host's architecture.
--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 ;;
--arch)
shift; arch=$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-dev}"
arch="${arch:=$(uname -m)}"
sdk_name="${sdk_name:=bottlerocket}"
sdk_registry="${sdk_registry:=public.ecr.aws/bottlerocket}"
tag="${tag:=twoliter.alpha/bottlerocket-sdk}"

cd "${bottlerocket_dir}"

cargo make \
-e "BUILDSYS_VARIANT=${variant}" \
-e "BUILDSYS_ARCH=${arch}" \
-e "BUILDSYS_SDK_NAME=${sdk_name}" \
-e "BUILDSYS_SDK_VERSION=${sdk_version}" \
-e "BUILDSYS_SDK_REGISTRY=${sdk_registry}" \
build-variant

sdk="${sdk_registry}/${sdk_name}-sdk-${arch}:${sdk_version}"

docker build \
--tag "${tag}" \
--build-arg "SDK=${sdk}" \
--file "${script_dir}/alpha-sdk.dockerfile" \
"${bottlerocket_dir}"
10 changes: 10 additions & 0 deletions tests/projects/project1/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.git
/.gomodcache
/build/*
!/build/rpms/
/build/rpms/*
!/build/rpms/*.rpm
/build/rpms/*-debuginfo-*.rpm
/build/rpms/*-debugsource-*.rpm
**/target/*
/sbkeys
9 changes: 9 additions & 0 deletions tests/projects/project1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/build/
**/target/
/.cargo/
/.gomodcache/
/keys/
/roles/
/sbkeys/
Test.toml
testsys.kubeconfig
15 changes: 15 additions & 0 deletions tests/projects/project1/Infra.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[repo.default]
metadata_base_url = "https://d2evc20wfryw7s.cloudfront.net/"
targets_url = "https://d2evc20wfryw7s.cloudfront.net/targets/"

[aws]
regions = ["us-west-2"]




# [repo.default]
# root_role_url = "https://cache.bottlerocket.aws/root.json"
# root_role_sha512 = "b81af4d8eb86743539fbc4709d33ada7b118d9f929f0c2f6c04e1d41f46241ed80423666d169079d736ab79965b4dd25a5a6db5f01578b397496d49ce11a3aa2"
# metadata_base_url = "https://updates.bottlerocket.aws/2020-07-07/"
# targets_url = "https://updates.bottlerocket.aws/targets/"
1 change: 1 addition & 0 deletions tests/projects/project1/Release.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.0.1"
11 changes: 11 additions & 0 deletions tests/projects/project1/Twoliter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema-version = 1

[sdk]
registry = "twoliter.alpha"
name = "bottlerocket-sdk"
version = "latest"

[toolchain]
registry = "public.ecr.aws/bottlerocket"
name = "bottlerocket-toolchain"
version = "v0.34.1"
9 changes: 9 additions & 0 deletions tests/projects/project1/packages/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::process::{exit, Command};

fn main() -> Result<(), std::io::Error> {
let ret = Command::new("buildsys").arg("build-package").status()?;
if !ret.success() {
exit(1);
}
Ok(())
}
21 changes: 21 additions & 0 deletions tests/projects/project1/packages/hello-agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "hello-agent"
version = "0.1.0"
edition = "2021"
publish = false
build = "../build.rs"

[package.metadata.build-package]
variant-sensitive = false
source-groups = ["hello-agent"]

[lib]
path = "../packages.rs"

# RPM BuildRequires
[build-dependencies]
# None

# RPM Requires
[dependencies]
# None
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Send a hello-agent Ping

[Service]
Type=oneshot
RemainAfterExit=false
StandardError=journal+console
ExecStart=/usr/bin/hello-agent
TimeoutStartSec=30s
44 changes: 44 additions & 0 deletions tests/projects/project1/packages/hello-agent/hello-agent.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
%global _cross_first_party 1
%undefine _debugsource_packages

Name: %{_cross_os}hello-agent
Version: 0.0
Release: 0%{?dist}
Summary: Hello-agent
License: Apache-2.0 OR MIT
URL: https://github.com/bottlerocket-os/bottlerocket

# sources < 100: misc

# 1xx sources: systemd units
Source103: hello-agent.service
Source104: hello-agent.timer

BuildRequires: %{_cross_os}glibc-devel
Requires: %{_cross_os}hello-agent

%description
%{summary}.

%prep
%setup -T -c
%cargo_prep

%build
mkdir bin

%cargo_build --manifest-path %{_builddir}/sources/Cargo.toml \
-p hello-agent

install -d %{buildroot}%{_cross_bindir}
install -p -m 0755 ${HOME}/.cache/%{__cargo_target}/release/hello-agent %{buildroot}%{_cross_bindir}

install -d %{buildroot}%{_cross_unitdir}
install -p -m 0644 \
%{S:103} %{S:104} \
%{buildroot}%{_cross_unitdir}

%files
%{_cross_bindir}/hello-agent
%{_cross_unitdir}/hello-agent.service
%{_cross_unitdir}/hello-agent.timer
19 changes: 19 additions & 0 deletions tests/projects/project1/packages/hello-agent/hello-agent.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=Scheduled Hello-Agent Pings

[Timer]
# Don't run missed executions
Persistent=false
# Run 5 seconds after startup
OnStartupSec=5
# Run every 5 sec thereafter
OnUnitActiveSec=5
# Don't fire at exactly the same second across machines started together.
RandomizedDelaySec=1
# We don't want to extend the startup report too long after the requested time.
AccuracySec=1
# File describing job to execute
Unit=hello-agent.service

[Install]
WantedBy=timers.target
20 changes: 20 additions & 0 deletions tests/projects/project1/packages/hello-go/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "hello-go"
version = "0.1.0"
edition = "2021"
publish = false
build = "../build.rs"

[package.metadata.build-package]
source-groups = ["hello-go"]

[lib]
path = "../packages.rs"

# RPM BuildRequires
[build-dependencies]
# None

# RPM Requires
[dependencies]
# None
9 changes: 9 additions & 0 deletions tests/projects/project1/packages/hello-go/hello-go.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Send a hello-go Ping

[Service]
Type=oneshot
RemainAfterExit=false
StandardError=journal+console
ExecStart=/usr/bin/hello-go
TimeoutStartSec=30s
43 changes: 43 additions & 0 deletions tests/projects/project1/packages/hello-go/hello-go.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%global _cross_first_party 1
%undefine _debugsource_packages

Name: %{_cross_os}hello-go
Version: 0.0
Release: 0%{?dist}
Summary: hello-go
License: Apache-2.0 OR MIT
URL: https://github.com/bottlerocket-os/bottlerocket

# sources < 100: misc

# 1xx sources: systemd units
Source103: hello-go.service
Source104: hello-go.timer

BuildRequires: %{_cross_os}glibc-devel
Requires: %{_cross_os}hello-go

%description
%{summary}.

%prep
%setup -T -c
cp -r %{_builddir}/sources/hello-go/* .

%build
%set_cross_go_flags
go build -buildmode=pie -ldflags="${GOLDFLAGS}" -o hello-go ./cmd/hello-go

%install
install -d %{buildroot}%{_cross_bindir}
install -p -m 0755 hello-go %{buildroot}%{_cross_bindir}

install -d %{buildroot}%{_cross_unitdir}
install -p -m 0644 \
%{S:103} %{S:104} \
%{buildroot}%{_cross_unitdir}

%files
%{_cross_bindir}/hello-go
%{_cross_unitdir}/hello-go.service
%{_cross_unitdir}/hello-go.timer
Loading