feat(libstack): expose env vars with PORTAINER_ prefix [BE-11661] (#687)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -29,6 +30,8 @@ import (
|
||||
|
||||
const PortainerEdgeStackLabel = "io.portainer.edge_stack_id"
|
||||
|
||||
const portainerEnvVarsPrefix = "PORTAINER_"
|
||||
|
||||
var mu sync.Mutex
|
||||
|
||||
func init() {
|
||||
@@ -322,11 +325,19 @@ func createProject(ctx context.Context, configFilepaths []string, options libsta
|
||||
envFiles = append(envFiles, options.EnvFilePath)
|
||||
}
|
||||
|
||||
var osPortainerEnvVars []string
|
||||
for _, ev := range os.Environ() {
|
||||
if strings.HasPrefix(ev, portainerEnvVarsPrefix) {
|
||||
osPortainerEnvVars = append(osPortainerEnvVars, ev)
|
||||
}
|
||||
}
|
||||
|
||||
projectOptions, err := cli.NewProjectOptions(configFilepaths,
|
||||
cli.WithWorkingDirectory(workingDir),
|
||||
cli.WithName(options.ProjectName),
|
||||
cli.WithoutEnvironmentResolution,
|
||||
cli.WithResolvedPaths(!slices.Contains(options.ConfigOptions, "--no-path-resolution")),
|
||||
cli.WithEnv(osPortainerEnvVars),
|
||||
cli.WithEnv(options.Env),
|
||||
cli.WithEnvFiles(envFiles...),
|
||||
func(o *cli.ProjectOptions) error {
|
||||
|
||||
Reference in New Issue
Block a user