mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 06:19:41 +02:00
* feat(compose): add docker-compose wrapper ce-187 * fix(compose): pick compose implementation upon startup * Add static compose build for linux * Fix wget * Fix platofrm specific docker-compose download * Keep amd64 architecture as download parameter * Add tmp folder for docker-compose * fix: line endings * add proxy server * logs * Proxy * Add lite transport for compose * Fix local deployment * refactor: pass proxyManager by ref * fix: string conversion * refactor: compose wrapper remove unused code * fix: tests * Add edge * Fix merge issue * refactor: remove unused code * Move server to proxy implementation * Cleanup wrapper and manager * feat: pass max supported compose syntax version with each endpoint * fix: pick compose syntax version * fix: store wrapper version in portainer * Get and show composeSyntaxMaxVersion at stack creation screen * Get and show composeSyntaxMaxVersion at stack editor screen * refactor: proxy server * Fix used tmp * Bump docker-compose to 1.28.0 * remove message for docker compose limitation * fix: markup typo * Rollback docker compose to 1.27.4 * * attempt to fix the windows build issue * * attempt to debug grunt issue * * use console log in grunt file * fix: try to fix windows build by removing indirect deps from go.mod * Remove tmp folder * Remove builder stage * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose - fixed verbose output * refactor: renames * fix(stack): get endpoint by EndpointProvider * fix(stack): use margin to add space between line instead of using br tag Co-authored-by: Stéphane Busso <stephane.busso@gmail.com> Co-authored-by: Simon Meng <simon.meng@portainer.io> Co-authored-by: yi-portainer <yi.chen@portainer.io> Co-authored-by: Steven Kang <skan070@gmail.com>
126 lines
3.6 KiB
Go
126 lines
3.6 KiB
Go
package libcompose
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/portainer/libcompose/config"
|
|
"github.com/portainer/libcompose/docker"
|
|
"github.com/portainer/libcompose/docker/client"
|
|
"github.com/portainer/libcompose/docker/ctx"
|
|
"github.com/portainer/libcompose/lookup"
|
|
"github.com/portainer/libcompose/project"
|
|
"github.com/portainer/libcompose/project/options"
|
|
portainer "github.com/portainer/portainer/api"
|
|
)
|
|
|
|
const (
|
|
dockerClientVersion = "1.24"
|
|
composeSyntaxMaxVersion = "2"
|
|
)
|
|
|
|
// ComposeStackManager represents a service for managing compose stacks.
|
|
type ComposeStackManager struct {
|
|
dataPath string
|
|
reverseTunnelService portainer.ReverseTunnelService
|
|
}
|
|
|
|
// NewComposeStackManager initializes a new ComposeStackManager service.
|
|
func NewComposeStackManager(dataPath string, reverseTunnelService portainer.ReverseTunnelService) *ComposeStackManager {
|
|
return &ComposeStackManager{
|
|
dataPath: dataPath,
|
|
reverseTunnelService: reverseTunnelService,
|
|
}
|
|
}
|
|
|
|
func (manager *ComposeStackManager) createClient(endpoint *portainer.Endpoint) (client.Factory, error) {
|
|
|
|
endpointURL := endpoint.URL
|
|
if endpoint.Type == portainer.EdgeAgentOnDockerEnvironment {
|
|
tunnel := manager.reverseTunnelService.GetTunnelDetails(endpoint.ID)
|
|
endpointURL = fmt.Sprintf("tcp://127.0.0.1:%d", tunnel.Port)
|
|
}
|
|
|
|
clientOpts := client.Options{
|
|
Host: endpointURL,
|
|
APIVersion: dockerClientVersion,
|
|
}
|
|
|
|
if endpoint.TLSConfig.TLS {
|
|
clientOpts.TLS = endpoint.TLSConfig.TLS
|
|
clientOpts.TLSVerify = !endpoint.TLSConfig.TLSSkipVerify
|
|
clientOpts.TLSCAFile = endpoint.TLSConfig.TLSCACertPath
|
|
clientOpts.TLSCertFile = endpoint.TLSConfig.TLSCertPath
|
|
clientOpts.TLSKeyFile = endpoint.TLSConfig.TLSKeyPath
|
|
}
|
|
|
|
return client.NewDefaultFactory(clientOpts)
|
|
}
|
|
|
|
// ComposeSyntaxMaxVersion returns the maximum supported version of the docker compose syntax
|
|
func (manager *ComposeStackManager) ComposeSyntaxMaxVersion() string {
|
|
return composeSyntaxMaxVersion
|
|
}
|
|
|
|
// Up will deploy a compose stack (equivalent of docker-compose up)
|
|
func (manager *ComposeStackManager) Up(stack *portainer.Stack, endpoint *portainer.Endpoint) error {
|
|
|
|
clientFactory, err := manager.createClient(endpoint)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
env := make(map[string]string)
|
|
for _, envvar := range stack.Env {
|
|
env[envvar.Name] = envvar.Value
|
|
}
|
|
|
|
composeFilePath := path.Join(stack.ProjectPath, stack.EntryPoint)
|
|
proj, err := docker.NewProject(&ctx.Context{
|
|
ConfigDir: manager.dataPath,
|
|
Context: project.Context{
|
|
ComposeFiles: []string{composeFilePath},
|
|
EnvironmentLookup: &lookup.ComposableEnvLookup{
|
|
Lookups: []config.EnvironmentLookup{
|
|
&lookup.EnvfileLookup{
|
|
Path: filepath.Join(stack.ProjectPath, ".env"),
|
|
},
|
|
&lookup.MapLookup{
|
|
Vars: env,
|
|
},
|
|
},
|
|
},
|
|
ProjectName: stack.Name,
|
|
},
|
|
ClientFactory: clientFactory,
|
|
}, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return proj.Up(context.Background(), options.Up{})
|
|
}
|
|
|
|
// Down will shutdown a compose stack (equivalent of docker-compose down)
|
|
func (manager *ComposeStackManager) Down(stack *portainer.Stack, endpoint *portainer.Endpoint) error {
|
|
clientFactory, err := manager.createClient(endpoint)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
composeFilePath := path.Join(stack.ProjectPath, stack.EntryPoint)
|
|
proj, err := docker.NewProject(&ctx.Context{
|
|
Context: project.Context{
|
|
ComposeFiles: []string{composeFilePath},
|
|
ProjectName: stack.Name,
|
|
},
|
|
ClientFactory: clientFactory,
|
|
}, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return proj.Down(context.Background(), options.Down{RemoveVolume: false, RemoveOrphans: true})
|
|
}
|