Fix instance updating
This commit is contained in:
parent
b2c12ac9be
commit
8bd44cd91e
9 changed files with 64 additions and 73 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel/drush"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/mstore"
|
||||
"github.com/tkw1536/pkglib/stream"
|
||||
)
|
||||
|
||||
|
|
@ -15,13 +17,25 @@ type Composer struct {
|
|||
ingredient.Base
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
// PHP *php.PHP
|
||||
MStore *mstore.MStore
|
||||
Drush *drush.Drush
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes a composer command
|
||||
// Exec executes a composer command for the main composer package.
|
||||
// Returns an error iff composer does not exit with 0.
|
||||
func (composer *Composer) Exec(ctx context.Context, progress io.Writer, command ...string) error {
|
||||
if err := composer.Dependencies.Barrel.ShellScript(ctx, stream.NonInteractive(progress), append([]string{"composer", "--no-interaction", "--working-dir", barrel.ComposerDirectory}, command...)...); err != nil {
|
||||
return composer.exec(ctx, progress, append([]string{"--working-dir", barrel.ComposerDirectory}, command...)...)
|
||||
}
|
||||
|
||||
// Exec executes a composer command for the wisski directory.
|
||||
// Returns an error iff composer does not exit with 0.
|
||||
func (composer *Composer) ExecWissKI(ctx context.Context, progress io.Writer, command ...string) error {
|
||||
return composer.exec(ctx, progress, append([]string{"--working-dir", barrel.WissKIDirectory}, command...)...)
|
||||
}
|
||||
|
||||
func (composer *Composer) exec(ctx context.Context, progress io.Writer, command ...string) error {
|
||||
if err := composer.Dependencies.Barrel.ShellScript(ctx, stream.NonInteractive(progress), append([]string{"composer", "--no-interaction"}, command...)...); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -37,7 +51,9 @@ func (composer *Composer) FixPermission(ctx context.Context, progress io.Writer)
|
|||
// Install attempts runs 'composer require' with the given arguments
|
||||
// Spec is like a specification on the command line.
|
||||
func (composer *Composer) Install(ctx context.Context, progress io.Writer, args ...string) error {
|
||||
composer.FixPermission(ctx, progress)
|
||||
if err := composer.FixPermission(ctx, progress); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requires := append([]string{"require"}, args...)
|
||||
if err := composer.Exec(ctx, progress, requires...); err != nil {
|
||||
|
|
|
|||
89
internal/wisski/ingredient/barrel/composer/update.go
Normal file
89
internal/wisski/ingredient/barrel/composer/update.go
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package composer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/mstore"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
var errBlindUpdateFailed = exit.Error{
|
||||
Message: "failed to run blind update script for instance %q",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
// Update performs a blind drush update
|
||||
func (composer *Composer) Update(ctx context.Context, progress io.Writer) (err error) {
|
||||
defer errBlindUpdateFailed.WithMessageF(composer.Slug).DeferWrap(&err)
|
||||
|
||||
if err := composer.FixPermission(ctx, progress); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(progress, "Updating Packages")
|
||||
{
|
||||
err := composer.Exec(ctx, progress, "update")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(progress, "Installing database updates")
|
||||
{
|
||||
err := composer.Dependencies.Drush.Exec(ctx, progress, "-y", "updatedb")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(progress, "Updating WissKI Packages")
|
||||
{
|
||||
err := composer.Exec(ctx, progress, "update")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return composer.setLastUpdate(ctx)
|
||||
}
|
||||
|
||||
const lastUpdate = mstore.For[int64]("lastUpdate")
|
||||
|
||||
func (drush *Composer) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastUpdate.Get(ctx, drush.Dependencies.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
// and turn it into time!
|
||||
return time.Unix(epoch, 0), nil
|
||||
}
|
||||
|
||||
func (drush *Composer) setLastUpdate(ctx context.Context) error {
|
||||
return lastUpdate.Set(ctx, drush.Dependencies.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastUpdateFetcher struct {
|
||||
ingredient.Base
|
||||
Dependencies struct {
|
||||
Composer *Composer
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ ingredient.WissKIFetcher = (*LastUpdateFetcher)(nil)
|
||||
)
|
||||
|
||||
func (lbr *LastUpdateFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastUpdate, err = lbr.Dependencies.Composer.LastUpdate(flags.Context)
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue