Alex Auvolat
390a5d97fe
This removes our dependency on cargo2nix, which was causing us some issues. Whereas cargo2nix creates one Nix derivation per crate, Crane uses only two derivations: 1. Build dependencies only 2. Build the final binary This means that during the second step, no caching can be done. For instance, if we do a change in garage_model, we need to recompile all of the Garage crates including those that do not depend on garage_model. On the upside, this allows all of the Garage crates to be built at once using cargo build logic, which is optimized for high parallelism and better pipelining between all of the steps of the build. All in all, this makes most builds faster than cargo2nix. A few other changes have been made to the build scripts and CI: - Unit tests are now run within a Nix derivation. In fact, we have different derivations to run the tests using LMDB and Sqlite as metadata db engines. - For debug builds, most CI steps now run in parallel (with the notable exception of the smoke test that runs after the build, which is inevitable). - We no longer pass the GIT_VERSION argument when building debug builds and running the tests. This means that dev binaries and test binaries don't know the exact version of Garage they are from. That shouldn't be an issue in most cases. - The not-dynamic.sh scripts has been fixed to fail if the file does not exist.
130 lines
3.3 KiB
Nix
130 lines
3.3 KiB
Nix
{ system ? builtins.currentSystem, }:
|
|
|
|
with import ./nix/common.nix;
|
|
|
|
let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
};
|
|
winscp = (import ./nix/winscp.nix) pkgs;
|
|
in
|
|
{
|
|
# --- Dev shell inherited from flake.nix ---
|
|
devShell = devShells.default;
|
|
devShellFull = devShells.full;
|
|
|
|
# --- Continuous integration shell ---
|
|
# The shell used for all CI jobs (along with devShell)
|
|
ci = pkgs.mkShell {
|
|
nativeBuildInputs = with pkgs; [
|
|
winscp
|
|
|
|
kaniko
|
|
manifest-tool
|
|
awscli2
|
|
file
|
|
s3cmd
|
|
minio-client
|
|
rclone
|
|
socat
|
|
psmisc
|
|
which
|
|
openssl
|
|
curl
|
|
jq
|
|
];
|
|
shellHook = ''
|
|
function to_s3 {
|
|
aws \
|
|
--endpoint-url https://garage.deuxfleurs.fr \
|
|
--region garage \
|
|
s3 cp \
|
|
./result/bin/garage \
|
|
s3://garagehq.deuxfleurs.fr/_releases/''${CI_COMMIT_TAG:-$CI_COMMIT_SHA}/''${TARGET}/garage
|
|
}
|
|
|
|
function to_docker {
|
|
executor \
|
|
--force \
|
|
--customPlatform="$(echo "''${DOCKER_PLATFORM}" | sed 's/i386/386/')" \
|
|
--destination "$(echo "''${CONTAINER_NAME}" | sed 's/i386/386/'):''${CONTAINER_TAG}" \
|
|
--context dir://`pwd` \
|
|
--verbosity=debug
|
|
}
|
|
|
|
function multiarch_docker {
|
|
manifest-tool push from-spec <(cat <<EOF
|
|
image: dxflrs/garage:''${CONTAINER_TAG}
|
|
manifests:
|
|
-
|
|
image: dxflrs/arm64_garage:''${CONTAINER_TAG}
|
|
platform:
|
|
architecture: arm64
|
|
os: linux
|
|
-
|
|
image: dxflrs/amd64_garage:''${CONTAINER_TAG}
|
|
platform:
|
|
architecture: amd64
|
|
os: linux
|
|
-
|
|
image: dxflrs/386_garage:''${CONTAINER_TAG}
|
|
platform:
|
|
architecture: 386
|
|
os: linux
|
|
-
|
|
image: dxflrs/arm_garage:''${CONTAINER_TAG}
|
|
platform:
|
|
architecture: arm
|
|
os: linux
|
|
EOF
|
|
)
|
|
}
|
|
|
|
function refresh_index {
|
|
aws \
|
|
--endpoint-url https://garage.deuxfleurs.fr \
|
|
--region garage \
|
|
s3 ls \
|
|
--recursive \
|
|
s3://garagehq.deuxfleurs.fr/_releases/ \
|
|
> aws-list.txt
|
|
|
|
nix-build nix/build_index.nix
|
|
|
|
aws \
|
|
--endpoint-url https://garage.deuxfleurs.fr \
|
|
--region garage \
|
|
s3 cp \
|
|
result/share/_releases.json \
|
|
s3://garagehq.deuxfleurs.fr/
|
|
|
|
aws \
|
|
--endpoint-url https://garage.deuxfleurs.fr \
|
|
--region garage \
|
|
s3 cp \
|
|
result/share/_releases.html \
|
|
s3://garagehq.deuxfleurs.fr/
|
|
}
|
|
'';
|
|
|
|
};
|
|
|
|
# --- Cache shell ---
|
|
# A shell for refreshing caches
|
|
cache = pkgs.mkShell {
|
|
shellHook = ''
|
|
function refresh_cache {
|
|
pass show deuxfleurs/nix_priv_key > /tmp/nix-signing-key.sec
|
|
for attr in pkgs.amd64.debug test.amd64 pkgs.{amd64,i386,arm,arm64}.release; do
|
|
echo "Updating cache for ''${attr}"
|
|
nix copy -j8 \
|
|
--to 's3://nix?endpoint=garage.deuxfleurs.fr®ion=garage&secret-key=/tmp/nix-signing-key.sec' \
|
|
$(nix path-info ''${attr} --file default.nix --derivation --recursive | sed 's/\.drv$/.drv^*/')
|
|
|
|
done
|
|
rm /tmp/nix-signing-key.sec
|
|
}
|
|
'';
|
|
};
|
|
}
|
|
|