From a74753da49f700f570c52a484d356cb3d58d58e8 Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Tue, 25 Mar 2025 21:55:58 +0100 Subject: [PATCH 1/5] Adds a simple makefile shell wrapper --- scripts/make_package.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/make_package.sh diff --git a/scripts/make_package.sh b/scripts/make_package.sh new file mode 100644 index 0000000..c5c6890 --- /dev/null +++ b/scripts/make_package.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Note env variables: DESTDIR, BUILDROOT, GOCACHE + +make_package() { + local package="$1" + local version="$2" + local git_url="$3" + local provided_binary="$4" + local artifact_path="$5" + + local dest_path="$DESTDIR/usr/bin/$package" + mkdir -p "$DESTDIR/usr/bin" + + # If binary path is provided, use it directly + if [ -n "$provided_binary" ]; then + echo "Using provided binary for $package" + cp "$provided_binary" "$dest_path" + return + fi + + # Clone the repository + local build_dir="$BUILDROOT/build/$package" + git clone --depth 1 --branch "$version" "$git_url" "$build_dir" + + # Build inside mkosi chroot + mkosi-chroot bash -c "cd '/build/$package' && make build" + + cp "$build_dir/$artifact_path" "$dest_path" +} From 3bd8bbe0c3824515cee336ae4709f0322d3f761c Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Mon, 31 Mar 2025 13:03:21 +0200 Subject: [PATCH 2/5] Updates git build tools and adds a sample tdx dummy dcap image --- mkosi.conf => buildernet.conf | 0 readme.md | 9 +++++++- scripts/git_package.sh | 38 ++++++++++++++++++++++++++++++++ scripts/make_package.sh | 30 ------------------------- tdx-dummy.conf | 4 ++++ tdx-dummy/dummy-tdx-dcap.service | 17 ++++++++++++++ tdx-dummy/mkosi.build | 6 +++++ tdx-dummy/mkosi.postinst | 8 +++++++ tdx-dummy/tdx-dummy.conf | 8 +++++++ 9 files changed, 89 insertions(+), 31 deletions(-) rename mkosi.conf => buildernet.conf (100%) create mode 100644 scripts/git_package.sh delete mode 100644 scripts/make_package.sh create mode 100644 tdx-dummy.conf create mode 100644 tdx-dummy/dummy-tdx-dcap.service create mode 100755 tdx-dummy/mkosi.build create mode 100755 tdx-dummy/mkosi.postinst create mode 100644 tdx-dummy/tdx-dummy.conf diff --git a/mkosi.conf b/buildernet.conf similarity index 100% rename from mkosi.conf rename to buildernet.conf diff --git a/readme.md b/readme.md index fa1017f..7330046 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,14 @@ Usage ```shell nix develop -c $SHELL -mkosi --force +mkosi --force -I buildernet.conf +``` + +For Ubuntu: +```shell +source ~/.nix-profile/etc/profile.d/nix.sh +nix --extra-experimental-features nix-command develop --extra-experimental-features flakes -c $SHELL +mkosi --force -I buildernet.conf ``` > Note: Make sure the above command is not run with sudo, as this will clear necessary environment variables set by the nix shell diff --git a/scripts/git_package.sh b/scripts/git_package.sh new file mode 100644 index 0000000..0ead37a --- /dev/null +++ b/scripts/git_package.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Note env variables: DESTDIR, BUILDROOT, GOCACHE + +make_package() { + local package="$1" + local version="$2" + local git_url="$3" + local build_cmd="$4" + # All remaining arguments are artifact mappings in src:dest format + + mkdir -p "$DESTDIR/usr/bin" + + # Clone the repository + local build_dir="$BUILDROOT/build/$package" + git clone --depth 1 --branch "$version" "$git_url" "$build_dir" + + # Build inside mkosi chroot with custom build command + mkosi-chroot bash -c "cd '/build/$package' && $build_cmd" + + # Process each artifact mapping + for artifact_map in "${@:5}"; do + # Split the mapping into source and destination + local src=$(echo "$artifact_map" | cut -d':' -f1) + local dest=$(echo "$artifact_map" | cut -d':' -f2) + + # Create destination directory if needed + mkdir -p "$(dirname "$DESTDIR$dest")" + + # Copy the artifact + cp "$build_dir/$src" "$DESTDIR$dest" + done +} + +# Example usage: +# make_package "myapp" "v1.0.0" "https://github.com/user/myapp.git" "make build" \ +# "bin/myapp:/usr/bin/myapp" \ +# "config/myapp.conf:/etc/myapp/myapp.conf" diff --git a/scripts/make_package.sh b/scripts/make_package.sh deleted file mode 100644 index c5c6890..0000000 --- a/scripts/make_package.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# -# Note env variables: DESTDIR, BUILDROOT, GOCACHE - -make_package() { - local package="$1" - local version="$2" - local git_url="$3" - local provided_binary="$4" - local artifact_path="$5" - - local dest_path="$DESTDIR/usr/bin/$package" - mkdir -p "$DESTDIR/usr/bin" - - # If binary path is provided, use it directly - if [ -n "$provided_binary" ]; then - echo "Using provided binary for $package" - cp "$provided_binary" "$dest_path" - return - fi - - # Clone the repository - local build_dir="$BUILDROOT/build/$package" - git clone --depth 1 --branch "$version" "$git_url" "$build_dir" - - # Build inside mkosi chroot - mkosi-chroot bash -c "cd '/build/$package' && make build" - - cp "$build_dir/$artifact_path" "$dest_path" -} diff --git a/tdx-dummy.conf b/tdx-dummy.conf new file mode 100644 index 0000000..462dc4b --- /dev/null +++ b/tdx-dummy.conf @@ -0,0 +1,4 @@ +[Config] +Include=base/base.conf +Include=tdx-dummy/tdx-dummy.conf +Include=devtools/devtools.conf diff --git a/tdx-dummy/dummy-tdx-dcap.service b/tdx-dummy/dummy-tdx-dcap.service new file mode 100644 index 0000000..f3feae4 --- /dev/null +++ b/tdx-dummy/dummy-tdx-dcap.service @@ -0,0 +1,17 @@ +[Unit] +Description=Dummy TDX DCAP server +After=network-setup.service +Wants=network-setup.service + +[Service] +Type=exec +User=root +Group=root +ExecStart=/usr/bin/dummy-tdx-dcap --listen-addr 0.0.0.0:8080 +Restart=on-failure +RestartSec=10 +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=minimal.target diff --git a/tdx-dummy/mkosi.build b/tdx-dummy/mkosi.build new file mode 100755 index 0000000..45a2ccd --- /dev/null +++ b/tdx-dummy/mkosi.build @@ -0,0 +1,6 @@ +#!/bin/bash +set -euxo pipefail + +source scripts/git_package.sh + +git_package "dummy-tdx-dcap" "v0.0.1" "https://github.com/Ruteri/dummy-tdx-dcap" 'go build -trimpath -ldflags "-s -w -buildid= -X github.com/flashbots/go-template/common.Version=v0.0.1" -v -o ./build/httpserver cmd/httpserver/main.go' "build/httpserver:/usr/bin/dummy-tdx-dcap" diff --git a/tdx-dummy/mkosi.postinst b/tdx-dummy/mkosi.postinst new file mode 100755 index 0000000..68965ee --- /dev/null +++ b/tdx-dummy/mkosi.postinst @@ -0,0 +1,8 @@ +#!/bin/bash +set -euxo pipefail + +# Install systemd service units +SERVICE_DIR="$BUILDROOT/etc/systemd/system" +mkdir -p "$SERVICE_DIR" + +install -m 644 "tdx-dummy/dummy-tdx-dcap.service" "$SERVICE_DIR/" diff --git a/tdx-dummy/tdx-dummy.conf b/tdx-dummy/tdx-dummy.conf new file mode 100644 index 0000000..4f885d4 --- /dev/null +++ b/tdx-dummy/tdx-dummy.conf @@ -0,0 +1,8 @@ +[Content] +WithNetwork=true +Packages=etcd-server +BuildScripts=tdx-dummy/mkosi.build +BuildPackages=ca-certificates + golang-go + git +PostInstallationScripts=tdx-dummy/mkosi.postinst From af919c280ad795425f51f1f02d5b660d209adc79 Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Mon, 31 Mar 2025 13:05:36 +0200 Subject: [PATCH 3/5] Renames git build script --- scripts/{git_package.sh => make_git_package.sh} | 4 ++-- tdx-dummy/mkosi.build | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename scripts/{git_package.sh => make_git_package.sh} (90%) diff --git a/scripts/git_package.sh b/scripts/make_git_package.sh similarity index 90% rename from scripts/git_package.sh rename to scripts/make_git_package.sh index 0ead37a..f81afe8 100644 --- a/scripts/git_package.sh +++ b/scripts/make_git_package.sh @@ -2,7 +2,7 @@ # # Note env variables: DESTDIR, BUILDROOT, GOCACHE -make_package() { +make_git_package() { local package="$1" local version="$2" local git_url="$3" @@ -33,6 +33,6 @@ make_package() { } # Example usage: -# make_package "myapp" "v1.0.0" "https://github.com/user/myapp.git" "make build" \ +# make_git_package "myapp" "v1.0.0" "https://github.com/user/myapp.git" "make build" \ # "bin/myapp:/usr/bin/myapp" \ # "config/myapp.conf:/etc/myapp/myapp.conf" diff --git a/tdx-dummy/mkosi.build b/tdx-dummy/mkosi.build index 45a2ccd..22ac161 100755 --- a/tdx-dummy/mkosi.build +++ b/tdx-dummy/mkosi.build @@ -1,6 +1,6 @@ #!/bin/bash set -euxo pipefail -source scripts/git_package.sh +source scripts/make_git_package.sh -git_package "dummy-tdx-dcap" "v0.0.1" "https://github.com/Ruteri/dummy-tdx-dcap" 'go build -trimpath -ldflags "-s -w -buildid= -X github.com/flashbots/go-template/common.Version=v0.0.1" -v -o ./build/httpserver cmd/httpserver/main.go' "build/httpserver:/usr/bin/dummy-tdx-dcap" +make_git_package "dummy-tdx-dcap" "v0.0.1" "https://github.com/Ruteri/dummy-tdx-dcap" 'go build -trimpath -ldflags "-s -w -buildid= -X github.com/flashbots/go-template/common.Version=v0.0.1" -v -o ./build/httpserver cmd/httpserver/main.go' "build/httpserver:/usr/bin/dummy-tdx-dcap" From 6432a6aa43a1ebeaac5dd680456840230142a23e Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:08:12 +0200 Subject: [PATCH 4/5] Removes etcd --- tdx-dummy/tdx-dummy.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/tdx-dummy/tdx-dummy.conf b/tdx-dummy/tdx-dummy.conf index 4f885d4..4bce4aa 100644 --- a/tdx-dummy/tdx-dummy.conf +++ b/tdx-dummy/tdx-dummy.conf @@ -1,6 +1,5 @@ [Content] WithNetwork=true -Packages=etcd-server BuildScripts=tdx-dummy/mkosi.build BuildPackages=ca-certificates golang-go From 899a169f9301fd99b0e6b562c35f4ac674baa404 Mon Sep 17 00:00:00 2001 From: Mateusz Morusiewicz <11313015+Ruteri@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:14:01 +0200 Subject: [PATCH 5/5] update readme --- readme.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/readme.md b/readme.md index 7330046..f9327fc 100644 --- a/readme.md +++ b/readme.md @@ -21,13 +21,6 @@ nix develop -c $SHELL mkosi --force -I buildernet.conf ``` -For Ubuntu: -```shell -source ~/.nix-profile/etc/profile.d/nix.sh -nix --extra-experimental-features nix-command develop --extra-experimental-features flakes -c $SHELL -mkosi --force -I buildernet.conf -``` - > Note: Make sure the above command is not run with sudo, as this will clear necessary environment variables set by the nix shell Create a qcow2 image to store persistent files: