Skip to content
Permalink
Browse files
feat(images-dependencies): introduce basic image dependencies configu…
…ration structs
  • Loading branch information
distorhead committed Jan 25, 2022
1 parent 525db42 commit da36104fdf9aa5d2223d1bde0464e4af582eb88a
@@ -0,0 +1,8 @@
package config

type Dependency struct {
ImageName string
Imports []*DependencyImport

// TODO: raw *rawDependencies
}
@@ -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
}
@@ -0,0 +1,9 @@
package config

type DependencyImportType string

const (
ImageNameImport DependencyImportType = "ImageName"
ImageTagImport DependencyImportType = "ImageTag"
ImageRepoImport DependencyImportType = "ImageRepo"
)
@@ -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
}
@@ -2,4 +2,5 @@ package config

type ImageInterface interface {
GetName() string
IsStapel() bool
}
@@ -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
}

0 comments on commit da36104

Please sign in to comment.