refactoring

This commit is contained in:
Dmitry Salakhov
2021-07-28 13:09:37 +12:00
parent 6703b340f3
commit d7fe7ab6fe
9 changed files with 72 additions and 61 deletions

View File

@@ -2,7 +2,6 @@ package stacks
import (
"fmt"
"log"
"net/http"
"path"
"strconv"
@@ -16,7 +15,6 @@ import (
"github.com/portainer/portainer/api/filesystem"
gittypes "github.com/portainer/portainer/api/git/types"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/stacks"
)
type composeStackFromFileContentPayload struct {
@@ -116,8 +114,9 @@ type composeStackFromGitRepositoryPayload struct {
// Path to the Stack file inside the Git repository
ComposeFile string `example:"docker-compose.yml" default:"docker-compose.yml"`
// Applicable when deploying with multiple stack files
AdditionalFiles []string
AutoUpdate *portainer.StackAutoUpdate
AdditionalFiles []string `example:"[nz.compose.yml, uat.compose.yml]"`
// Optional auto update configuration
AutoUpdate *portainer.StackAutoUpdate
// A list of environment variables used during stack deployment
Env []portainer.Pair
}
@@ -226,15 +225,10 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite
}
if payload.AutoUpdate != nil && payload.AutoUpdate.Interval != "" {
d, err := time.ParseDuration(payload.AutoUpdate.Interval)
if err != nil {
return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Unable to parse auto update interval", Err: err}
jobID, e := startAutoupdate(stack.ID, stack.AutoUpdate.Interval, handler.Scheduler, handler.StackDeployer, handler.DataStore, handler.GitService)
if e != nil {
return e
}
jobID := handler.Scheduler.StartJobEvery(d, func() {
if err := stacks.RedeployWhenChanged(stack.ID, handler.StackDeployer, handler.DataStore, handler.GitService); err != nil {
log.Printf("[ERROR] %s\n", err)
}
})
stack.AutoUpdate.JobID = jobID
}