mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat: process image templates in compose services, set default git-based tags if not specified
This commit is contained in:
@@ -53,6 +53,11 @@ func LoadProject(ctx context.Context, paths []string, opts ...composecli.Project
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Process image templates in services to expand Go template expressions using git repo state.
|
||||
if project, err = ProcessImageTemplates(project); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// loadProjectFromContent loads a compose project from YAML content
|
||||
// loadProjectFromContent loads a compose project from YAML content.
|
||||
// Keep the implementation in sync with LoadProject.
|
||||
func loadProjectFromContent(t *testing.T, content string) (*types.Project, error) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -62,6 +63,11 @@ func loadProjectFromContent(t *testing.T, content string) (*types.Project, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Process image templates in services to expand Go template expressions using git repo state.
|
||||
if project, err = ProcessImageTemplates(project); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user