mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
refactor(stack): stack build process backend only [EE-4342] (#7750)
This commit is contained in:
parent
83a1ce9d2a
commit
e9de484c3e
65 changed files with 2270 additions and 942 deletions
82
api/stacks/stackbuilders/swarm_file_content_builder.go
Normal file
82
api/stacks/stackbuilders/swarm_file_content_builder.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package stackbuilders
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/filesystem"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/stacks/deployments"
|
||||
)
|
||||
|
||||
type SwarmStackFileContentBuilder struct {
|
||||
FileContentMethodStackBuilder
|
||||
SecurityContext *security.RestrictedRequestContext
|
||||
}
|
||||
|
||||
// CreateSwarmStackFileContentBuilder creates a builder for the swarm stack that will be deployed by file content method
|
||||
func CreateSwarmStackFileContentBuilder(securityContext *security.RestrictedRequestContext,
|
||||
dataStore dataservices.DataStore,
|
||||
fileService portainer.FileService,
|
||||
stackDeployer deployments.StackDeployer) *SwarmStackFileContentBuilder {
|
||||
|
||||
return &SwarmStackFileContentBuilder{
|
||||
FileContentMethodStackBuilder: FileContentMethodStackBuilder{
|
||||
StackBuilder: CreateStackBuilder(dataStore, fileService, stackDeployer),
|
||||
},
|
||||
SecurityContext: securityContext,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *SwarmStackFileContentBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) FileContentMethodStackBuildProcess {
|
||||
b.FileContentMethodStackBuilder.SetGeneralInfo(payload, endpoint)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *SwarmStackFileContentBuilder) SetUniqueInfo(payload *StackPayload) FileContentMethodStackBuildProcess {
|
||||
if b.hasError() {
|
||||
return b
|
||||
}
|
||||
b.stack.Name = payload.Name
|
||||
b.stack.Type = portainer.DockerSwarmStack
|
||||
b.stack.SwarmID = payload.SwarmID
|
||||
b.stack.EntryPoint = filesystem.ComposeFileDefaultName
|
||||
b.stack.Env = payload.Env
|
||||
b.stack.FromAppTemplate = payload.FromAppTemplate
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *SwarmStackFileContentBuilder) SetFileContent(payload *StackPayload) FileContentMethodStackBuildProcess {
|
||||
if b.hasError() {
|
||||
return b
|
||||
}
|
||||
|
||||
stackFolder := strconv.Itoa(int(b.stack.ID))
|
||||
projectPath, err := b.fileService.StoreStackFileFromBytes(stackFolder, b.stack.EntryPoint, []byte(payload.StackFileContent))
|
||||
if err != nil {
|
||||
b.err = httperror.InternalServerError("Unable to persist Compose file on disk", err)
|
||||
return b
|
||||
}
|
||||
b.stack.ProjectPath = projectPath
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *SwarmStackFileContentBuilder) Deploy(payload *StackPayload, endpoint *portainer.Endpoint) FileContentMethodStackBuildProcess {
|
||||
if b.hasError() {
|
||||
return b
|
||||
}
|
||||
|
||||
swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, true)
|
||||
if err != nil {
|
||||
b.err = httperror.InternalServerError(err.Error(), err)
|
||||
return b
|
||||
}
|
||||
|
||||
b.deploymentConfiger = swarmDeploymentConfig
|
||||
b.stack.CreatedBy = b.deploymentConfiger.GetUsername()
|
||||
|
||||
return b.FileContentMethodStackBuilder.Deploy(payload, endpoint)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue