Skip to content

Commit

Permalink
fix(build): set image to known name if unset
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Sep 29, 2024
1 parent a055b4b commit 6df404d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,16 @@ func (g *Generator) parseServiceBuild(service types.ServiceConfig, c *NixContain
cx = path.Join(g.rootPath, cx)
}

// Always prepend the image name to the list of specified tags.
tags := service.Build.Tags
if service.Image != "" {
// Always prepend the image name to the list of specified tags.
tags = slices.Insert(tags, 0, service.Image)
} else {
// If no image is set on the service, we'll add a custom tag and point
// the image to it.
imageName := fmt.Sprintf("compose2nix-%s", c.Name)
tags = append(tags, imageName)
c.Image = imageName
}

b := &NixBuild{
Expand Down
4 changes: 2 additions & 2 deletions testdata/TestBuildSpec.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Containers
virtualisation.oci-containers.containers."test-museum" = {
image = "";
image = "compose2nix-test-museum";
environment = {
"ENTE_CREDENTIALS_FILE" = "/credentials.yaml";
};
Expand Down Expand Up @@ -122,7 +122,7 @@
};
script = ''
cd /some/path
docker build -t latest -t non-latest --build-arg GIT_COMMIT=development-cluster .
docker build -t latest -t non-latest -t compose2nix-test-museum --build-arg GIT_COMMIT=development-cluster .
'';
};
systemd.services."docker-build-test-prefetcharr" = {
Expand Down
4 changes: 2 additions & 2 deletions testdata/TestBuildSpec.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Containers
virtualisation.oci-containers.containers."test-museum" = {
image = "";
image = "compose2nix-test-museum";
environment = {
"ENTE_CREDENTIALS_FILE" = "/credentials.yaml";
};
Expand Down Expand Up @@ -132,7 +132,7 @@
};
script = ''
cd /some/path
podman build -t latest -t non-latest --build-arg GIT_COMMIT=development-cluster .
podman build -t latest -t non-latest -t compose2nix-test-museum --build-arg GIT_COMMIT=development-cluster .
'';
};
systemd.services."podman-build-test-prefetcharr" = {
Expand Down
4 changes: 2 additions & 2 deletions testdata/TestBuildSpec_BuildEnabled.docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Containers
virtualisation.oci-containers.containers."test-museum" = {
image = "";
image = "compose2nix-test-museum";
environment = {
"ENTE_CREDENTIALS_FILE" = "/credentials.yaml";
};
Expand Down Expand Up @@ -89,7 +89,7 @@
};
script = ''
cd /some/path
docker build --build-arg GIT_COMMIT=development-cluster -f path/Dockerfile .
docker build -t compose2nix-test-museum --build-arg GIT_COMMIT=development-cluster -f path/Dockerfile .
'';
partOf = [ "docker-compose-test-root.target" ];
wantedBy = [ "docker-compose-test-root.target" ];
Expand Down
4 changes: 2 additions & 2 deletions testdata/TestBuildSpec_BuildEnabled.podman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Containers
virtualisation.oci-containers.containers."test-museum" = {
image = "";
image = "compose2nix-test-museum";
environment = {
"ENTE_CREDENTIALS_FILE" = "/credentials.yaml";
};
Expand Down Expand Up @@ -99,7 +99,7 @@
};
script = ''
cd /some/path
podman build --build-arg GIT_COMMIT=development-cluster -f path/Dockerfile .
podman build -t compose2nix-test-museum --build-arg GIT_COMMIT=development-cluster -f path/Dockerfile .
'';
partOf = [ "podman-compose-test-root.target" ];
wantedBy = [ "podman-compose-test-root.target" ];
Expand Down

0 comments on commit 6df404d

Please sign in to comment.