Skip to content

Commit

Permalink
feat(images-dependencies): introduce basic image dependencies configu…
Browse files Browse the repository at this point in the history
…ration structs
  • Loading branch information
distorhead committed Jan 25, 2022
1 parent 525db42 commit da36104
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/config/dependency.go
@@ -0,0 +1,8 @@
package config

type Dependency struct {
ImageName string
Imports []*DependencyImport

// TODO: raw *rawDependencies
}
31 changes: 31 additions & 0 deletions pkg/config/dependency_import.go
@@ -0,0 +1,31 @@
package config

import (
"fmt"
"strings"
)

type DependencyImport struct {
Type DependencyImportType
TargetBuildArg string
TargetEnv string

// TODO: raw *rawDependencyImport
}

func (i *DependencyImport) validate(img ImageInterface) error {
switch {
case img.IsStapel() && i.TargetBuildArg != "":
return newDetailedConfigError("`targetBuildArg cannot be used in the stapel image", nil, nil) // TODO: raw
case !img.IsStapel() && i.TargetEnv != "":
return newDetailedConfigError("`targetEnv cannot be used in the dockerfile image", nil, nil) // TODO: raw
}

switch i.Type {
case ImageNameImport, ImageTagImport, ImageRepoImport:
default:
return newDetailedConfigError(fmt.Sprintf("invalid `type: %s` for dependency import, expected one of: %s", i.Type, strings.Join([]string{string(ImageNameImport), string(ImageTagImport), string(ImageRepoImport)}, ", ")), nil, nil) // TODO: raw
}

return nil
}
9 changes: 9 additions & 0 deletions pkg/config/dependency_import_type.go
@@ -0,0 +1,9 @@
package config

type DependencyImportType string

const (
ImageNameImport DependencyImportType = "ImageName"
ImageTagImport DependencyImportType = "ImageTag"
ImageRepoImport DependencyImportType = "ImageRepo"
)
4 changes: 4 additions & 0 deletions pkg/config/image_from_dockerfile.go
Expand Up @@ -42,3 +42,7 @@ func (c *ImageFromDockerfile) validate(giterminismManager giterminism_manager.In
func (c *ImageFromDockerfile) GetName() string {
return c.Name
}

func (c *ImageFromDockerfile) IsStapel() bool {
return false
}
1 change: 1 addition & 0 deletions pkg/config/image_interface.go
Expand Up @@ -2,4 +2,5 @@ package config

type ImageInterface interface {
GetName() string
IsStapel() bool
}
4 changes: 4 additions & 0 deletions pkg/config/stapel_image_base.go
Expand Up @@ -28,6 +28,10 @@ func (c *StapelImageBase) GetName() string {
return c.Name
}

func (c *StapelImageBase) IsStapel() bool {
return true
}

func (c *StapelImageBase) imports() []*Import {
return c.Import
}
Expand Down

0 comments on commit da36104

Please sign in to comment.