Skip to content

Commit

Permalink
Merge pull request #411 from cbgbt/twoliter-0.5.2-rc1
Browse files Browse the repository at this point in the history
Use `krane` to fetch the project's SDK
  • Loading branch information
cbgbt authored Dec 3, 2024
2 parents ac930e7 + fbf3bbb commit 37945a6
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 28 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

[unreleased]: /~https://github.com/bottlerocket-os/twoliter/compare/v0.5.1...HEAD
[unreleased]: /~https://github.com/bottlerocket-os/twoliter/compare/v0.5.2...HEAD

## [0.5.2] - 2024-12-03

### Changed

- Use `krane` to fetch the SDK during the build instead of `docker` ([#411])
- Enable verbose `krane` logs when the log level is DEBUG or TRACE ([#411])
- Update `ecr-login` to v0.9.0 ([#411])

[#411]: /~https://github.com/bottlerocket-os/twoliter/pull/411

[0.5.2]: /~https://github.com/bottlerocket-os/twoliter/compare/v0.5.1...v0.5.2

## [0.5.1] - 2024-11-11

Expand Down
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ targets = ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl"]

[workspace.metadata.cross.build]
pre-build = [
# install golang for krane-bundle
"apt update && apt --assume-yes install golang-1.22",
# install golang and patch for krane-bundle
"apt update && apt --assume-yes install golang-1.22 patch",
"update-alternatives --install /usr/bin/go go /usr/lib/go-1.22/bin/go 10",
# give the builder access to the go build and module caches
"mkdir /.cache && chmod a+rw /.cache",
Expand All @@ -61,7 +61,7 @@ pubsys-setup = { version = "0.1", path = "tools/pubsys-setup", artifact = [ "bin
testsys = { version = "0.1", path = "tools/testsys", artifact = [ "bin:testsys" ] }
testsys-config = { version = "0.1", path = "tools/testsys-config" }
testsys-model = { version = "0.0.14", git = "/~https://github.com/bottlerocket-os/bottlerocket-test-system", tag = "v0.0.14" }
twoliter = { version = "0.5.1", path = "twoliter", artifact = [ "bin:twoliter" ] }
twoliter = { version = "0.5.2-rc1", path = "twoliter", artifact = [ "bin:twoliter" ] }
unplug = { version = "0.1", path = "tools/unplug", artifact = [ "bin:unplug" ] }
update-metadata = { version = "0.1", path = "tools/update-metadata" }

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TOP := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))

BOTTLEROCKET_SDK_VERSION ?= v0.45.0
BOTTLEROCKET_SDK_VERSION ?= v0.47.0
BOTTLEROCKET_SDK_IMAGE ?= public.ecr.aws/bottlerocket/bottlerocket-sdk:$(BOTTLEROCKET_SDK_VERSION)

.PHONY: design
Expand Down
1 change: 1 addition & 0 deletions tools/krane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ tempfile.workspace = true
[build-dependencies]
flate2.workspace = true
tar.workspace = true
which.workspace = true
44 changes: 39 additions & 5 deletions tools/krane/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
use flate2::{read::GzDecoder, write::GzEncoder};
use std::env;
use std::fs::File;
use std::io::{self, prelude::*};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs};
use tar::Archive;

const CRANE_VERSION: &str = "0.20.1";

fn apply_source_patches(source_path: impl AsRef<Path>, patch_dir: impl AsRef<Path>) {
let source_path = source_path.as_ref();
let patch_dir = patch_dir.as_ref();

which::which("patch").expect("Must have the `patch` utility installed in PATH");

let mut patches = fs::read_dir(patch_dir)
.expect("Failed to read patch directory")
.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| path.extension().map(|ext| ext == "patch").unwrap_or(false))
.collect::<Vec<_>>();
patches.sort();

for patch in patches {
println!("Executing `patch -p1 -i '{}'`", patch.display());

let patch_status = Command::new("patch")
.current_dir(source_path)
.arg("-p1")
.arg("-i")
.arg(patch.as_os_str())
.status()
.expect("Failed to execute patch command");

if !patch_status.success() {
panic!("Failed to apply patch '{}'", patch.display());
}
}
}

fn main() {
let script_dir = env::current_dir().unwrap();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

println!("cargo::rerun-if-changed=../build-cache-fetch");
println!("cargo::rerun-if-changed=hashes/crane");
println!("cargo::rerun-if-changed=patches");

// Download and checksum-verify crane
env::set_current_dir(&out_dir).expect("Failed to set current directory");
Expand All @@ -32,6 +64,10 @@ fn main() {
.unpack(&crane_output_dir)
.expect("Failed to extract crane sources");

// Perform any local modifications
let crane_source_dir = crane_output_dir.join(format!("go-containerregistry-{CRANE_VERSION}"));
apply_source_patches(&crane_source_dir, script_dir.join("patches"));

// build krane
let build_output_loc = out_dir.join("krane");
Command::new("go")
Expand All @@ -40,9 +76,7 @@ fn main() {
.env("GOARCH", get_goarch())
.arg("-o")
.arg(&build_output_loc)
.current_dir(
crane_output_dir.join(format!("go-containerregistry-{CRANE_VERSION}/cmd/krane")),
)
.current_dir(crane_source_dir.join("cmd/krane"))
.status()
.expect("Failed to build crane");

Expand Down
Loading

0 comments on commit 37945a6

Please sign in to comment.