From 7bf1975362f45bacedc97b9250a8d6ba368f7901 Mon Sep 17 00:00:00 2001 From: ecpullen Date: Wed, 11 Oct 2023 18:53:55 +0000 Subject: [PATCH] twoliter: Create a test project --- tests/projects/project1/.dockerignore | 10 ++++ tests/projects/project1/.gitignore | 10 ++++ tests/projects/project1/Release.toml | 1 + tests/projects/project1/Twoliter.toml | 11 +++++ tests/projects/project1/packages/build.rs | 9 ++++ .../project1/packages/hello-agent/Cargo.toml | 21 ++++++++ .../packages/hello-agent/hello-agent.service | 9 ++++ .../packages/hello-agent/hello-agent.spec | 44 +++++++++++++++++ .../packages/hello-agent/hello-agent.timer | 19 +++++++ .../project1/packages/hello-go/Cargo.toml | 20 ++++++++ .../packages/hello-go/hello-go.service | 9 ++++ .../project1/packages/hello-go/hello-go.spec | 43 ++++++++++++++++ .../project1/packages/hello-go/hello-go.timer | 19 +++++++ tests/projects/project1/packages/packages.rs | 7 +++ tests/projects/project1/sources/Cargo.lock | 7 +++ tests/projects/project1/sources/Cargo.toml | 3 ++ tests/projects/project1/sources/clarify.toml | 1 + tests/projects/project1/sources/deny.toml | 43 ++++++++++++++++ .../project1/sources/hello-agent/Cargo.toml | 7 +++ .../project1/sources/hello-agent/build.rs | 1 + .../project1/sources/hello-agent/src/main.rs | 6 +++ .../sources/hello-go/cmd/hello-go/main.go | 11 +++++ .../projects/project1/sources/hello-go/go.mod | 3 ++ tests/projects/project1/variants/Cargo.lock | 27 ++++++++++ tests/projects/project1/variants/Cargo.toml | 10 ++++ tests/projects/project1/variants/build.rs | 9 ++++ .../project1/variants/hello-ootb/Cargo.toml | 49 +++++++++++++++++++ tests/projects/project1/variants/variants.rs | 7 +++ 28 files changed, 416 insertions(+) create mode 100644 tests/projects/project1/.dockerignore create mode 100644 tests/projects/project1/.gitignore create mode 100644 tests/projects/project1/Release.toml create mode 100644 tests/projects/project1/Twoliter.toml create mode 100644 tests/projects/project1/packages/build.rs create mode 100644 tests/projects/project1/packages/hello-agent/Cargo.toml create mode 100644 tests/projects/project1/packages/hello-agent/hello-agent.service create mode 100644 tests/projects/project1/packages/hello-agent/hello-agent.spec create mode 100644 tests/projects/project1/packages/hello-agent/hello-agent.timer create mode 100644 tests/projects/project1/packages/hello-go/Cargo.toml create mode 100644 tests/projects/project1/packages/hello-go/hello-go.service create mode 100644 tests/projects/project1/packages/hello-go/hello-go.spec create mode 100644 tests/projects/project1/packages/hello-go/hello-go.timer create mode 100644 tests/projects/project1/packages/packages.rs create mode 100644 tests/projects/project1/sources/Cargo.lock create mode 100644 tests/projects/project1/sources/Cargo.toml create mode 100644 tests/projects/project1/sources/clarify.toml create mode 100644 tests/projects/project1/sources/deny.toml create mode 100644 tests/projects/project1/sources/hello-agent/Cargo.toml create mode 100644 tests/projects/project1/sources/hello-agent/build.rs create mode 100644 tests/projects/project1/sources/hello-agent/src/main.rs create mode 100644 tests/projects/project1/sources/hello-go/cmd/hello-go/main.go create mode 100644 tests/projects/project1/sources/hello-go/go.mod create mode 100644 tests/projects/project1/variants/Cargo.lock create mode 100644 tests/projects/project1/variants/Cargo.toml create mode 100644 tests/projects/project1/variants/build.rs create mode 100644 tests/projects/project1/variants/hello-ootb/Cargo.toml create mode 100644 tests/projects/project1/variants/variants.rs diff --git a/tests/projects/project1/.dockerignore b/tests/projects/project1/.dockerignore new file mode 100644 index 000000000..b5c2394a0 --- /dev/null +++ b/tests/projects/project1/.dockerignore @@ -0,0 +1,10 @@ +/.git +/.gomodcache +/build/* +!/build/rpms/ +/build/rpms/* +!/build/rpms/*.rpm +/build/rpms/*-debuginfo-*.rpm +/build/rpms/*-debugsource-*.rpm +**/target/* +/sbkeys diff --git a/tests/projects/project1/.gitignore b/tests/projects/project1/.gitignore new file mode 100644 index 000000000..41c75f0c2 --- /dev/null +++ b/tests/projects/project1/.gitignore @@ -0,0 +1,10 @@ +/build/ +**/target/ +/.cargo/ +/.gomodcache/ +/keys/ +/roles/ +/sbkeys/ +Test.toml +testsys.kubeconfig +Infra.toml diff --git a/tests/projects/project1/Release.toml b/tests/projects/project1/Release.toml new file mode 100644 index 000000000..5820a7290 --- /dev/null +++ b/tests/projects/project1/Release.toml @@ -0,0 +1 @@ +version = "0.0.1" diff --git a/tests/projects/project1/Twoliter.toml b/tests/projects/project1/Twoliter.toml new file mode 100644 index 000000000..93b341d68 --- /dev/null +++ b/tests/projects/project1/Twoliter.toml @@ -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" diff --git a/tests/projects/project1/packages/build.rs b/tests/projects/project1/packages/build.rs new file mode 100644 index 000000000..cad8999af --- /dev/null +++ b/tests/projects/project1/packages/build.rs @@ -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(()) +} diff --git a/tests/projects/project1/packages/hello-agent/Cargo.toml b/tests/projects/project1/packages/hello-agent/Cargo.toml new file mode 100644 index 000000000..5f31ebf14 --- /dev/null +++ b/tests/projects/project1/packages/hello-agent/Cargo.toml @@ -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 diff --git a/tests/projects/project1/packages/hello-agent/hello-agent.service b/tests/projects/project1/packages/hello-agent/hello-agent.service new file mode 100644 index 000000000..0157859b6 --- /dev/null +++ b/tests/projects/project1/packages/hello-agent/hello-agent.service @@ -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 diff --git a/tests/projects/project1/packages/hello-agent/hello-agent.spec b/tests/projects/project1/packages/hello-agent/hello-agent.spec new file mode 100644 index 000000000..da93bc9c7 --- /dev/null +++ b/tests/projects/project1/packages/hello-agent/hello-agent.spec @@ -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 + +%description +%{summary}. + +%prep +%setup -T -c +%cargo_prep + +%build +mkdir bin + +%cargo_build_static --manifest-path %{_builddir}/sources/Cargo.toml \ + -p hello-agent + +%install +install -d %{buildroot}%{_cross_bindir} +install -p -m 0755 ${HOME}/.cache/.static/%{__cargo_target_static}/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 diff --git a/tests/projects/project1/packages/hello-agent/hello-agent.timer b/tests/projects/project1/packages/hello-agent/hello-agent.timer new file mode 100644 index 000000000..b25efb68d --- /dev/null +++ b/tests/projects/project1/packages/hello-agent/hello-agent.timer @@ -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 diff --git a/tests/projects/project1/packages/hello-go/Cargo.toml b/tests/projects/project1/packages/hello-go/Cargo.toml new file mode 100644 index 000000000..56d5d3230 --- /dev/null +++ b/tests/projects/project1/packages/hello-go/Cargo.toml @@ -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 diff --git a/tests/projects/project1/packages/hello-go/hello-go.service b/tests/projects/project1/packages/hello-go/hello-go.service new file mode 100644 index 000000000..98eb700c8 --- /dev/null +++ b/tests/projects/project1/packages/hello-go/hello-go.service @@ -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 diff --git a/tests/projects/project1/packages/hello-go/hello-go.spec b/tests/projects/project1/packages/hello-go/hello-go.spec new file mode 100644 index 000000000..99ada0ac1 --- /dev/null +++ b/tests/projects/project1/packages/hello-go/hello-go.spec @@ -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 diff --git a/tests/projects/project1/packages/hello-go/hello-go.timer b/tests/projects/project1/packages/hello-go/hello-go.timer new file mode 100644 index 000000000..97f4cd95a --- /dev/null +++ b/tests/projects/project1/packages/hello-go/hello-go.timer @@ -0,0 +1,19 @@ +[Unit] +Description=Scheduled Hello-Go Pings + +[Timer] +# Don't run missed executions +Persistent=false +# Run 120 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-go.service + +[Install] +WantedBy=timers.target diff --git a/tests/projects/project1/packages/packages.rs b/tests/projects/project1/packages/packages.rs new file mode 100644 index 000000000..36be246d5 --- /dev/null +++ b/tests/projects/project1/packages/packages.rs @@ -0,0 +1,7 @@ +/*! + +This is an intentionally empty file that all of the package `Cargo.toml` files can point to as their +`lib.rs`. The build system uses `build.rs` to invoke `buildsys` but Cargo needs something to compile +so we give it an empty `lib.rs` file. + +!*/ diff --git a/tests/projects/project1/sources/Cargo.lock b/tests/projects/project1/sources/Cargo.lock new file mode 100644 index 000000000..260f47aa3 --- /dev/null +++ b/tests/projects/project1/sources/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello-agent" +version = "0.1.0" diff --git a/tests/projects/project1/sources/Cargo.toml b/tests/projects/project1/sources/Cargo.toml new file mode 100644 index 000000000..56523c484 --- /dev/null +++ b/tests/projects/project1/sources/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "1" +members = ["hello-agent"] diff --git a/tests/projects/project1/sources/clarify.toml b/tests/projects/project1/sources/clarify.toml new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/projects/project1/sources/clarify.toml @@ -0,0 +1 @@ + diff --git a/tests/projects/project1/sources/deny.toml b/tests/projects/project1/sources/deny.toml new file mode 100644 index 000000000..d25731065 --- /dev/null +++ b/tests/projects/project1/sources/deny.toml @@ -0,0 +1,43 @@ +[licenses] +unlicensed = "deny" + +# Deny licenses unless they are specifically listed here +copyleft = "deny" +allow-osi-fsf-free = "neither" +default = "deny" + +# We want really high confidence when inferring licenses from text +confidence-threshold = 0.93 + +# Commented license types are allowed but not currently used +allow = [ + "Apache-2.0", + # "BSD-2-Clause", + # "BSD-3-Clause", + # "BSL-1.0", + # "CC0-1.0", + # "ISC", + "MIT", + # "OpenSSL", + # "Unlicense", + # "Zlib", +] + +exceptions = [] + + +[bans] +# Deny multiple versions or wildcard dependencies. +multiple-versions = "deny" +wildcards = "deny" + +deny = [{ name = "structopt" }, { name = "clap", wrappers = ["cargo-readme"] }] + +skip = [] + +skip-tree = [] + +[sources] +# Deny crates from unknown registries or git repositories. +unknown-registry = "deny" +unknown-git = "deny" diff --git a/tests/projects/project1/sources/hello-agent/Cargo.toml b/tests/projects/project1/sources/hello-agent/Cargo.toml new file mode 100644 index 000000000..b8551d9ee --- /dev/null +++ b/tests/projects/project1/sources/hello-agent/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hello-agent" +version = "0.1.0" +authors = ["Ethan Pullen "] +license = "Apache-2.0 OR MIT" +edition = "2021" +publish = false diff --git a/tests/projects/project1/sources/hello-agent/build.rs b/tests/projects/project1/sources/hello-agent/build.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/tests/projects/project1/sources/hello-agent/build.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/projects/project1/sources/hello-agent/src/main.rs b/tests/projects/project1/sources/hello-agent/src/main.rs new file mode 100644 index 000000000..14e06693c --- /dev/null +++ b/tests/projects/project1/sources/hello-agent/src/main.rs @@ -0,0 +1,6 @@ +use std::process; + +fn main() -> ! { + println!("Hello from hello-agent"); + process::exit(0) +} diff --git a/tests/projects/project1/sources/hello-go/cmd/hello-go/main.go b/tests/projects/project1/sources/hello-go/cmd/hello-go/main.go new file mode 100644 index 000000000..0987f2ee8 --- /dev/null +++ b/tests/projects/project1/sources/hello-go/cmd/hello-go/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + fmt.Println("Hello Go") + os.Exit(0) +} diff --git a/tests/projects/project1/sources/hello-go/go.mod b/tests/projects/project1/sources/hello-go/go.mod new file mode 100644 index 000000000..5f66e7b7e --- /dev/null +++ b/tests/projects/project1/sources/hello-go/go.mod @@ -0,0 +1,3 @@ +module hello-go + +go 1.19 diff --git a/tests/projects/project1/variants/Cargo.lock b/tests/projects/project1/variants/Cargo.lock new file mode 100644 index 000000000..9291e5672 --- /dev/null +++ b/tests/projects/project1/variants/Cargo.lock @@ -0,0 +1,27 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aws-test-1" +version = "0.1.0" +dependencies = [ + "hello-agent", + "hello-go", +] + +[[package]] +name = "hello-agent" +version = "0.1.0" + +[[package]] +name = "hello-go" +version = "0.1.0" + +[[package]] +name = "hello-ootb" +version = "0.1.0" +dependencies = [ + "hello-agent", + "hello-go", +] diff --git a/tests/projects/project1/variants/Cargo.toml b/tests/projects/project1/variants/Cargo.toml new file mode 100644 index 000000000..e3366baab --- /dev/null +++ b/tests/projects/project1/variants/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] +resolver = "1" +members = ["hello-ootb"] + +[profile.dev] +debug = false +opt-level = 'z' + +[profile.dev.build-override] +opt-level = 'z' diff --git a/tests/projects/project1/variants/build.rs b/tests/projects/project1/variants/build.rs new file mode 100644 index 000000000..d6a90e4df --- /dev/null +++ b/tests/projects/project1/variants/build.rs @@ -0,0 +1,9 @@ +use std::process::{exit, Command}; + +fn main() -> Result<(), std::io::Error> { + let ret = Command::new("buildsys").arg("build-variant").status()?; + if !ret.success() { + exit(1); + } + Ok(()) +} diff --git a/tests/projects/project1/variants/hello-ootb/Cargo.toml b/tests/projects/project1/variants/hello-ootb/Cargo.toml new file mode 100644 index 000000000..37b386388 --- /dev/null +++ b/tests/projects/project1/variants/hello-ootb/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "hello-ootb" +version = "0.1.0" +edition = "2021" +publish = false +build = "../build.rs" +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[package.metadata.build-variant.image-features] +grub-set-private-var = true +unified-cgroup-hierarchy = true +uefi-secure-boot = true +xfs-data-partition = true +systemd-networkd = true + +[package.metadata.build-variant] +included-packages = [ + # core + "release", + "kernel-6.1", + # docker + "docker-cli", + "docker-engine", + "docker-init", + "docker-proxy", + # tools + "login", + "iputils", + "strace", + "chrony-tools", + #other + "hello-agent", + "hello-go", +] +kernel-parameters = [ + "console=tty0", + "console=ttyS0,115200n8", + "net.ifnames=0", + "netdog.default-interface=eth0:dhcp4,dhcp6?", + "quiet", +] + +[lib] +path = "../variants.rs" + +[build-dependencies] +hello-agent = { path = "../../packages/hello-agent" } +hello-go = { path = "../../packages/hello-go" } diff --git a/tests/projects/project1/variants/variants.rs b/tests/projects/project1/variants/variants.rs new file mode 100644 index 000000000..6bedb60e6 --- /dev/null +++ b/tests/projects/project1/variants/variants.rs @@ -0,0 +1,7 @@ +/*! + +This is an intentionally empty file that all of the variant `Cargo.toml` files can point to as their +`lib.rs`. The build system uses `build.rs` to invoke `buildsys` but Cargo needs something to compile +so we give it an empty `lib.rs` file. + +!*/