mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
feat(templates): support env variables in Compose stacks
This commit is contained in:
parent
c8c54cf991
commit
e15da005a5
8 changed files with 58 additions and 19 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"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"
|
||||
|
@ -35,19 +36,31 @@ func (manager *ComposeStackManager) Up(stack *portainer.Stack, endpoint *portain
|
|||
TLSCAFile: endpoint.TLSCACertPath,
|
||||
TLSCertFile: endpoint.TLSCertPath,
|
||||
TLSKeyFile: endpoint.TLSKeyPath,
|
||||
APIVersion: "1.24",
|
||||
APIVersion: portainer.SupportedDockerAPIVersion,
|
||||
})
|
||||
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.EnvfileLookup{
|
||||
Path: filepath.Join(stack.ProjectPath, ".env"),
|
||||
EnvironmentLookup: &lookup.ComposableEnvLookup{
|
||||
Lookups: []config.EnvironmentLookup{
|
||||
&lookup.EnvfileLookup{
|
||||
Path: filepath.Join(stack.ProjectPath, ".env"),
|
||||
},
|
||||
&lookup.MapLookup{
|
||||
Vars: env,
|
||||
},
|
||||
},
|
||||
},
|
||||
ProjectName: stack.Name,
|
||||
},
|
||||
|
@ -69,7 +82,7 @@ func (manager *ComposeStackManager) Down(stack *portainer.Stack, endpoint *porta
|
|||
TLSCAFile: endpoint.TLSCACertPath,
|
||||
TLSCertFile: endpoint.TLSCertPath,
|
||||
TLSKeyFile: endpoint.TLSKeyPath,
|
||||
APIVersion: "1.24",
|
||||
APIVersion: portainer.SupportedDockerAPIVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue