Streamline generating continue file

Fixes #29
This commit is contained in:
Greg Hellings
2024-11-18 22:26:17 -06:00
parent ee831b6c48
commit 1b8a742563
4 changed files with 128 additions and 34 deletions
+6 -10
View File
@@ -168,19 +168,15 @@
// uploads
// cibuilds
// {
continue = pkgs.writeText "continue.yml" (
builtins.replaceStrings
[
"QEMU_MATRIX"
"VBOX_MATRIX"
"HYPERV_MATRIX"
]
[
continue = (
import ./nix/continue.nix {
inherit
pkgs
qemu_list
vbox_list
hyperv_list
]
(builtins.readFile ./.gitlab-ci-build.yml.in)
;
}
);
cache = pkgs.callPackage (import ./nix/cache.nix) { inherit active distroFile; };
validate = pkgs.callPackage (import ./nix/validate.nix) { };
+16 -16
View File
@@ -22,26 +22,26 @@ writeShellApplication {
];
text =
''
push="''${1:-yes}"
if [ "$push" == "yes" ]; then
mc alias set storage "$STORAGE_URL" root "$MINIO_SECRET"
fi
mkdir -p cache
push="''${1:-yes}"
if [ "$push" == "yes" ]; then
mc alias set storage "$STORAGE_URL" root "$MINIO_SECRET"
fi
mkdir -p cache
''
+ (concatStringsSep "\n" (
map (d: ''
url=$(echo var.iso.url | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
sha=$(echo var.iso.checksum | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
distro=$(echo var.distro | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
# shellcheck disable=SC2143
if [ -z "$(mc ls "storage/isos/cache/$distro" | grep "$sha")" ]; then
curl -L --retry 3 --retry-all-errors -o "cache/$sha.iso" "$url"
if [ "$push" == "yes" ]; then
mc put "cache/$sha.iso" "storage/isos/cache/$distro/$sha.iso"
fi
else
echo "Skipping ${d.distro} - cache/$sha.iso"
url=$(echo var.iso.url | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
sha=$(echo var.iso.checksum | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
distro=$(echo var.distro | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
# shellcheck disable=SC2143
if [ -z "$(mc ls "storage/isos/cache/$distro" | grep "$sha")" ]; then
curl -L --retry 3 --retry-all-errors -o "cache/$sha.iso" "$url"
if [ "$push" == "yes" ]; then
mc put "cache/$sha.iso" "storage/isos/cache/$distro/$sha.iso"
fi
else
echo "Skipping ${d.distro} - cache/$sha.iso"
fi
'') active
));
}
+98
View File
@@ -0,0 +1,98 @@
{
pkgs,
qemu_list,
vbox_list,
hyperv_list,
...
}:
let
general = {
stage = "build";
cache = [
{
key = {
files = [ "sources/build.pkr.hcl" ];
};
paths = [ "./packer_config/" ];
}
];
rules = [
{
"if" = "$CI_COMMIT_TAG";
variables = {
EXCEPT = "";
JOB_PREFIX = "upload";
};
}
{
"if" = "$CI_COMMIT_TAG =~ \"/^$/\"";
variables = {
EXCEPT = "-except=upload";
JOB_PREIX = "ci";
};
}
];
needs = [
{
pipeline = "$PARENT_PIPELINE_ID";
job = "generate";
artifacts = true;
}
];
script = [
"nix run \".#\\\"\${JOB_PREIX}\${buildcmd}\\\"\" || exit 1"
];
};
variables = {
PACKER_CONFIG_DIR = "./packer_config/";
PACKER_CACHE_DIR = "./cache/";
PACKER_LOG = "1";
};
continue = {
stages = [
"build"
"release"
];
"qemu.amd64" = general // {
variables = variables // {
only = "-only=qemu.amd64";
};
tag = [ "qemu" ];
parallel = {
matrix = qemu_list;
};
before_script = [
"echo $BUILD"
"env"
];
};
"virtualbox-iso.amd64" = general // {
variables = variables // {
only = "-only=\"virtualbox-iso.amd64\"";
};
tags = [ "vbox" ];
parallel = {
matrix = vbox_list;
};
};
"hyperv-iso.amd64" = general // {
variables = variables // {
only = "-only=\"hyperv-iso.amd64\"";
};
tags = [ "hyperv" ];
parallel = {
matrix = hyperv_list;
};
script = [
"packer init sources"
"packer build -only=\"hyperv-iso.amd64\" -var-file=\"\${distro}\" -var build=\${BUILD} -var cpus=2 -var memory=4096 \${EXCEPT} sources"
"if (-not $?) { throw \"Error in build\")"
];
};
};
in
pkgs.writeText "continue.yml" (builtins.toJSON continue)
+8 -8
View File
@@ -11,13 +11,13 @@ writeShellApplication {
packer
];
text = ''
shopt -s globstar
if [ -e "''${PACKER_CONFIG_DIR}" ]; then
find "''${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";"
fi
packer init sources
for vars in distros/**/*.pkrvars.hcl; do
packer validate -except=upload "-var-file=''${vars}" sources/
done
shopt -s globstar
if [ -e "''${PACKER_CONFIG_DIR}" ]; then
find "''${PACKER_CONFIG_DIR}" -name '*_linux_amd64' -exec chmod +x '{}' ";"
fi
packer init sources
for vars in distros/**/*.pkrvars.hcl; do
packer validate -except=upload "-var-file=''${vars}" sources/
done
'';
}