fix: services.<name>.service.build.context

One could declare it, but it was unceremoniously ignored.
A "localhost/" image was created with pretty much nothing in it
 and it couldn't be launched.

The cause was services.<name>.service.image being always set
 and subsequently thugs services.<name>.image.nixBuild being truthy.
That would build an image and write the services.<name>.image field
 in the docker-compose.json. It leads to the build.context being
ignored and the service failing.

This was solved by only writing services.<name>.service.image when
 services.<name>.service.build.context is not set.
services.<name>.image.nixBuild is additionally set to false when
the context is set.

Related to #208
This commit is contained in:
LoveIsGrief 2023-08-19 22:13:18 +02:00
parent a8d9725e6c
commit 638c4b8e55
No known key found for this signature in database
GPG Key ID: E96D1EDFA05345EB
3 changed files with 20 additions and 16 deletions

View File

@ -86,7 +86,8 @@ in
description = serviceRef "environment";
};
service.image = mkOption {
type = str;
type = nullOr str;
default = null;
description = serviceRef "image";
};
service.command = mkOption {
@ -328,8 +329,9 @@ in
volumes
environment
sysctls
image
;
} // lib.optionalAttrs (config.service.image != null) {
inherit (config.service) image;
} // lib.optionalAttrs (config.service.build.context != null) {
inherit (config.service) build;
} // lib.optionalAttrs (cap_add != []) {

View File

@ -163,17 +163,19 @@ in
'';
};
};
config = {
build.image = builtImage;
build.imageName = config.build.image.imageName;
build.imageTag =
if config.build.image.imageTag != ""
then config.build.image.imageTag
else lib.head (lib.strings.splitString "-" (baseNameOf config.build.image.outPath));
service.image = lib.mkDefault "${config.build.imageName}:${config.build.imageTag}";
image.rawConfig.Cmd = config.image.command;
image.nixBuild = lib.mkDefault (priorityIsDefault options.service.image);
};
config = lib.mkMerge [{
build.image = builtImage;
build.imageName = config.build.image.imageName;
build.imageTag =
if config.build.image.imageTag != ""
then config.build.image.imageTag
else lib.head (lib.strings.splitString "-" (baseNameOf config.build.image.outPath));
image.rawConfig.Cmd = config.image.command;
image.nixBuild = lib.mkDefault (priorityIsDefault options.service.image);
}
( lib.mkIf (config.service.build.context == null)
{
service.image = lib.mkDefault "${config.build.imageName}:${config.build.imageTag}";
})
];
}