rework building
All checks were successful
Albatros default

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 #!/usr/bin/env bash
set -euxo pipefail 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 #if [[ $BRANCH == "main" && -f $SECRET_PATH ]]; then
# mkdir -p /kaniko/.docker # mkdir -p /kaniko/.docker

View file

@ -1,5 +1,23 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1678964307, "lastModified": 1678964307,
@ -17,8 +35,24 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "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", "root": "root",

129
flake.nix
View file

@ -2,67 +2,114 @@
description = "Albatros"; description = "Albatros";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs"; nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs }: outputs = { self, nixpkgs, flake-utils }:
let with flake-utils.lib; let
# @FIXME probably not a good idea to hardcode it... archmap = {
system = "x86_64-linux"; aarch64-linux = {
GOOS = "linux";
pkgs = import nixpkgs { GOARCH = "arm64";
inherit system; };
overlays = [ ]; # we dropped the overlay we had, keep it as "skeleton". 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 # Should be configurable
albatrosStaticBin = arch: (pkgs.buildGoModule rec { 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"; pname = "albatros-go-module";
version = "0.9"; version = albaVersion;
src = ./.; src = ./.;
CGO_ENABLED = 0; CGO_ENABLED = 0;
vendorSha256 = "sha256-jzRYYsopJDYsar0nSYkTAOCGf4z20sgpDQ/eFmwYzM8="; vendorSha256 = "sha256-KYjXb882jWLFO6zilQXlrZorL9tw/+6njQNkB6E9Er4=";
checkPhase = '' dontCheck=true;
true
'';
buildPhase = '' 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 = '' installPhase = ''
cp albatros $out mkdir -p $out
cp alba ci $out/
''; '';
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "albatros is a CI for Nomad"; description = "albatros is a collection of tools to build your software supply chain";
homepage = "https://git.deuxfleurs.fr/quentin/albatros"; homepage = "https://git.deuxfleurs.fr/Deuxfleurs/albatros";
license = licenses.agpl3; license = licenses.agpl3;
platforms = platforms.linux; 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 # logic to build docker containers
dockerImg = staticBin: arch: pkgs.dockerTools.buildImage { container = pkgs.dockerTools.buildImage {
name = "dxflrs/albatros"; name = "dxflrs/albatros-ci";
architecture = arch; architecture = (builtins.getAttr targetHost archmap).GOARCH;
config = { config = {
Cmd = [ "${staticBin}" ]; Cmd = [ "${ci}" ];
}; };
}; };
# map nixos/llvm arch to golang arch # Exposed content
archmap = { in {
"aarch64-linux" = "arm64"; packages = {
"x86_64-linux" = "amd64"; inherit ci alba container;
"i686-linux" = "386"; default = ci;
"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;
}; };
});
} }