Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General clean up #12

Merged
merged 7 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ test-cmd-devfile-push:
test-cmd-devfile-deploy:
ginkgo $(GINKGO_FLAGS) -focus="odo devfile deploy command tests" tests/integration/devfile/

# Run odo push devfile command tests
# Run odo deploy delete devfile command tests
.PHONY: test-cmd-devfile-deploy-delete
test-cmd-devfile-deploy-delete:
ginkgo $(GINKGO_FLAGS) -focus="odo devfile deploy delete command tests" tests/integration/devfile/
Expand Down
1 change: 1 addition & 0 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (a Adapter) runBuildConfig(client *occlient.Client, parameters common.Build
return err
}

log.Successf("Started build using BuildConfig")
bc, err := client.RunBuildConfigWithBinaryInput(buildName, reader)
if err != nil {
return err
Expand Down
9 changes: 0 additions & 9 deletions pkg/devfile/parser/data/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ type DevfileComponent struct {

// Volume component
Volume *Volume `json:"volume,omitempty"`

// Dockerfile component
Dockerfile *Dockerfile `json:"dockerfile,omitempty"`
}

// Dockerfile cmponent
type Dockerfile struct {
Path string `json:"path"`
Args []string `json:"args,omitempty"`
}

// DevfileProject project defined in devfile
Expand Down
64 changes: 38 additions & 26 deletions pkg/odo/cli/component/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
projectCmd "github.com/openshift/odo/pkg/odo/cli/project"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/completion"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -21,39 +20,52 @@ import (
ktemplates "k8s.io/kubectl/pkg/util/templates"
)

// TODO: add CLI Reference doc
// TODO: add delete example
var deployCmdExample = ktemplates.Examples(` # Deploys an image and deploys the application
var deployCmdExample = ktemplates.Examples(` # Build and Deploy the current component
%[1]s

# Specify the tag for the image by calling
%[1]s --tag <registry>/<namespace>/<image>:<tag>
`)

// DeployRecommendedCommandName is the recommended build command name
const DeployRecommendedCommandName = "deploy"

// DeployOptions encapsulates options that build command uses
type DeployOptions struct {
*CommonPushOptions
componentContext string
sourcePath string
ignores []string
EnvSpecificInfo *envinfo.EnvSpecificInfo

// devfile path
DevfilePath string
devObj devfileParser.DevfileObj
DockerfileURL string
DockerfileBytes []byte
namespace string
tag string
ManifestSource []byte

*genericclioptions.Context
}

// NewDeployOptions returns new instance of BuildOptions
// with "default" values for certain values, for example, show is "false"
func NewDeployOptions() *DeployOptions {
return &DeployOptions{
CommonPushOptions: NewCommonPushOptions(),
return &DeployOptions{}
}

// CompleteDevfilePath completes the devfile path from context
func (do *DeployOptions) CompleteDevfilePath() {
if len(do.DevfilePath) > 0 {
do.DevfilePath = filepath.Join(do.componentContext, do.DevfilePath)
} else {
do.DevfilePath = filepath.Join(do.componentContext, "devfile.yaml")
}
}

// Complete completes push args
// Complete completes deploy args
func (do *DeployOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
do.DevfilePath = filepath.Join(do.componentContext, do.DevfilePath)
do.CompleteDevfilePath()
envInfo, err := envinfo.NewEnvSpecificInfo(do.componentContext)
if err != nil {
return errors.Wrap(err, "unable to retrieve configuration information")
Expand All @@ -67,6 +79,7 @@ func (do *DeployOptions) Complete(name string, cmd *cobra.Command, args []string
// Validate validates the push parameters
func (do *DeployOptions) Validate() (err error) {

log.Infof("\nValidation")
// Validate the --tag
if do.tag == "" {
return errors.New("odo deploy requires a tag, in the format <registry>/namespace>/<image>")
Expand All @@ -77,17 +90,12 @@ func (do *DeployOptions) Validate() (err error) {
return err
}

return
}

// Run has the logic to perform the required actions as part of command
func (do *DeployOptions) Run() (err error) {
devObj, err := devfileParser.Parse(do.DevfilePath)
do.devObj, err = devfileParser.Parse(do.DevfilePath)
if err != nil {
return err
}

metadata := devObj.Data.GetMetadata()
metadata := do.devObj.Data.GetMetadata()
dockerfileURL := metadata.Dockerfile
localDir, err := os.Getwd()
if err != nil {
Expand Down Expand Up @@ -125,26 +133,32 @@ func (do *DeployOptions) Run() (err error) {
return errors.New("dockerfile required for build. No 'dockerfile' field found in devfile, or Dockerfile found in project directory")
}

err = do.DevfileBuild()
if err != nil {
return err
}

// Need to add validation?
s := log.Spinner("Validating Manifest URL")
manifestURL := metadata.Manifest
if manifestURL == "" {
s.End(false)
return errors.New("Unable to deploy as alpha.deployment-manifest is not defined in devfile.yaml")
}

err = util.ValidateURL(manifestURL)
if err != nil {
s.End(false)
return errors.New(fmt.Sprintf("Invalid manifest url: %s, %s", manifestURL, err))
}

do.ManifestSource, err = util.DownloadFileInMemory(manifestURL)
if err != nil {
s.End(false)
return errors.New(fmt.Sprintf("Unable to download manifest: %s, %s", manifestURL, err))
}
s.End(true)

return
}

// Run has the logic to perform the required actions as part of command
func (do *DeployOptions) Run() (err error) {
err = do.DevfileDeploy()
if err != nil {
return err
Expand Down Expand Up @@ -178,10 +192,8 @@ func NewCmdDeploy(name, fullName string) *cobra.Command {
genericclioptions.AddContextFlag(deployCmd, &do.componentContext)

// enable devfile flag if experimental mode is enabled
if experimental.IsExperimentalModeEnabled() {
deployCmd.Flags().StringVar(&do.DevfilePath, "devfile", "./devfile.yaml", "Path to a devfile.yaml")
deployCmd.Flags().StringVar(&do.tag, "tag", "", "Tag used to build the image")
}
deployCmd.Flags().StringVar(&do.tag, "tag", "", "Tag used to build the image")
deployCmd.Flags().StringSliceVar(&do.ignores, "ignore", []string{}, "Files or folders to be ignored via glob expressions.")

//Adding `--project` flag
projectCmd.AddProjectFlag(deployCmd)
Expand Down
40 changes: 21 additions & 19 deletions pkg/odo/cli/component/deploy_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
projectCmd "github.com/openshift/odo/pkg/odo/cli/project"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/completion"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/pkg/errors"
"github.com/spf13/cobra"

Expand All @@ -23,34 +22,44 @@ import (
const manifestFile = ".odo/manifest.yaml"

// TODO: add CLI Reference doc
var deployDeleteCmdExample = ktemplates.Examples(` # Deletes deployment from Kubernetes cluster
var deployDeleteCmdExample = ktemplates.Examples(` # Delete deployed component
%[1]s
`)

// DeployDeleteRecommendedCommandName is the recommended build command name
const DeployDeleteRecommendedCommandName = "delete"

// DeployDeleteOptions encapsulates options that deploy delete command uses
type DeployDeleteOptions struct {
*CommonPushOptions
componentContext string
EnvSpecificInfo *envinfo.EnvSpecificInfo

// devfile path
DevfilePath string
namespace string
ManifestPath string
ManifestSource []byte

*genericclioptions.Context
}

// NewDeployDeleteOptions returns new instance of DeployDeleteOptions
// with "default" values for certain values, for example, show is "false"
func NewDeployDeleteOptions() *DeployDeleteOptions {
return &DeployDeleteOptions{
CommonPushOptions: NewCommonPushOptions(),
return &DeployDeleteOptions{}
}

// CompleteDevfilePath completes the devfile path from context
func (ddo *DeployDeleteOptions) CompleteDevfilePath() {
if len(ddo.DevfilePath) > 0 {
ddo.DevfilePath = filepath.Join(ddo.componentContext, ddo.DevfilePath)
} else {
ddo.DevfilePath = filepath.Join(ddo.componentContext, "devfile.yaml")
}
}

// Complete completes push args
func (ddo *DeployDeleteOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
ddo.DevfilePath = filepath.Join(ddo.componentContext, ddo.DevfilePath)
ddo.CompleteDevfilePath()
envInfo, err := envinfo.NewEnvSpecificInfo(ddo.componentContext)
if err != nil {
return errors.Wrap(err, "unable to retrieve configuration information")
Expand All @@ -63,25 +72,23 @@ func (ddo *DeployDeleteOptions) Complete(name string, cmd *cobra.Command, args [

// Validate validates the push parameters
func (ddo *DeployDeleteOptions) Validate() (err error) {
return
}

// Run has the logic to perform the required actions as part of command
func (ddo *DeployDeleteOptions) Run() (err error) {
// ddo.componentContext, .odo, manifest.yaml
// TODO: Check manifest is actually there!!!
// read bytes into deployDeleteOptions
if _, err := os.Stat(manifestFile); os.IsNotExist(err) {
return errors.Wrap(err, "manifest file at "+manifestFile+" does not exist")
}

manifestSource, err := ioutil.ReadFile(manifestFile)
ddo.ManifestSource, err = ioutil.ReadFile(manifestFile)
if err != nil {
return err
}
ddo.ManifestPath = manifestFile
ddo.ManifestSource = manifestSource
return
}

// Run has the logic to perform the required actions as part of command
func (ddo *DeployDeleteOptions) Run() (err error) {
err = ddo.DevfileDeployDelete()
if err != nil {
return err
Expand All @@ -106,11 +113,6 @@ func NewCmdDeployDelete(name, fullName string) *cobra.Command {
}
genericclioptions.AddContextFlag(deployDeleteCmd, &ddo.componentContext)

// enable devfile flag if experimental mode is enabled
if experimental.IsExperimentalModeEnabled() {
deployDeleteCmd.Flags().StringVar(&ddo.DevfilePath, "devfile", "./devfile.yaml", "Path to a devfile.yaml")
}

//Adding `--project` flag
projectCmd.AddProjectFlag(deployDeleteCmd)

Expand Down
61 changes: 8 additions & 53 deletions pkg/odo/cli/component/devfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,12 @@ func (po *PushOptions) DevfilePush() (err error) {
return
}

// DevfileBuild build an image of my application in the cluster
func (do *DeployOptions) DevfileBuild() (err error) {
// Parse devfile
devObj, err := devfileParser.Parse(do.DevfilePath)
if err != nil {
return err
}

//DevfileDeploy
func (do *DeployOptions) DevfileDeploy() (err error) {
componentName, err := getComponentName(do.componentContext)
if err != nil {
return errors.Wrap(err, "unable to get component name")
}
componentName = "build-" + componentName

// Set the source path to either the context or current working directory (if context not set)
do.sourcePath, err = util.GetAbsPath(do.componentContext)
Expand All @@ -124,14 +117,14 @@ func (do *DeployOptions) DevfileBuild() (err error) {
// Apply ignore information
err = genericclioptions.ApplyIgnore(&do.ignores, do.sourcePath)
if err != nil {
return errors.Wrap(err, "unable to apply ignore information")
return errors.Wrap(err, uUnable to apply ignore information")
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
}

kubeContext := kubernetes.KubernetesContext{
Namespace: do.namespace,
}

devfileHandler, err := adapters.NewPlatformAdapter(componentName, do.componentContext, devObj, kubeContext)
devfileHandler, err := adapters.NewPlatformAdapter(componentName, do.componentContext, do.devObj, kubeContext)
if err != nil {
return err
}
Expand All @@ -143,9 +136,7 @@ func (do *DeployOptions) DevfileBuild() (err error) {
EnvSpecificInfo: *do.EnvSpecificInfo,
}

// TODO: I don't think we need to check this here, we could check this on the deploy if we want to expose a URL (odo url create)
warnIfURLSInvalid(do.EnvSpecificInfo.GetURL())

log.Infof("\nBuilding devfile component %s", componentName)
// Build image for the component
err = devfileHandler.Build(buildParams)
if err != nil {
Expand All @@ -156,52 +147,16 @@ func (do *DeployOptions) DevfileBuild() (err error) {
)
os.Exit(1)
}

log.Infof("\nBuilding devfile component %s", componentName)
log.Success("Changes successfully built image for component")

return nil
}

func (do *DeployOptions) DevfileDeploy() (err error) {
// Parse devfile
devObj, err := devfileParser.Parse(do.DevfilePath)
if err != nil {
return err
}

componentName, err := getComponentName(do.componentContext)
if err != nil {
return errors.Wrap(err, "unable to get component name")
}

// Set the source path to either the context or current working directory (if context not set)
do.sourcePath, err = util.GetAbsPath(do.componentContext)
if err != nil {
return errors.Wrap(err, "unable to get source path")
}

// Apply ignore information
err = genericclioptions.ApplyIgnore(&do.ignores, do.sourcePath)
if err != nil {
return errors.Wrap(err, "Unable to apply ignore information")
}

kubeContext := kubernetes.KubernetesContext{
Namespace: do.namespace,
}

devfileHandler, err := adapters.NewPlatformAdapter(componentName, do.componentContext, devObj, kubeContext)
if err != nil {
return err
}
log.Success("Successfully built image")

deployParams := common.DeployParameters{
EnvSpecificInfo: *do.EnvSpecificInfo,
Tag: do.tag,
ManifestSource: do.ManifestSource,
}

warnIfURLSInvalid(do.EnvSpecificInfo.GetURL())

// Deploy the application
err = devfileHandler.Deploy(deployParams)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sync/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a Adapter) SyncFilesBuild(buildParameters common.BuildParameters, dockerfi
var s *log.Status
syncFolder := "/"

s = log.Spinner("Checking files for deploy")
s = log.Spinner("Checking files for building")
// run the indexer and find the project source files
files, err := util.DeployRunIndexer(buildParameters.Path, absIgnoreRules)
if len(files) > 0 {
Expand Down
Loading