Add support for php 8.1

This commit adds optional support for basing images on php 8.1 as
opposed to php 8.0.
This commit is contained in:
Tom Wiesing 2023-06-29 11:05:40 +02:00 committed by Tom
parent 3ef9c23a0c
commit d114c8fafe
12 changed files with 91 additions and 9 deletions

View file

@ -14,11 +14,34 @@ 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.
//
// It does not perform any checks if the instance already exists, or does the creation in the database.
func (instances *Instances) Create(slug string) (wissKI *wisski.WissKI, err error) {
func (instances *Instances) Create(slug string, phpversion string) (wissKI *wisski.WissKI, err error) {
// make sure that the slug is valid!
slug, err = instances.IsValidSlug(slug)
@ -64,6 +87,12 @@ func (instances *Instances) Create(slug string) (wissKI *wisski.WissKI, err erro
return nil, err
}
// docker image
wissKI.Liquid.Instance.DockerBaseImage, err = GetBaseImage(phpversion)
if err != nil {
return nil, err
}
// store the instance in the object and return it!
return wissKI, nil
}

View file

@ -37,7 +37,7 @@ func (purger *Purger) Purge(ctx context.Context, out io.Writer, slug string) err
instance, err := purger.Dependencies.Instances.WissKI(ctx, slug)
if err == instances.ErrWissKINotFound {
fmt.Fprintln(out, "Not found in bookkeeping table, assuming defaults")
instance, err = purger.Dependencies.Instances.Create(slug)
instance, err = purger.Dependencies.Instances.Create(slug, "")
}
if err != nil {
return errPurgeNoDetails.WithMessageF(err)

View file

@ -22,11 +22,27 @@ type Provision struct {
// ProvisionFlags are flags for a new instance
type ProvisionFlags struct {
// Slug is the slug of the wisski instance
Slug string
// PHP Version to use
PHPVersion string
}
var ErrInstanceAlreadyExists = errors.New("instance with provided slug already exists")
func (pv *Provision) ValidateFlags(flags ProvisionFlags) error {
// check the slug
if _, err := pv.Dependencies.Instances.IsValidSlug(flags.Slug); err != nil {
return err
}
// check for known php versions
if _, err := instances.GetBaseImage(flags.PHPVersion); err != nil {
return err
}
return nil
}
// Provision provisions a new docker compose instance.
func (pv *Provision) Provision(progress io.Writer, ctx context.Context, flags ProvisionFlags) (*wisski.WissKI, error) {
// check that it doesn't already exist
@ -36,7 +52,7 @@ func (pv *Provision) Provision(progress io.Writer, ctx context.Context, flags Pr
}
// make it in-memory
instance, err := pv.Dependencies.Instances.Create(flags.Slug)
instance, err := pv.Dependencies.Instances.Create(flags.Slug, flags.PHPVersion)
if err != nil {
return nil, err
}

View file

@ -29,6 +29,18 @@
<a href="{{ .Info.URL }}" target="_blank" rel="noopener noreferrer">{{ .Info.URL }}</a>
</td>
</tr>
<tr>
<td>
Docker Base Image
</td>
<td>
{{ if .Instance.DockerBaseImage }}
<code>{{ .Instance.DockerBaseImage }}</code>
{{ else }}
(none)
{{ end }}
</td>
</tr>
<tr>
<td>
Running

View file

@ -34,6 +34,9 @@ type Instance struct {
// The filesystem path the system can be found under
FilesystemBase string `gorm:"column:filesystem_base;not null"`
// DockerBaseImage is the php base image to use
DockerBaseImage string `gorm:"column:docker_base;not_null`
// SQL Database credentials for the system
SqlDatabase string `gorm:"column:sql_database;not null"`
SqlUsername string `gorm:"column:sql_user;not null"`

View file

@ -6,4 +6,5 @@ WISSKI_HOSTNAME=${HOSTNAME}
HOST_RULE=${HOST_RULE}
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
HTTPS_ENABLED=${HTTPS_ENABLED}
HTTPS_ENABLED=${HTTPS_ENABLED}
BARREL_BASE_IMAGE=${BARREL_BASE_IMAGE}

View file

@ -1,4 +1,5 @@
FROM docker.io/library/php:8.0-apache-bullseye
ARG BARREL_BASE_IMAGE
FROM $BARREL_BASE_IMAGE
ARG COMPOSER_VERSION=2.3.8
WORKDIR /var/www

View file

@ -2,7 +2,11 @@ version: "3.7"
services:
barrel:
build: .
build:
context: .
args:
BARREL_BASE_IMAGE: ${BARREL_BASE_IMAGE}
restart: always
hostname: ${WISSKI_HOSTNAME}

View file

@ -85,6 +85,18 @@ function composer_install_and_enable() {
done
}
function try_variants() {
for var in "$@"
do
if composer require --dry-run "$var" > /dev/null 2>&1; then
composer require "$var"
return 0;
fi
done
return 1;
}
# Create a new composer project.
log_info " => Creating composer project"
@ -99,7 +111,7 @@ composer --no-interaction config allow-plugins true
# Install drush so that we can automate a lot of things
log_info " => Installing 'drush'"
composer require drush/drush
try_variants 'drush/drush' 'drush/drush:^12' 'drush/drush:^11' || (echo "No version of Drush is installable" && false)
# Use 'drush' to run the site-installation.
# Here we need to use the username, password and database creds we made above.

View file

@ -31,6 +31,8 @@ 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,
},
MakeDirs: []string{"data", ".composer"},