Skip to content

Commit eeda0af

Browse files
authored
Merge pull request #6029 from thaJeztah/stack_deploy_failearly
stack deploy: fail early on invalid image reference format
2 parents aa065b4 + bcb36e2 commit eeda0af

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

cli/command/stack/loader/loader.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sort"
1313
"strings"
1414

15+
"github.com/distribution/reference"
1516
"github.com/docker/cli/cli/command"
1617
"github.com/docker/cli/cli/command/stack/options"
1718
"github.com/docker/cli/cli/compose/loader"
@@ -49,6 +50,17 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.
4950
_, _ = fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n",
5051
propertyWarnings(deprecatedProperties))
5152
}
53+
54+
// Validate if each service has a valid image-reference.
55+
for _, svc := range config.Services {
56+
if svc.Image == "" {
57+
return nil, errors.Errorf("invalid image reference for service %s: no image specified", svc.Name)
58+
}
59+
if _, err := reference.ParseAnyReference(svc.Image); err != nil {
60+
return nil, errors.Wrapf(err, "invalid image reference for service %s", svc.Name)
61+
}
62+
}
63+
5264
return config, nil
5365
}
5466

0 commit comments

Comments
 (0)