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 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package drush
|
||||
package composer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"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"
|
||||
"github.com/tkw1536/pkglib/stream"
|
||||
)
|
||||
|
||||
var errBlindUpdateFailed = exit.Error{
|
||||
|
|
@ -19,18 +19,43 @@ var errBlindUpdateFailed = exit.Error{
|
|||
}
|
||||
|
||||
// Update performs a blind drush update
|
||||
func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
||||
err := drush.Dependencies.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")
|
||||
if err != nil {
|
||||
return errBlindUpdateFailed.WithMessageF(drush.Slug).Wrap(err)
|
||||
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
|
||||
}
|
||||
|
||||
return drush.setLastUpdate(ctx)
|
||||
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 *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
||||
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
|
||||
|
|
@ -43,14 +68,14 @@ func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
|||
return time.Unix(epoch, 0), nil
|
||||
}
|
||||
|
||||
func (drush *Drush) setLastUpdate(ctx context.Context) error {
|
||||
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 {
|
||||
Drush *Drush
|
||||
Composer *Composer
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +84,6 @@ var (
|
|||
)
|
||||
|
||||
func (lbr *LastUpdateFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastUpdate, err = lbr.Dependencies.Drush.LastUpdate(flags.Context)
|
||||
info.LastUpdate, err = lbr.Dependencies.Composer.LastUpdate(flags.Context)
|
||||
return
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ 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/mstore"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
|
||||
"github.com/tkw1536/pkglib/stream"
|
||||
)
|
||||
|
|
@ -16,7 +15,6 @@ type Drush struct {
|
|||
ingredient.Base
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
MStore *mstore.MStore
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel/composer"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/pkglib/stream"
|
||||
|
|
@ -166,7 +165,7 @@ func (manager *Manager) applyWissKI(ctx context.Context, progress io.Writer, wis
|
|||
// install dependencies in the WissKI directory
|
||||
logging.LogMessage(progress, "Installing WissKI Dependencies")
|
||||
{
|
||||
if err := manager.Dependencies.Barrel.ShellScript(ctx, stream.NonInteractive(progress), "composer", "--working-dir", barrel.WissKIDirectory, "install"); err != nil {
|
||||
if err := manager.Dependencies.Composer.ExecWissKI(ctx, progress, "install"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ func (wisski *WissKI) Drush() *drush.Drush {
|
|||
return export[*drush.Drush](wisski)
|
||||
}
|
||||
|
||||
func (wisski *WissKI) Composer() *composer.Composer {
|
||||
return export[*composer.Composer](wisski)
|
||||
}
|
||||
|
||||
func (wisski *WissKI) Users() *users.Users {
|
||||
return export[*users.Users](wisski)
|
||||
}
|
||||
|
|
@ -127,7 +131,7 @@ func (wisski *WissKI) allIngredients() []initFunc {
|
|||
}),
|
||||
auto[*barrel.LastRebuildFetcher],
|
||||
auto[*barrel.RunningFetcher],
|
||||
auto[*drush.LastUpdateFetcher],
|
||||
auto[*composer.LastUpdateFetcher],
|
||||
auto[*drush.LastCronFetcher],
|
||||
auto[*info.SnapshotsFetcher],
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue