Skip to content

Commit

Permalink
image.Build*: Use values from ctx instead of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Nov 8, 2022
1 parent ae46de3 commit 2544714
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newDeployHandler(ctx context.Context, fs filesystem.Filesystem, devfileObj

// ApplyImage builds and pushes the OCI image to be used on Kubernetes
func (o *deployHandler) ApplyImage(img v1alpha2.Component) error {
return image.BuildPushSpecificImage(o.ctx, o.fs, o.path, img, true)
return image.BuildPushSpecificImage(o.ctx, o.fs, img, true)
}

// ApplyKubernetes applies inline Kubernetes YAML from the devfile.yaml file
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/component/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type runHandler struct {
var _ libdevfile.Handler = (*runHandler)(nil)

func (a *runHandler) ApplyImage(img devfilev1.Component) error {
return image.BuildPushSpecificImage(a.ctx, a.fs, a.path, img, true)
return image.BuildPushSpecificImage(a.ctx, a.fs, img, true)
}

func (a *runHandler) ApplyKubernetes(kubernetes devfilev1.Component) error {
Expand Down
16 changes: 12 additions & 4 deletions pkg/devfile/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"context"
"errors"
"os/exec"
"path/filepath"

devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"

envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"

"k8s.io/utils/pointer"
Expand All @@ -33,7 +34,12 @@ var lookPathCmd = exec.LookPath

// BuildPushImages build all images defined in the devfile with the detected backend
// If push is true, also push the images to their registries
func BuildPushImages(ctx context.Context, fs filesystem.Filesystem, devfileObj parser.DevfileObj, path string, push bool) error {
func BuildPushImages(ctx context.Context, fs filesystem.Filesystem, push bool) error {
var (
devfileObj = odocontext.GetDevfileObj(ctx)
devfilePath = odocontext.GetDevfilePath(ctx)
path = filepath.Dir(devfilePath)
)

backend, err := selectBackend(ctx)
if err != nil {
Expand Down Expand Up @@ -61,12 +67,14 @@ func BuildPushImages(ctx context.Context, fs filesystem.Filesystem, devfileObj p

// BuildPushSpecificImage build an image defined in the devfile present in devfilePath
// If push is true, also push the image to its registry
func BuildPushSpecificImage(ctx context.Context, fs filesystem.Filesystem, devfilePath string, component devfile.Component, push bool) error {
func BuildPushSpecificImage(ctx context.Context, fs filesystem.Filesystem, component devfile.Component, push bool) error {
var (
devfilePath = odocontext.GetDevfilePath(ctx)
)
backend, err := selectBackend(ctx)
if err != nil {
return err
}

return buildPushImage(backend, fs, component.Image, devfilePath, push)
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/odo/cli/build_images/build_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package build_images
import (
"context"
"fmt"
"path/filepath"

"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -63,12 +62,7 @@ func (o *BuildImagesOptions) Validate(ctx context.Context) (err error) {

// Run contains the logic for the odo command
func (o *BuildImagesOptions) Run(ctx context.Context) (err error) {
var (
devfileObj = odocontext.GetDevfileObj(ctx)
devfilePath = odocontext.GetDevfilePath(ctx)
path = filepath.Dir(devfilePath)
)
return image.BuildPushImages(ctx, o.clientset.FS, *devfileObj, path, o.pushFlag)
return image.BuildPushImages(ctx, o.clientset.FS, o.pushFlag)
}

// NewCmdBuildImages implements the odo command
Expand Down

0 comments on commit 2544714

Please sign in to comment.