Skip to content

Commit e776ed4

Browse files
committed
feat: support long syntax for image names and build tags
This adds support for specifying image references using a map with name/tag/digest fields instead of a plain string, making it possible to use YAML anchors for version management in compose files. Depends on compose-spec/compose-go#NNN (ssam18/compose-go feat/image-long-syntax)
1 parent 63601eb commit e776ed4

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ require (
147147
gopkg.in/yaml.v3 v3.0.1 // indirect
148148
)
149149

150+
replace github.com/compose-spec/compose-go/v2 => github.com/ssam18/compose-go/v2 v2.10.1-0.20260403150144-9520977b355e
151+
150152
exclude (
151153
// FIXME(thaJeztah): remove this once kubernetes updated their dependencies to no longer need this.
152154
//

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg
3636
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
3737
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
3838
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
39-
github.com/compose-spec/compose-go/v2 v2.10.1 h1:mFbXobojGRFIVi1UknrvaDAZ+PkJfyjqkA1yseh+vAU=
40-
github.com/compose-spec/compose-go/v2 v2.10.1/go.mod h1:Ohac1SzhO/4fXXrzWIztIVB6ckmKBv1Nt5Z5mGVESUg=
4139
github.com/containerd/cgroups/v3 v3.1.3 h1:eUNflyMddm18+yrDmZPn3jI7C5hJ9ahABE5q6dyLYXQ=
4240
github.com/containerd/cgroups/v3 v3.1.3/go.mod h1:PKZ2AcWmSBsY/tJUVhtS/rluX0b1uq1GmPO1ElCmbOw=
4341
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
@@ -343,6 +341,8 @@ github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiT
343341
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
344342
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
345343
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
344+
github.com/ssam18/compose-go/v2 v2.10.1-0.20260403150144-9520977b355e h1:cEGBnX0T7lYq9QboJwmnxj6M5zk1H+KFqdBQsXQ2GNg=
345+
github.com/ssam18/compose-go/v2 v2.10.1-0.20260403150144-9520977b355e/go.mod h1:Ohac1SzhO/4fXXrzWIztIVB6ckmKBv1Nt5Z5mGVESUg=
346346
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
347347
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
348348
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

pkg/compose/loader_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,70 @@ services:
286286
api.Separator = "-"
287287
}
288288

289+
func TestLoadProject_ImageLongSyntax(t *testing.T) {
290+
tmpDir := t.TempDir()
291+
composeFile := filepath.Join(tmpDir, "compose.yaml")
292+
composeContent := `
293+
name: test-project
294+
services:
295+
web:
296+
image:
297+
name: nginx
298+
tag: "1.25"
299+
build:
300+
context: .
301+
tags:
302+
- name: nginx
303+
tag: "1.25"
304+
- name: nginx
305+
tag: latest
306+
- nginx:stable
307+
`
308+
err := os.WriteFile(composeFile, []byte(composeContent), 0o644)
309+
assert.NilError(t, err)
310+
311+
service, err := NewComposeService(nil)
312+
assert.NilError(t, err)
313+
314+
project, err := service.LoadProject(t.Context(), api.ProjectLoadOptions{
315+
ConfigPaths: []string{composeFile},
316+
})
317+
assert.NilError(t, err)
318+
319+
webService := project.Services["web"]
320+
assert.Equal(t, "nginx:1.25", webService.Image)
321+
assert.Check(t, is.Len(webService.Build.Tags, 3))
322+
assert.Equal(t, "nginx:1.25", webService.Build.Tags[0])
323+
assert.Equal(t, "nginx:latest", webService.Build.Tags[1])
324+
assert.Equal(t, "nginx:stable", webService.Build.Tags[2])
325+
}
326+
327+
func TestLoadProject_ImageLongSyntaxDigest(t *testing.T) {
328+
tmpDir := t.TempDir()
329+
composeFile := filepath.Join(tmpDir, "compose.yaml")
330+
composeContent := `
331+
name: test-project
332+
services:
333+
web:
334+
image:
335+
name: nginx
336+
digest: sha256:abc123
337+
`
338+
err := os.WriteFile(composeFile, []byte(composeContent), 0o644)
339+
assert.NilError(t, err)
340+
341+
service, err := NewComposeService(nil)
342+
assert.NilError(t, err)
343+
344+
project, err := service.LoadProject(t.Context(), api.ProjectLoadOptions{
345+
ConfigPaths: []string{composeFile},
346+
})
347+
assert.NilError(t, err)
348+
349+
webService := project.Services["web"]
350+
assert.Equal(t, "nginx@sha256:abc123", webService.Image)
351+
}
352+
289353
func TestLoadProject_InvalidComposeFile(t *testing.T) {
290354
tmpDir := t.TempDir()
291355
composeFile := filepath.Join(tmpDir, "compose.yaml")

0 commit comments

Comments
 (0)