1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

feat(libstack): expose env vars with PORTAINER_ prefix [BE-11661] (#687)

This commit is contained in:
Devon Steenberg 2025-05-12 11:18:04 +12:00 committed by GitHub
parent 9fdc535d6b
commit 1abdf42f99
3 changed files with 232 additions and 0 deletions

View file

@ -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 {