barrel: Use default value for base image

This commit is contained in:
Tom Wiesing 2023-06-30 12:34:51 +02:00
parent 5a85494194
commit 154f9a93ea
No known key found for this signature in database
6 changed files with 38 additions and 33 deletions

View file

@ -6,6 +6,7 @@ import (
"strings"
"github.com/FAU-CDI/wisski-distillery/internal/config/validators"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
)
@ -14,29 +15,6 @@ var (
errRestrictedSlug = errors.New("restricted slug")
)
const (
PHP8 = "8.0"
PHP8_IMAGE = "docker.io/library/php:8.0-apache-bullseye"
PHP8_1 = "8.1"
PHP8_1_IMAGE = "docker.io/library/php:8.1-apache-bullseye"
)
var errUnknownPHPVersion = errors.New("unknown php version")
// GetBaseImage returns the php base image to use
func GetBaseImage(php string) (string, error) {
switch php {
case "":
return PHP8_IMAGE, nil
case PHP8:
return PHP8_IMAGE, nil
case PHP8_1:
return PHP8_1_IMAGE, nil
default:
return "", errUnknownPHPVersion
}
}
// Create fills the struct for a new WissKI instance.
// It validates that slug is a valid name for an instance.
//
@ -88,7 +66,7 @@ func (instances *Instances) Create(slug string, phpversion string) (wissKI *wiss
}
// docker image
wissKI.Liquid.Instance.DockerBaseImage, err = GetBaseImage(phpversion)
wissKI.Liquid.Instance.DockerBaseImage, err = models.GetBaseImage(phpversion)
if err != nil {
return nil, err
}

View file

@ -7,6 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/pkglib/fsx"
@ -37,7 +38,7 @@ func (pv *Provision) ValidateFlags(flags ProvisionFlags) error {
return err
}
// check for known php versions
if _, err := instances.GetBaseImage(flags.PHPVersion); err != nil {
if _, err := models.GetBaseImage(flags.PHPVersion); err != nil {
return err
}
return nil

View file

@ -34,11 +34,7 @@
Docker Base Image
</td>
<td>
{{ if .Instance.DockerBaseImage }}
<code>{{ .Instance.DockerBaseImage }}</code>
{{ else }}
(none)
{{ end }}
<code>{{ .Instance.GetDockerBaseImage }}</code>
</td>
</tr>
<tr>

View file

@ -35,7 +35,7 @@ type Instance struct {
FilesystemBase string `gorm:"column:filesystem_base;not null"`
// DockerBaseImage is the php base image to use
DockerBaseImage string `gorm:"column:docker_base;not_null`
DockerBaseImage string `gorm:"column:docker_base;not_null"`
// SQL Database credentials for the system
SqlDatabase string `gorm:"column:sql_database;not null"`
@ -48,6 +48,36 @@ type Instance struct {
GraphDBPassword string `gorm:"column:graphdb_password;not null"`
}
const (
PHP8 = "8.0"
PHP8_IMAGE = "docker.io/library/php:8.0-apache-bullseye"
PHP8_1 = "8.1"
PHP8_1_IMAGE = "docker.io/library/php:8.1-apache-bullseye"
)
var errUnknownPHPVersion = errors.New("unknown php version")
// GetBaseImage returns the php base image to use
func GetBaseImage(php string) (string, error) {
switch php {
case "":
return PHP8_IMAGE, nil
case PHP8:
return PHP8_IMAGE, nil
case PHP8_1:
return PHP8_1_IMAGE, nil
default:
return "", errUnknownPHPVersion
}
}
func (i Instance) GetDockerBaseImage() string {
if i.DockerBaseImage == "" {
return PHP8_IMAGE
}
return i.DockerBaseImage
}
func (i Instance) IsBlindUpdateEnabled() bool {
return bool(i.AutoBlindUpdateEnabled)
}

View file

@ -13,7 +13,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/mstore"
)
// Build builds or rebuilds the barel connected to this instance.
// Build builds or rebuilds the barrel connected to this instance.
//
// It also logs the current time into the metadata belonging to this instance.
func (barrel *Barrel) Build(ctx context.Context, progress io.Writer, start bool) error {

View file

@ -32,7 +32,7 @@ func (barrel *Barrel) Stack() component.StackWithResources {
"DATA_PATH": filepath.Join(barrel.FilesystemBase, "data"),
"RUNTIME_DIR": barrel.Malt.Config.Paths.RuntimeDir(),
"BARREL_BASE_IMAGE": barrel.DockerBaseImage,
"BARREL_BASE_IMAGE": barrel.GetDockerBaseImage(),
},
MakeDirs: []string{"data", ".composer"},