diff --git a/.dockerignore b/.dockerignore index 1d17dae..b9cb747 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ .venv +result +*.Dockerfile \ No newline at end of file diff --git a/.github/workflows/nix-auto.yml b/.github/workflows/nix-auto.yml index 59b5e21..73a2a7e 100644 --- a/.github/workflows/nix-auto.yml +++ b/.github/workflows/nix-auto.yml @@ -1,4 +1,4 @@ -name: Nix Flake actions +name: CI tasks from Nix config on: pull_request: diff --git a/README.md b/README.md index ec9d63e..0f5b686 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ See the [Development](#development) section for how to get the test agent runnin ## Installation +The test agent can be installed using nix: + + nix profile install github:datadog/dd-apm-test-agent#ddapm-test-agent + # nix profile upgrade ddapm-test-agent # to upgrade + The test agent can be installed from PyPI: pip install ddapm-test-agent diff --git a/build-on-darwin.Dockerfile b/build-on-darwin.Dockerfile new file mode 100644 index 0000000..7ca734b --- /dev/null +++ b/build-on-darwin.Dockerfile @@ -0,0 +1,28 @@ +# simple hack to build the same image on OSX. otherwise the Nix docker build will by default not cross compile to linux +# in CI or on linux systems - use `nix build .#image | docker load -i result` instead + +FROM nixos/nix AS builder +RUN set -xe; \ + echo 'sandbox = true' >> /etc/nix/nix.conf; \ + echo 'filter-syscalls = false' >> /etc/nix/nix.conf; \ + echo 'max-jobs = auto' >> /etc/nix/nix.conf; \ + echo 'experimental-features = nix-command flakes' >> /etc/nix/nix.conf + +WORKDIR /build +COPY flake.lock *.nix . + +RUN nix flake show + + +COPY . . + +RUN nix build .#image +RUN mkdir -p /output; mkdir -p /img +# very simplistic way to unpack image - relies only on there being a single layer +RUN tar -xf result --strip-components=1 -C /img +RUN tar -xf /img/layer.tar -C /output + +FROM scratch AS final +COPY --from=builder /output/ / + +ENTRYPOINT ["/bin/ddapm-test-agent"] \ No newline at end of file diff --git a/flake.lock b/flake.lock index 5b735d4..b5c181a 100644 --- a/flake.lock +++ b/flake.lock @@ -18,24 +18,6 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nix-github-actions": { "inputs": { "nixpkgs": [ @@ -56,41 +38,7 @@ "type": "github" } }, - "nix2containerPkg": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1730479402, - "narHash": "sha256-79NLeNjpCa4mSasmFsE3QA6obURezF0TUO5Pm+1daog=", - "owner": "nlewo", - "repo": "nix2container", - "rev": "5fb215a1564baa74ce04ad7f903d94ad6617e17a", - "type": "github" - }, - "original": { - "owner": "nlewo", - "repo": "nix2container", - "type": "github" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1712920918, - "narHash": "sha256-1yxFvUcJfUphK9V91KufIQom7gCsztza0H4Rz2VCWUU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "92323443a56f4e9fc4e4b712e3119f66d0969297", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 1717179513, "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=", @@ -106,7 +54,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_2": { "locked": { "lastModified": 1733097829, "narHash": "sha256-9hbb1rqGelllb4kVUCZ307G2k3/UhmA8PPGBoyuWaSw=", @@ -126,8 +74,7 @@ "inputs": { "flake-utils": "flake-utils", "nix-github-actions": "nix-github-actions", - "nix2containerPkg": "nix2containerPkg", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs", "treefmt-nix": "treefmt-nix" } }, @@ -146,24 +93,9 @@ "type": "github" } }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "treefmt-nix": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1735135567, diff --git a/flake.nix b/flake.nix index 71e76e1..6ad9550 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,6 @@ flake-utils.url = "github:numtide/flake-utils"; - nix2containerPkg.url = "github:nlewo/nix2container"; treefmt-nix.url = "github:numtide/treefmt-nix"; nix-github-actions.url = "github:nix-community/nix-github-actions/"; @@ -20,7 +19,6 @@ nixpkgs, flake-utils, treefmt-nix, - nix2containerPkg, nix-github-actions, }: (flake-utils.lib.eachDefaultSystem ( @@ -32,8 +30,6 @@ treefmt = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; - nix2container = nix2containerPkg.packages.${system}.nix2container; - # include dependencies not publish to nixpkgs ddsketch = pkgs.callPackage ./ddsketch.nix { inherit python pkgs; }; ddtrace = pkgs.callPackage ./ddtrace.nix { inherit python pkgs ddsketch; }; @@ -94,31 +90,19 @@ ); ddapm-test-agent = ddapm-test-agent_base { doCheck = false; }; + skopeo = pkgs.skopeo; - run_with_agent = pkgs.writeShellScriptBin "run_with_agent" '' - #!${pkgs.bash}/bin/bash - set -euxo pipefail - - ${pkgs.coreutils}/bin/nohup ${pkgs.bash}/bin/bash -c "${ddapm-test-agent}/bin/ddapm-test-agent" & - - exec $@ - ''; - - toolContainer = nix2container.buildImage { + image = pkgs.dockerTools.buildImage { name = "ghcr.io/pawelchcki/ddapm-test-agent"; tag = "latest"; - config = { - entrypoint = [ "/bin/ddapm-test-agent" ]; - }; - copyToRoot = pkgs.buildEnv { name = "root"; - paths = [ - ddapm-test-agent - run_with_agent - ]; + paths = [ ddapm-test-agent ]; pathsToLink = [ "/bin" ]; }; + config = { + entrypoint = [ "/bin/ddapm-test-agent" ]; + }; }; in { @@ -128,8 +112,8 @@ ddapm-test-agent ddtrace ddsketch - toolContainer - run_with_agent + image + skopeo ; default = ddapm-test-agent; reno = pkgs.reno; @@ -144,10 +128,7 @@ devShells.default = pkgs.mkShell { venvDir = "./.venv"; - nativeBuildInputs = ddapm-test-agent.nativeBuildInputs ++ [ - ddapm-test-agent - run_with_agent - ]; + nativeBuildInputs = ddapm-test-agent.nativeBuildInputs ++ [ ddapm-test-agent ]; }; } ))