pool: Reddo component-like fields
This commit is contained in:
parent
99983ee6db
commit
337a5fbeba
48 changed files with 291 additions and 163 deletions
|
|
@ -11,9 +11,10 @@ import (
|
|||
// Barrel provides access to the underlying Barrel
|
||||
type Barrel struct {
|
||||
ingredient.Base
|
||||
|
||||
Locker *locker.Locker
|
||||
MStore *mstore.MStore
|
||||
Dependencies struct {
|
||||
Locker *locker.Locker
|
||||
MStore *mstore.MStore
|
||||
}
|
||||
}
|
||||
|
||||
func (barrel *Barrel) DataPath() string {
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ import (
|
|||
//
|
||||
// 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 {
|
||||
if !barrel.Locker.TryLock(ctx) {
|
||||
if !barrel.Dependencies.Locker.TryLock(ctx) {
|
||||
return locker.Locked
|
||||
}
|
||||
defer barrel.Locker.Unlock(ctx)
|
||||
defer barrel.Dependencies.Locker.Unlock(ctx)
|
||||
|
||||
stack := barrel.Stack()
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ func (barrel *Barrel) Build(ctx context.Context, progress io.Writer, start bool)
|
|||
var lastRebuild = mstore.For[int64]("lastRebuild")
|
||||
|
||||
func (barrel Barrel) LastRebuild(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastRebuild.Get(ctx, barrel.MStore)
|
||||
epoch, err := lastRebuild.Get(ctx, barrel.Dependencies.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -61,16 +61,17 @@ func (barrel Barrel) LastRebuild(ctx context.Context) (t time.Time, err error) {
|
|||
}
|
||||
|
||||
func (barrel *Barrel) setLastRebuild(ctx context.Context) error {
|
||||
return lastRebuild.Set(ctx, barrel.MStore, time.Now().Unix())
|
||||
return lastRebuild.Set(ctx, barrel.Dependencies.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastRebuildFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *Barrel
|
||||
Dependencies struct {
|
||||
Barrel *Barrel
|
||||
}
|
||||
}
|
||||
|
||||
func (lbr *LastRebuildFetcher) Fetch(ctx context.Context, flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastRebuild, _ = lbr.Barrel.LastRebuild(ctx)
|
||||
info.LastRebuild, _ = lbr.Dependencies.Barrel.LastRebuild(ctx)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var errCronFailed = exit.Error{
|
|||
}
|
||||
|
||||
func (drush *Drush) Cron(ctx context.Context, progress io.Writer) error {
|
||||
code := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/cron.sh")()
|
||||
code := drush.Dependencies.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/cron.sh")()
|
||||
if code != 0 {
|
||||
// keep going, because we want to run as many crons as possible
|
||||
logging.ProgressF(progress, ctx, "%v", errCronFailed.WithMessageF(drush.Slug, code))
|
||||
|
|
@ -31,7 +31,7 @@ func (drush *Drush) Cron(ctx context.Context, progress io.Writer) error {
|
|||
|
||||
func (drush *Drush) LastCron(ctx context.Context, server *phpx.Server) (t time.Time, err error) {
|
||||
var timestamp int64
|
||||
err = drush.PHP.EvalCode(ctx, server, ×tamp, `$val = \Drupal::state()->get('system.cron_last'); return $val; `)
|
||||
err = drush.Dependencies.PHP.EvalCode(ctx, server, ×tamp, `$val = \Drupal::state()->get('system.cron_last'); return $val; `)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -40,8 +40,9 @@ func (drush *Drush) LastCron(ctx context.Context, server *phpx.Server) (t time.T
|
|||
|
||||
type LastCronFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Drush *Drush
|
||||
Dependencies struct {
|
||||
Drush *Drush
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -53,6 +54,6 @@ func (lbr *LastCronFetcher) Fetch(flags ingredient.FetcherFlags, info *status.Wi
|
|||
return
|
||||
}
|
||||
|
||||
info.LastRebuild, _ = lbr.Drush.LastCron(flags.Context, flags.Server)
|
||||
info.LastRebuild, _ = lbr.Dependencies.Drush.LastCron(flags.Context, flags.Server)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ import (
|
|||
// Drush implements commands related to drush
|
||||
type Drush struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *barrel.Barrel
|
||||
MStore *mstore.MStore
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
MStore *mstore.MStore
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var errBlindUpdateFailed = exit.Error{
|
|||
|
||||
// Update performs a blind drush update
|
||||
func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
||||
code := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")()
|
||||
code := drush.Dependencies.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")()
|
||||
if code != 0 {
|
||||
return errBlindUpdateFailed.WithMessageF(drush.Slug, code)
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
|||
const lastUpdate = mstore.For[int64]("lastUpdate")
|
||||
|
||||
func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastUpdate.Get(ctx, drush.MStore)
|
||||
epoch, err := lastUpdate.Get(ctx, drush.Dependencies.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -44,13 +44,14 @@ func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
|||
}
|
||||
|
||||
func (drush *Drush) setLastUpdate(ctx context.Context) error {
|
||||
return lastUpdate.Set(ctx, drush.MStore, time.Now().Unix())
|
||||
return lastUpdate.Set(ctx, drush.Dependencies.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastUpdateFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Drush *Drush
|
||||
Dependencies struct {
|
||||
Drush *Drush
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -58,6 +59,6 @@ var (
|
|||
)
|
||||
|
||||
func (lbr *LastUpdateFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastUpdate, err = lbr.Drush.LastUpdate(flags.Context)
|
||||
info.LastUpdate, err = lbr.Dependencies.Drush.LastUpdate(flags.Context)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,16 @@ import (
|
|||
// Instead, this should code directly defined in go.
|
||||
type Provisioner struct {
|
||||
ingredient.Base
|
||||
Barrel *barrel.Barrel
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
}
|
||||
}
|
||||
|
||||
// Provision provisions an instance, assuming that the required databases already exist.
|
||||
func (provision *Provisioner) Provision(ctx context.Context, progress io.Writer) error {
|
||||
|
||||
// build the container
|
||||
if err := provision.Barrel.Build(ctx, progress, false); err != nil {
|
||||
if err := provision.Dependencies.Barrel.Build(ctx, progress, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +57,7 @@ func (provision *Provisioner) Provision(ctx context.Context, progress io.Writer)
|
|||
// TODO: Move the provision script into the control plane!
|
||||
provisionScript := "sudo PATH=$PATH -u www-data /bin/bash /provision_container.sh " + strings.Join(provisionParams, " ")
|
||||
|
||||
code, err := provision.Barrel.Stack().Run(ctx, stream.NonInteractive(progress), true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
code, err := provision.Dependencies.Barrel.Stack().Run(ctx, stream.NonInteractive(progress), true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ func (barrel *Barrel) Running(ctx context.Context, progress io.Writer) (bool, er
|
|||
|
||||
type RunningFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *Barrel
|
||||
Dependencies struct {
|
||||
Barrel *Barrel
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -28,6 +29,6 @@ var (
|
|||
)
|
||||
|
||||
func (rf *RunningFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.Running, err = rf.Barrel.Running(flags.Context, io.Discard)
|
||||
info.Running, err = rf.Dependencies.Barrel.Running(flags.Context, io.Discard)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ import (
|
|||
|
||||
type SSH struct {
|
||||
ingredient.Base
|
||||
Barrel *barrel.Barrel
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -22,7 +24,7 @@ var (
|
|||
)
|
||||
|
||||
func (ssh *SSH) Keys() ([]ssh.PublicKey, error) {
|
||||
file, err := ssh.Environment.Open(ssh.Barrel.AuthorizedKeysPath())
|
||||
file, err := ssh.Environment.Open(ssh.Dependencies.Barrel.AuthorizedKeysPath())
|
||||
if environment.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue