Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8e944cb

Browse files
Extract cnab-run environment variables as constants.
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
1 parent 0010dc8 commit 8e944cb

6 files changed

Lines changed: 16 additions & 7 deletions

File tree

cmd/cnab-run/env.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
)
1313

1414
const (
15-
envVarOchestrator = "DOCKER_STACK_ORCHESTRATOR"
1615
fileDockerContext = "/cnab/app/context.dockercontext"
1716
)
1817

cmd/cnab-run/install.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"github.com/deislabs/duffle/pkg/bundle"
9+
"github.com/docker/app/internal"
910
"github.com/docker/app/internal/packager"
1011
"github.com/docker/app/render"
1112
"github.com/docker/cli/cli/command"
@@ -34,7 +35,7 @@ func installAction(instanceName string) error {
3435
}
3536
defer app.Cleanup()
3637

37-
orchestratorRaw := os.Getenv(envVarOchestrator)
38+
orchestratorRaw := os.Getenv(internal.DockerStackOrchestratorEnvVar)
3839
orchestrator, err := cli.StackOrchestrator(orchestratorRaw)
3940
if err != nil {
4041
return err
@@ -62,7 +63,7 @@ func installAction(instanceName string) error {
6263
func getFlagset(orchestrator command.Orchestrator) *pflag.FlagSet {
6364
result := pflag.NewFlagSet("", pflag.ContinueOnError)
6465
if orchestrator == command.OrchestratorKubernetes {
65-
result.String("namespace", os.Getenv("DOCKER_KUBERNETES_NAMESPACE"), "")
66+
result.String("namespace", os.Getenv(internal.DockerKubernetesNamespaceEnvVar), "")
6667
}
6768
return result
6869
}

cmd/cnab-run/status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55

6+
"github.com/docker/app/internal"
67
"github.com/docker/cli/cli/command/stack"
78
"github.com/docker/cli/cli/command/stack/options"
89
"github.com/docker/cli/opts"
@@ -14,7 +15,7 @@ func statusAction(instanceName string) error {
1415
if err != nil {
1516
return errors.Wrap(err, "unable to restore docker context")
1617
}
17-
orchestratorRaw := os.Getenv(envVarOchestrator)
18+
orchestratorRaw := os.Getenv(internal.DockerStackOrchestratorEnvVar)
1819
orchestrator, err := cli.StackOrchestrator(orchestratorRaw)
1920
if err != nil {
2021
return err

cmd/cnab-run/uninstall.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55

6+
"github.com/docker/app/internal"
67
"github.com/docker/cli/cli/command/stack"
78
"github.com/docker/cli/cli/command/stack/options"
89
"github.com/pkg/errors"
@@ -13,7 +14,7 @@ func uninstallAction(instanceName string) error {
1314
if err != nil {
1415
return errors.Wrap(err, "unable to restore docker context")
1516
}
16-
orchestratorRaw := os.Getenv(envVarOchestrator)
17+
orchestratorRaw := os.Getenv(internal.DockerStackOrchestratorEnvVar)
1718
orchestrator, err := cli.StackOrchestrator(orchestratorRaw)
1819
if err != nil {
1920
return err

internal/names.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const (
2424

2525
// Namespace is the reverse DNS namespace used with labels and CNAB custom actions.
2626
Namespace = "com.docker.app."
27+
28+
// DockerStackOrchestratorEnvVar is the environment variable set by the CNAB runtime to select
29+
// the stack orchestrator.
30+
DockerStackOrchestratorEnvVar = "DOCKER_STACK_ORCHESTRATOR"
31+
// DockerKubernetesNamespaceEnvVar is the environment variable set by the CNAB runtime to select
32+
// the kubernetes namespace.
33+
DockerKubernetesNamespaceEnvVar = "DOCKER_KUBERNETES_NAMESPACE"
2734
)
2835

2936
var (

internal/packager/cnab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
2121
},
2222
DefaultValue: "",
2323
Destination: &bundle.Location{
24-
EnvironmentVariable: "DOCKER_STACK_ORCHESTRATOR",
24+
EnvironmentVariable: internal.DockerStackOrchestratorEnvVar,
2525
},
2626
Metadata: &bundle.ParameterMetadata{
2727
Description: "Orchestrator on which to deploy",
@@ -30,7 +30,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
3030
"docker.kubernetes-namespace": {
3131
DataType: "string",
3232
Destination: &bundle.Location{
33-
EnvironmentVariable: "DOCKER_KUBERNETES_NAMESPACE",
33+
EnvironmentVariable: internal.DockerKubernetesNamespaceEnvVar,
3434
},
3535
Metadata: &bundle.ParameterMetadata{
3636
Description: "Namespace in which to deploy",

0 commit comments

Comments
 (0)