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..f9327fc 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ Usage ```shell nix develop -c $SHELL -mkosi --force +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/make_git_package.sh b/scripts/make_git_package.sh new file mode 100644 index 0000000..f81afe8 --- /dev/null +++ b/scripts/make_git_package.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Note env variables: DESTDIR, BUILDROOT, GOCACHE + +make_git_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_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.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..22ac161 --- /dev/null +++ b/tdx-dummy/mkosi.build @@ -0,0 +1,6 @@ +#!/bin/bash +set -euxo pipefail + +source scripts/make_git_package.sh + +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" 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..4bce4aa --- /dev/null +++ b/tdx-dummy/tdx-dummy.conf @@ -0,0 +1,7 @@ +[Content] +WithNetwork=true +BuildScripts=tdx-dummy/mkosi.build +BuildPackages=ca-certificates + golang-go + git +PostInstallationScripts=tdx-dummy/mkosi.postinst