Skip to content

Commit

Permalink
Cleanup and document nix usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelchcki committed Dec 30, 2024
1 parent 0ed8663 commit 0759f8a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 100 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.venv
result
*.Dockerfile
2 changes: 1 addition & 1 deletion .github/workflows/nix-auto.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nix Flake actions
name: CI tasks from Nix config

on:
pull_request:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions build-on-darwin.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
74 changes: 3 additions & 71 deletions flake.lock

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

37 changes: 9 additions & 28 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand All @@ -20,7 +19,6 @@
nixpkgs,
flake-utils,
treefmt-nix,
nix2containerPkg,
nix-github-actions,
}:
(flake-utils.lib.eachDefaultSystem (
Expand All @@ -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; };
Expand Down Expand Up @@ -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
{
Expand All @@ -128,8 +112,8 @@
ddapm-test-agent
ddtrace
ddsketch
toolContainer
run_with_agent
image
skopeo
;
default = ddapm-test-agent;
reno = pkgs.reno;
Expand All @@ -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 ];
};
}
))
Expand Down

0 comments on commit 0759f8a

Please sign in to comment.