Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <fridrich.david19@gmail.com>
  • Loading branch information
gauron99 authored and David Fridrich committed Aug 26, 2024
1 parent 0ddc30a commit 25dba57
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ func printDeployMessages(out io.Writer, f fn.Function) {
}
}

// isUndigested returns true if provided image string 'v' has valid tag and false if
// isUndigested returns true if provided image string 'v' is valid ( by
// by acceptable standards -- tagged, untagged -> assuming :latest) and false if
// not. It is lenient in validating - does not always throw an error, just
// returning false in some scenarios.
func isUndigested(v string) (validTag bool, err error) {
Expand Down
34 changes: 27 additions & 7 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,23 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
client, done := newClient(ClientConfig{Verbose: cfg.Verbose}, clientOptions...)
defer done()

f, digested, err := processImageName(f, cfg.Image)
// check for digested image first
var digested bool
digested, err = isDigested(cfg.Image)
if err != nil {
return
}
if digested {
f.Deploy.Image = cfg.Image
return err
}

// if !digested {
// valid, err := isUndigested(cfg.Image)
// if err != nil {
// return err
// }
// if valid {
// f.Run.Image = cfg.Image //assign image to be potentially run
// }
// }

// Build
//
// If requesting to run via the container, build the container if it is
Expand All @@ -189,8 +198,19 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
if err != nil {
return err
}
if f, _, err = build(cmd, cfg.Build, f, client, buildOptions); err != nil {
return err

if digested {
// run cmd takes f.Build.Image - see newContainerConfig in docker/runner.go
// it doesnt get saved, just runtime image
f.Build.Image = cfg.Image
} else {
if f, _, err = build(cmd, cfg.Build, f, client, buildOptions); err != nil {
return err
}
}
} else { // dont run digested image without a container
if digested {
return fmt.Errorf("cannot use digested image with --container=false")
}
}

Expand Down
13 changes: 4 additions & 9 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,19 @@ func TestRun_Images(t *testing.T) {
args: []string{"--image", "exampleimage@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"},
runInvoked: true,
buildInvoked: false,
runError: nil,
buildError: nil,
},
{
name: "image with tag direct deploy",
args: []string{"--image", "exampleimage:latest", "--build=false"},
runInvoked: true,
buildInvoked: false,
runError: nil,
buildError: nil,
},
{
name: "image without tag direct deploy",
args: []string{"--image", "exampleimage", "--build=false"},
runInvoked: true,
name: "digested image without container should fail",
args: []string{"--container=false", "--image", "exampleimage@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"},
runInvoked: false,
buildInvoked: false,
runError: nil,
buildError: nil,
buildError: fmt.Errorf("cannot use digested image with --container=false"),
},
}

Expand Down

0 comments on commit 25dba57

Please sign in to comment.