1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

refactor(stack): stack build process backend only [EE-4342] (#7750)

This commit is contained in:
Oscar Zhou 2022-10-05 22:33:59 +13:00 committed by GitHub
parent 83a1ce9d2a
commit e9de484c3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 2270 additions and 942 deletions

View file

@ -11,7 +11,8 @@ import (
portainer "github.com/portainer/portainer/api"
httperrors "github.com/portainer/portainer/api/http/errors"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/stackutils"
"github.com/portainer/portainer/api/stacks/deployments"
"github.com/portainer/portainer/api/stacks/stackutils"
)
type stackMigratePayload struct {
@ -189,26 +190,53 @@ func (handler *Handler) migrateStack(r *http.Request, stack *portainer.Stack, ne
}
func (handler *Handler) migrateComposeStack(r *http.Request, stack *portainer.Stack, next *portainer.Endpoint) *httperror.HandlerError {
config, configErr := handler.createComposeDeployConfig(r, stack, next, false)
if configErr != nil {
return configErr
// Create compose deployment config
securityContext, err := security.RetrieveRestrictedRequestContext(r)
if err != nil {
return httperror.InternalServerError("Unable to retrieve info from request context", err)
}
err := handler.deployComposeStack(config, false)
composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfig(securityContext,
stack,
next,
handler.DataStore,
handler.FileService,
handler.StackDeployer,
false,
false)
if err != nil {
return httperror.InternalServerError(err.Error(), err)
}
// Deploy the stack
err = composeDeploymentConfig.Deploy()
if err != nil {
return httperror.InternalServerError(err.Error(), err)
}
return nil
}
func (handler *Handler) migrateSwarmStack(r *http.Request, stack *portainer.Stack, next *portainer.Endpoint) *httperror.HandlerError {
config, configErr := handler.createSwarmDeployConfig(r, stack, next, true, true)
if configErr != nil {
return configErr
// Create swarm deployment config
securityContext, err := security.RetrieveRestrictedRequestContext(r)
if err != nil {
return httperror.InternalServerError("Unable to retrieve info from request context", err)
}
err := handler.deploySwarmStack(config)
swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(securityContext,
stack,
next,
handler.DataStore,
handler.FileService,
handler.StackDeployer,
true,
true)
if err != nil {
return httperror.InternalServerError(err.Error(), err)
}
// Deploy the stack
err = swarmDeploymentConfig.Deploy()
if err != nil {
return httperror.InternalServerError(err.Error(), err)
}