From 4c8ea6cec9a0645825d2323465784ba3fe4ebf12 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 24 Mar 2023 14:35:43 +0100 Subject: [PATCH] working on better builder --- .albatros | 12 ++++---- README.md | 16 +++++++++-- hcl/builder.hcl | 76 ++++++++++--------------------------------------- hcl/nix.conf | 9 ++++++ hcl/pin.sh | 4 +++ hcl/user.sh | 19 +++++++++++++ hcl/warmup.sh | 11 +++++++ 7 files changed, 78 insertions(+), 69 deletions(-) create mode 100644 hcl/nix.conf create mode 100644 hcl/pin.sh create mode 100644 hcl/user.sh create mode 100644 hcl/warmup.sh diff --git a/.albatros b/.albatros index e10424b..b30c445 100755 --- a/.albatros +++ b/.albatros @@ -2,9 +2,9 @@ set -euxo pipefail nix build -if [[ $BRANCH == "main" && -f $SECRET_PATH ]]; then - mkdir -p /kaniko/.docker - cp $SECRET_PATH /kaniko/.docker/config.json - export HOME=/kaniko - nix develop --command sh -c "executor --force --destination dxflrs/albatros:${COMMIT} --context dir://`pwd` --verbosity=debug" 1>&2 -fi +#if [[ $BRANCH == "main" && -f $SECRET_PATH ]]; then +# mkdir -p /kaniko/.docker +# cp $SECRET_PATH /kaniko/.docker/config.json +# export HOME=/kaniko +# nix develop --command sh -c "executor --force --destination dxflrs/albatros:${COMMIT} --context dir://`pwd` --verbosity=debug" 1>&2 +#fi diff --git a/README.md b/README.md index 62d0164..0ebe834 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,20 @@ And... that's basically all you need. ### A NixOS builder with local cache -Currently, we propose a single, nix-based builder. -I am currently working on using proper caching on it. +The nix builder will create a local cache on your node agent at `/var/cache/albatros`. +It will create two folders: `/var/cache/albatros/nix` that contains a nix store, +and `/var/cache/albatros/cacheroot` that contains nix roots, ie. the builds we must keep. + +Caching is handled thanks to these roots: roots that are older than 7 days will be removed, +then a garbage collection will be triggered, and their associate content will be deleted. + +To keep your cache between builds, you must put your outlink in `/mnt/cacheroot` with a unique name. +The git commit is a good candidate: + +```bash +# create an output link at a persisted path +nix build --out-link $GCROOT +``` ## Register a build diff --git a/hcl/builder.hcl b/hcl/builder.hcl index 6094eee..1e9dd74 100644 --- a/hcl/builder.hcl +++ b/hcl/builder.hcl @@ -37,19 +37,7 @@ job "builder" { } template { - data = <