feat: process image templates in compose services, set default git-based tags if not specified

This commit is contained in:
Pasha Sviderski
2025-11-01 16:06:52 +10:00
parent 328ace1fd1
commit 26c3699a9e
3 changed files with 19 additions and 4 deletions
+7 -3
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"path"
"strconv"
"strings"
"testing"
composecli "github.com/compose-spec/compose-go/v2/cli"
@@ -99,7 +100,7 @@ func TestComposeBuild(t *testing.T) {
require.NoError(t, err)
servicesToBuild, err := cliInternal.ServicesThatNeedBuild(project, nil, false)
require.NoError(t, err)
serviceImage1 := fmt.Sprintf("127.0.0.1:%d/service-first", registryHostPort)
serviceImage1 := project.Services["service-first"].Image // contains auto-generated default tag
serviceImage2 := fmt.Sprintf("127.0.0.1:%d/service-second:version2", registryHostPort)
t.Cleanup(func() {
// Remove the images after the test
@@ -146,12 +147,15 @@ func TestComposeBuild(t *testing.T) {
cli.BuildServices(context.Background(), servicesToBuild, buildOpts)
// Check the image of the first service
ref1, err := name.NewRepository(fmt.Sprintf("127.0.0.1:%d/service-first", registryHostPort))
tagSeparatorIdx := strings.LastIndex(serviceImage1, ":")
serviceRepo1, serviceTag1 := serviceImage1[:tagSeparatorIdx], serviceImage1[tagSeparatorIdx+1:]
ref1, err := name.NewRepository(serviceRepo1)
require.NoError(t, err)
tags, err := remote.List(ref1)
require.NoError(t, err)
assert.Equal(t, tags, []string{"latest"}, "Tags for service service-first do not match")
assert.Equal(t, tags, []string{serviceTag1}, "Tags for service service-first do not match")
// Check the image of the second service
ref2, err := name.NewRepository(fmt.Sprintf("127.0.0.1:%d/service-second", registryHostPort))