rework building
Albatros default Details

This commit is contained in:
Quentin 2023-05-04 11:00:37 +02:00
parent 8de564e62e
commit 664dc72ec5
Signed by: quentin
GPG Key ID: E9602264D639FF68
4 changed files with 137 additions and 42 deletions

View File

@ -1,6 +1,20 @@
#!/usr/bin/env bash
set -euxo pipefail
nix build --print-build-logs
nix build --print-build-logs .#packages.x86_64-linux.ci -o df/linux/amd64/ci
nix build --print-build-logs .#packages.i686-linux.ci -o df/linux/386/ci
nix build --print-build-logs .#packages.aarch64-linux.ci -o df/linux/arm64/ci
nix build --print-build-logs .#packages.armv6l-linux.ci -o df/linux/arm/ci
nix build --print-build-logs .#packages.x86_64-linux.alba -o df/linux/amd64/alba
nix build --print-build-logs .#packages.i686-linux.alba -o df/linux/386/alba
nix build --print-build-logs .#packages.aarch64-linux.alba -o df/linux/arm64/alba
nix build --print-build-logs .#packages.armv6l-linux.alba -o df/linux/arm/alba
nix build --print-build-logs .#packages.x86_64-linux.container -o docker/linux.amd64.tar.gz
nix build --print-build-logs .#packages.armv6l-linux.container -o docker/linux.arm.tar.gz
nix build --print-build-logs .#packages.aarch64-linux.container -o docker/linux.arm64.tar.gz
nix build --print-build-logs .#packages.i686-linux.container -o docker/linux.386.tar.gz
#if [[ $BRANCH == "main" && -f $SECRET_PATH ]]; then
# mkdir -p /kaniko/.docker

View File

@ -1,5 +1,23 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1678964307,
@ -17,8 +35,24 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

129
flake.nix
View File

@ -2,67 +2,114 @@
description = "Albatros";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs }:
let
# @FIXME probably not a good idea to hardcode it...
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ ]; # we dropped the overlay we had, keep it as "skeleton".
outputs = { self, nixpkgs, flake-utils }:
with flake-utils.lib; let
archmap = {
aarch64-linux = {
GOOS = "linux";
GOARCH = "arm64";
};
x86_64-linux = {
GOOS = "linux";
GOARCH = "amd64";
};
i686-linux = {
GOOS = "linux";
GOARCH = "386";
};
armv6l-linux = {
GOOS = "linux";
GOARCH = "arm";
};
};
in eachSystem [
# supported systems
system.x86_64-linux
system.i686-linux
system.armv6l-linux
system.aarch64-linux
] (targetHost: let
# declare the go module of this package, allow for cross compilation
albatrosStaticBin = arch: (pkgs.buildGoModule rec {
# Should be configurable
buildSystem = system.x86_64-linux;
# generic config
albaVersion = "0.9";
# nix repository
pkgs = import nixpkgs {
system = buildSystem;
# we don't use nixos cross environment as it is slow and not required
#crossSystem = {
# config = targetHost;
#};
overlays = [ ]; # we dropped the overlay we had, keep it as "skeleton".
};
# declare the go module of this package
albatrosProject = (pkgs.buildGoModule rec {
pname = "albatros-go-module";
version = "0.9";
version = albaVersion;
src = ./.;
CGO_ENABLED = 0;
vendorSha256 = "sha256-jzRYYsopJDYsar0nSYkTAOCGf4z20sgpDQ/eFmwYzM8=";
checkPhase = ''
true
'';
vendorSha256 = "sha256-KYjXb882jWLFO6zilQXlrZorL9tw/+6njQNkB6E9Er4=";
dontCheck=true;
buildPhase = ''
go build bin/albatros.go
go build bin/ci.go
go build -tags containers_image_docker_daemon_stub,containers_image_storage_stub,containers_image_openpgp bin/alba.go
'';
installPhase = ''
cp albatros $out
mkdir -p $out
cp alba ci $out/
'';
meta = with pkgs.lib; {
description = "albatros is a CI for Nomad";
homepage = "https://git.deuxfleurs.fr/quentin/albatros";
description = "albatros is a collection of tools to build your software supply chain";
homepage = "https://git.deuxfleurs.fr/Deuxfleurs/albatros";
license = licenses.agpl3;
platforms = platforms.linux;
};
}).overrideAttrs (old: old // { GOOS = "linux"; GOARCH = arch; });
}).overrideAttrs (old: old // (builtins.getAttr targetHost archmap));
# get only a statically compiled ci
ci = pkgs.stdenv.mkDerivation {
pname = "albatros-ci";
version = albaVersion;
dontUnpack = true;
dontBuild = true;
installPhase = ''
cp ${albatrosProject}/ci $out
'';
};
# get only a statically compiled alba tool
alba = pkgs.stdenv.mkDerivation {
pname = "albatros-alba";
version = albaVersion;
dontUnpack = true;
dontBuild = true;
installPhase = ''
cp ${albatrosProject}/alba $out
'';
};
# logic to build docker containers
dockerImg = staticBin: arch: pkgs.dockerTools.buildImage {
name = "dxflrs/albatros";
architecture = arch;
container = pkgs.dockerTools.buildImage {
name = "dxflrs/albatros-ci";
architecture = (builtins.getAttr targetHost archmap).GOARCH;
config = {
Cmd = [ "${staticBin}" ];
Cmd = [ "${ci}" ];
};
};
# map nixos/llvm arch to golang arch
archmap = {
"aarch64-linux" = "arm64";
"x86_64-linux" = "amd64";
"i686-linux" = "386";
"armv6l-linux" = "arm";
};
# generate packages for each architecture
packages = builtins.mapAttrs (name: value: rec {
albatros = (albatrosStaticBin value);
docker.albatros = (dockerImg albatros value);
default = albatros;
}) archmap;
in
{
inherit packages;
# Exposed content
in {
packages = {
inherit ci alba container;
default = ci;
};
});
}