Skip to content

Commit

Permalink
Log if image is referenced by tag (knative#2090)
Browse files Browse the repository at this point in the history
* Log if image is referenced by tag

Signed-off-by: AdamKorcz <[email protected]>

* fixup: do not warn with standard images

Signed-off-by: Matej Vasek <[email protected]>

---------

Signed-off-by: AdamKorcz <[email protected]>
Signed-off-by: Matej Vasek <[email protected]>
Co-authored-by: Matej Vasek <[email protected]>
  • Loading branch information
AdamKorcz and matejvasek authored Nov 29, 2023
1 parent 284da86 commit 7ebf92d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/whilp/git-urls v1.0.0
github.com/xanzy/go-gitlab v0.83.0
golang.org/x/crypto v0.15.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/net v0.18.0
golang.org/x/oauth2 v0.14.0
golang.org/x/sync v0.5.0
Expand Down Expand Up @@ -227,7 +228,6 @@ require (
go.starlark.net v0.0.0-20220817180228-f738f5508c12 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions pkg/builders/s2i/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"

"github.com/docker/docker/api/types"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/openshift/source-to-image/pkg/build/strategies"
s2idocker "github.com/openshift/source-to-image/pkg/docker"
"github.com/openshift/source-to-image/pkg/scm/git"
"golang.org/x/exp/maps"
"golang.org/x/term"

"knative.dev/func/pkg/builders"
Expand Down Expand Up @@ -356,6 +358,9 @@ func s2iScriptURL(ctx context.Context, cli DockerClient, image string) (string,
if err != nil {
return "", fmt.Errorf("cannot parse image name: %w", err)
}
if _, ok := ref.(name.Tag); ok && !slices.Contains(maps.Values(DefaultBuilderImages), image) {
fmt.Fprintln(os.Stderr, "image referenced by tag which is discouraged: Tags are mutable and can point to a different artifact than the expected one")
}
img, err = remote.Image(ref)
if err != nil {
return "", fmt.Errorf("cannot get image from registry: %w", err)
Expand Down

0 comments on commit 7ebf92d

Please sign in to comment.