1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00
portainer/api/stacks/stackbuilders/stack_file_upload_builder.go
andres-portainer bfa27d9103
Some checks are pending
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
chore(code): clean up the code EE-7251 (#11948)
2024-06-18 15:59:12 -03:00

80 lines
2.4 KiB
Go

package stackbuilders
import (
"strconv"
"time"
portainer "github.com/portainer/portainer/api"
httperror "github.com/portainer/portainer/pkg/libhttp/error"
)
type FileUploadMethodStackBuildProcess interface {
// Set general stack information
SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) FileUploadMethodStackBuildProcess
// Set unique stack information, e.g. swarm stack has swarmID, kubernetes stack has namespace
SetUniqueInfo(payload *StackPayload) FileUploadMethodStackBuildProcess
// Deploy stack based on the configuration
Deploy(payload *StackPayload, endpoint *portainer.Endpoint) FileUploadMethodStackBuildProcess
// Save the stack information to database
SaveStack() (*portainer.Stack, *httperror.HandlerError)
// Get response from HTTP request. Use if it is needed
GetResponse() string
// Process the upload file
SetUploadedFile(payload *StackPayload) FileUploadMethodStackBuildProcess
}
type FileUploadMethodStackBuilder struct {
StackBuilder
}
func (b *FileUploadMethodStackBuilder) SetGeneralInfo(payload *StackPayload, endpoint *portainer.Endpoint) FileUploadMethodStackBuildProcess {
stackID := b.dataStore.Stack().GetNextIdentifier()
b.stack.ID = portainer.StackID(stackID)
b.stack.EndpointID = endpoint.ID
b.stack.Status = portainer.StackStatusActive
b.stack.CreationDate = time.Now().Unix()
return b
}
func (b *FileUploadMethodStackBuilder) SetUniqueInfo(payload *StackPayload) FileUploadMethodStackBuildProcess {
return b
}
func (b *FileUploadMethodStackBuilder) SetUploadedFile(payload *StackPayload) FileUploadMethodStackBuildProcess {
if b.hasError() {
return b
}
stackFolder := strconv.Itoa(int(b.stack.ID))
projectPath, err := b.fileService.StoreStackFileFromBytes(stackFolder, b.stack.EntryPoint, payload.StackFileContentBytes)
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 *FileUploadMethodStackBuilder) Deploy(payload *StackPayload, endpoint *portainer.Endpoint) FileUploadMethodStackBuildProcess {
if b.hasError() {
return b
}
// Deploy the stack
if err := b.deploymentConfiger.Deploy(); err != nil {
b.err = httperror.InternalServerError(err.Error(), err)
return b
}
b.doCleanUp = false
return b
}
func (b *FileUploadMethodStackBuilder) GetResponse() string {
return ""
}