mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
feat(stacks): support automated sync for stacks [EE-248] (#5340)
This commit is contained in:
parent
5fe90db36a
commit
bcccdfb669
94 changed files with 2680 additions and 469 deletions
34
api/stacks/scheduled.go
Normal file
34
api/stacks/scheduled.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
)
|
||||
|
||||
func StartStackSchedules(scheduler *scheduler.Scheduler, stackdeployer StackDeployer, datastore portainer.DataStore, gitService portainer.GitService) error {
|
||||
stacks, err := datastore.Stack().RefreshableStacks()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to fetch refreshable stacks")
|
||||
}
|
||||
for _, stack := range stacks {
|
||||
d, err := time.ParseDuration(stack.AutoUpdate.Interval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Unable to parse auto update interval")
|
||||
}
|
||||
jobID := scheduler.StartJobEvery(d, func() {
|
||||
if err := RedeployWhenChanged(stack.ID, stackdeployer, datastore, gitService); err != nil {
|
||||
log.Printf("[ERROR] %s\n", err)
|
||||
}
|
||||
})
|
||||
|
||||
stack.AutoUpdate.JobID = jobID
|
||||
if err := datastore.Stack().UpdateStack(stack.ID, &stack); err != nil {
|
||||
return errors.Wrap(err, "failed to update stack job id")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue