Skip to content

Dockerfile Outerloop Support #580

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

Merged
merged 7 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
513 changes: 505 additions & 8 deletions crds/workspace.devfile.io_devworkspaces.v1beta1.yaml

Large diffs are not rendered by default.

513 changes: 505 additions & 8 deletions crds/workspace.devfile.io_devworkspaces.yaml

Large diffs are not rendered by default.

496 changes: 488 additions & 8 deletions crds/workspace.devfile.io_devworkspacetemplates.v1beta1.yaml

Large diffs are not rendered by default.

496 changes: 488 additions & 8 deletions crds/workspace.devfile.io_devworkspacetemplates.yaml

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions pkg/apis/workspaces/v1alpha1/commands_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,36 @@ func convertCommandTo_v1alpha2(src *Command, dest *v1alpha2.Command) error {
return nil
}

// getGroup returns the group the command belongs to
func getGroup(dc v1alpha2.Command) *v1alpha2.CommandGroup {
switch {
case dc.Composite != nil:
return dc.Composite.Group
case dc.Exec != nil:
return dc.Exec.Group
case dc.Apply != nil:
return dc.Apply.Group
case dc.Custom != nil:
return dc.Custom.Group

default:
return nil
}
}

func convertCommandFrom_v1alpha2(src *v1alpha2.Command, dest *Command) error {
if src == nil {
return nil
}

id := src.Key()

srcCmdGroup := getGroup(*src)
if srcCmdGroup != nil && srcCmdGroup.Kind == v1alpha2.DeployCommandGroupKind {
// skip converting deploy kind commands as deploy kind commands are not supported in v1alpha1
return nil
}

jsonCommand, err := json.Marshal(src)
if err != nil {
return err
Expand Down
27 changes: 27 additions & 0 deletions pkg/apis/workspaces/v1alpha1/commands_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ func TestCommandConversion_v1alpha1(t *testing.T) {
}
}
}

func TestCommandConversionFrom_v1alpha2(t *testing.T) {

src := &v1alpha2.Command{
Id: "test1",
CommandUnion: v1alpha2.CommandUnion{
Exec: &v1alpha2.ExecCommand{
LabeledCommand: v1alpha2.LabeledCommand{
BaseCommand: v1alpha2.BaseCommand{
Group: &v1alpha2.CommandGroup{
Kind: v1alpha2.DeployCommandGroupKind,
},
},
},
},
},
}

output := &Command{}

err := convertCommandFrom_v1alpha2(src, output)
if !assert.NoError(t, err, "Should not return error when converting from v1alpha2") {
return
}

assert.Equal(t, &Command{}, output, "Conversion from v1alpha2 should be skipped for deploy kind command")
}
3 changes: 3 additions & 0 deletions pkg/apis/workspaces/v1alpha1/components_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func convertComponentFrom_v1alpha2(src *v1alpha2.Component, dest *Component) err
if src.Plugin != nil {
// Need to handle plugin components separately.
return convertPluginComponentFrom_v1alpha2(src, dest)
} else if src.Image != nil {
// Skip converting an Image component since v1alpha1 does not have an Image component
return nil
}
name := src.Key()
jsonComponent, err := json.Marshal(src)
Expand Down
22 changes: 22 additions & 0 deletions pkg/apis/workspaces/v1alpha1/components_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,25 @@ func TestComponentConversion_v1alpha1(t *testing.T) {
}
}
}

func TestComponentConversionFrom_v1alpha2(t *testing.T) {

src := &v1alpha2.Component{
Name: "test1",
ComponentUnion: v1alpha2.ComponentUnion{
Image: &v1alpha2.ImageComponent{
Image: v1alpha2.Image{
ImageName: "image:latest",
},
},
},
}
output := &Component{}

err := convertComponentFrom_v1alpha2(src, output)
if !assert.NoError(t, err, "Should not return error when converting from v1alpha2") {
return
}

assert.Equal(t, &Component{}, output, "Conversion from v1alpha2 should be skipped for Image Component")
}
11 changes: 6 additions & 5 deletions pkg/apis/workspaces/v1alpha2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ const (
)

// CommandGroupKind describes the kind of command group.
// +kubebuilder:validation:Enum=build;run;test;debug
// +kubebuilder:validation:Enum=build;run;test;debug;deploy
type CommandGroupKind string

const (
BuildCommandGroupKind CommandGroupKind = "build"
RunCommandGroupKind CommandGroupKind = "run"
TestCommandGroupKind CommandGroupKind = "test"
DebugCommandGroupKind CommandGroupKind = "debug"
BuildCommandGroupKind CommandGroupKind = "build"
RunCommandGroupKind CommandGroupKind = "run"
TestCommandGroupKind CommandGroupKind = "test"
DebugCommandGroupKind CommandGroupKind = "debug"
DeployCommandGroupKind CommandGroupKind = "deploy"
)

type CommandGroup struct {
Expand Down
38 changes: 38 additions & 0 deletions pkg/apis/workspaces/v1alpha2/component_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v1alpha2

// ImageType describes the type of image.
// Only one of the following image type may be specified.
// +kubebuilder:validation:Enum=Dockerfile
type ImageType string

const (
DockerfileImageType ImageType = "Dockerfile"
)

type BaseImage struct {
}

// Component that allows the developer to build a runtime image for outerloop
type ImageComponent struct {
BaseComponent `json:",inline"`
Image `json:",inline"`
}

type Image struct {
// Name of the image for the resulting outerloop build
ImageName string `json:"imageName"`
ImageUnion `json:",inline"`
}

// +union
type ImageUnion struct {
// Type of image
//
// +unionDiscriminator
// +optional
ImageType ImageType `json:"imageType,omitempty"`

// Allows specifying dockerfile type build
// +optional
Dockerfile *DockerfileImage `json:"dockerfile,omitempty"`
}
81 changes: 81 additions & 0 deletions pkg/apis/workspaces/v1alpha2/component_image_dockerfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package v1alpha2

// DockerfileSrcType describes the type of
// the src for the Dockerfile outerloop build.
// Only one of the following location type may be specified.
// +kubebuilder:validation:Enum=Uri;DevfileRegistry;Git
type DockerfileSrcType string

const (
UriLikeDockerfileSrcType DockerfileSrcType = "Uri"
DevfileRegistryLikeDockerfileSrcType DockerfileSrcType = "DevfileRegistry"
GitLikeDockerfileSrcType DockerfileSrcType = "Git"
)

// Dockerfile Image type to specify the outerloop build using a Dockerfile
type DockerfileImage struct {
BaseImage `json:",inline"`
DockerfileSrc `json:",inline"`
Dockerfile `json:",inline"`
}

// +union
type DockerfileSrc struct {
// Type of Dockerfile src
// +
// +unionDiscriminator
// +optional
SrcType DockerfileSrcType `json:"srcType,omitempty"`

// URI Reference of a Dockerfile.
// It can be a full URL or a relative URI from the current devfile as the base URI.
// +optional
Uri string `json:"uri,omitempty"`

// Dockerfile's Devfile Registry source
// +optional
DevfileRegistry *DockerfileDevfileRegistrySource `json:"devfileRegistry,omitempty"`

// Dockerfile's Git source
// +optional
Git *DockerfileGitProjectSource `json:"git,omitempty"`
}

type Dockerfile struct {
// Path of source directory to establish build context. Defaults to ${PROJECT_ROOT} in the container
// +optional
BuildContext string `json:"buildContext,omitempty"`

// The arguments to supply to the dockerfile build.
// +optional
Args []string `json:"args,omitempty" patchStrategy:"replace"`

// Specify if a privileged builder pod is required.
//
// Default value is `false`
// +optional
RootRequired *bool `json:"rootRequired,omitempty"`
}

type DockerfileDevfileRegistrySource struct {
// Id in a devfile registry that contains a Dockerfile. The src in the OCI registry
// required for the Dockerfile build will be downloaded for building the image.
Id string `json:"id"`

// Devfile Registry URL to pull the Dockerfile from when using the Devfile Registry as Dockerfile src.
// To ensure the Dockerfile gets resolved consistently in different environments,
// it is recommended to always specify the `devfileRegistryUrl` when `Id` is used.
// +optional
RegistryUrl string `json:"registryUrl,omitempty"`
}

type DockerfileGitProjectSource struct {
// Git src for the Dockerfile build. The src required for the Dockerfile build will need to be
// cloned for building the image.
GitProjectSource `json:",inline"`

// Location of the Dockerfile in the Git repository when using git as Dockerfile src.
// Defaults to Dockerfile.
// +optional
FileLocation string `json:"fileLocation,omitempty"`
}
7 changes: 6 additions & 1 deletion pkg/apis/workspaces/v1alpha2/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// ComponentType describes the type of component.
// Only one of the following component type may be specified.
// +kubebuilder:validation:Enum=Container;Kubernetes;Openshift;Volume;Plugin;Custom
// +kubebuilder:validation:Enum=Container;Kubernetes;Openshift;Volume;Image;Plugin;Custom
type ComponentType string

const (
Expand All @@ -16,6 +16,7 @@ const (
OpenshiftComponentType ComponentType = "Openshift"
PluginComponentType ComponentType = "Plugin"
VolumeComponentType ComponentType = "Volume"
ImageComponentType ComponentType = "Image"
CustomComponentType ComponentType = "Custom"
)

Expand Down Expand Up @@ -72,6 +73,10 @@ type ComponentUnion struct {
// +optional
Volume *VolumeComponent `json:"volume,omitempty"`

// Allows specifying the definition of an image for outer loop builds
// +optional
Image *ImageComponent `json:"image,omitempty"`

// Allows importing a plugin.
//
// Plugins are mainly imported devfiles that contribute components, commands
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/workspaces/v1alpha2/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type GitLikeProjectSource struct {
CheckoutFrom *CheckoutFrom `json:"checkoutFrom,omitempty"`

// The remotes map which should be initialized in the git project.
// Projects must have at least one remote configured while StarterProjects can only have at most one remote configured.
// Projects must have at least one remote configured while StarterProjects & Image Component's Git source can only have at most one remote configured.
Remotes map[string]string `json:"remotes"`
}

Expand Down
Loading