Skip to content

Commit

Permalink
fix: only set log opts if driver is set
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Oct 7, 2024
1 parent 13b6fa0 commit 305a190
Show file tree
Hide file tree
Showing 17 changed files with 4 additions and 202 deletions.
6 changes: 2 additions & 4 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,16 @@ func (g *Generator) buildNixContainer(service types.ServiceConfig, networkMap ma
if service.LogDriver != "" {
if service.LogDriver != "json-file" || g.UseComposeLogDriver {
c.LogDriver = service.LogDriver
c.ExtraOptions = append(c.ExtraOptions, mapToRepeatedKeyValFlag("--log-opt", service.LogOpt)...)
}
// Log options are always passed through.
c.ExtraOptions = append(c.ExtraOptions, mapToRepeatedKeyValFlag("--log-opt", service.LogOpt)...)
}
// New logging setting always overrides the legacy setting.
// https://docs.docker.com/compose/compose-file/compose-file-v3/#logging
if logging := service.Logging; logging != nil {
if logging.Driver != "json-file" || g.UseComposeLogDriver {
c.LogDriver = logging.Driver
c.ExtraOptions = append(c.ExtraOptions, mapToRepeatedKeyValFlag("--log-opt", logging.Options)...)
}
// Log options are always passed through.
c.ExtraOptions = append(c.ExtraOptions, mapToRepeatedKeyValFlag("--log-opt", logging.Options)...)
}

if err := parseHealthCheck(c, service, g.Runtime); err != nil {
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestBasic.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -95,9 +92,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -151,9 +145,6 @@
"--health-start-interval=5s"
"--health-start-period=40s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -283,9 +274,6 @@
];
log-driver = "journald";
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestBasic.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -103,9 +100,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -156,9 +150,6 @@
"--health-start-period=40s"
"--health-startup-interval=5s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -285,9 +276,6 @@
];
log-driver = "journald";
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
16 changes: 1 addition & 15 deletions testdata/TestBasicAutoFormat.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -89,9 +86,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -141,9 +135,6 @@
"--health-start-interval=5s"
"--health-start-period=40s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -258,12 +249,7 @@
};
dependsOn = [ "sabnzbd" ];
log-driver = "journald";
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
extraOptions = [ "--network=container:sabnzbd" ];
};
systemd.services."docker-traefik" = {
serviceConfig = {
Expand Down
16 changes: 1 addition & 15 deletions testdata/TestBasicAutoFormat.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -97,9 +94,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -146,9 +140,6 @@
"--health-start-period=40s"
"--health-startup-interval=5s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -260,12 +251,7 @@
};
dependsOn = [ "sabnzbd" ];
log-driver = "journald";
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
extraOptions = [ "--network=container:sabnzbd" ];
};
systemd.services."podman-traefik" = {
serviceConfig = {
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestNoWriteNixSetup.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -85,9 +82,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -136,9 +130,6 @@
"--health-start-interval=5s"
"--health-start-period=40s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -263,9 +254,6 @@
log-driver = "journald";
autoStart = false;
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestNoWriteNixSetup.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -83,9 +80,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -131,9 +125,6 @@
"--health-start-period=40s"
"--health-startup-interval=5s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -255,9 +246,6 @@
log-driver = "journald";
autoStart = false;
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestOverrideSystemdStopTimeout.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -92,9 +89,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -144,9 +138,6 @@
"--health-start-interval=5s"
"--health-start-period=40s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -273,9 +264,6 @@
log-driver = "journald";
autoStart = false;
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestOverrideSystemdStopTimeout.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -100,9 +97,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -149,9 +143,6 @@
"--health-start-period=40s"
"--health-startup-interval=5s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -275,9 +266,6 @@
log-driver = "journald";
autoStart = false;
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
12 changes: 0 additions & 12 deletions testdata/TestProject.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
"--cpus=1"
"--dns=1.1.1.1"
"--health-cmd=curl -f http://localhost/\${POTATO}"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--memory-reservation=524288000b"
"--memory=1048576000b"
"--network=container:myproject-sabnzbd"
Expand Down Expand Up @@ -91,9 +88,6 @@
extraOptions = [
"--health-cmd=curl -f http://localhost/"
"--hostname=sabnzbd"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network-alias=sabnzbd"
"--network=myproject_default"
];
Expand Down Expand Up @@ -142,9 +136,6 @@
"--health-start-interval=5s"
"--health-start-period=40s"
"--health-timeout=10s"
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=host"
];
};
Expand Down Expand Up @@ -269,9 +260,6 @@
log-driver = "journald";
autoStart = false;
extraOptions = [
"--log-opt=compress=true"
"--log-opt=max-file=3"
"--log-opt=max-size=10m"
"--network=container:sabnzbd"
];
};
Expand Down
Loading

0 comments on commit 305a190

Please sign in to comment.