Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate extraOptions and env #468

Merged
merged 7 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dockerfile-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func main() {
ImageName: pulumi.String("pulumi-user/example:v1.0.0"),
Build: docker.DockerBuildArgs{
Target: pulumi.String("dependencies"),
Env: pulumi.StringMap{
"TEST_ENV": pulumi.String("42"),
Args: pulumi.StringMap{
"TEST_ARG": pulumi.String("42"),
},
},
SkipPush: pulumi.Bool(true),
Expand Down
2 changes: 1 addition & 1 deletion examples/dockerfile-py/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
image_name="pulumi-user/example:v1.0.0",
build=DockerBuildArgs(
target="dependencies",
env={'TEST_ENV': '42'},
args={'TEST_ARG': '42'},
),
skip_push=True,
)
Expand Down
2 changes: 1 addition & 1 deletion examples/dockerfile-with-targets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const myDependenciesImage = new docker.Image("my-image", {
imageName: "pulumi-user/example:v1.0.0",
build: {
target: "dependencies",
env: { "TEST_ENV": "42" },
args: { "TEST_ARG": "42" },
},
skipPush: true,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ static Task<int> Main()
ImageName = "pulumi-user/example:v1.0.0",
Build = new DockerBuildArgs
{
Env = new Dictionary<string, string>
Args = new Dictionary<string, string>
{
{"TEST_ENV", "42"},
{"TEST_ARG", "42"},
},
Target = "dependencies",
},
Expand Down
14 changes: 0 additions & 14 deletions provider/cmd/pulumi-resource-docker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3074,20 +3074,6 @@
"description": "The path to the Dockerfile to use.",
"default": "Dockerfile"
},
"env": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build."
},
"extraOptions": {
"type": "array",
"items": {
"type": "string"
},
"description": "A bag of extra options to pass on to the docker SDK."
},
"target": {
"type": "string",
"description": "The target of the Dockerfile to build"
Expand Down
27 changes: 0 additions & 27 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ type Build struct {
Context string
Dockerfile string
CachedImages []string
Env map[string]string
Args map[string]*string
ExtraOptions []string
Target string
BuilderVersion types.BuilderVersion
}
Expand Down Expand Up @@ -301,20 +299,9 @@ func marshalBuildAndApplyDefaults(b resource.PropertyValue) (Build, error) {
}
build.BuilderVersion = version

// Envs
build.Env = marshalEnvs(buildObject["env"])

// Args
build.Args = marshalArgs(buildObject["args"])

// ExtraOptions
if !buildObject["extraOptions"].IsNull() {
opts := buildObject["extraOptions"].ArrayValue()
for _, v := range opts {
build.ExtraOptions = append(build.ExtraOptions, v.StringValue())
}
}

// Target
if !buildObject["target"].IsNull() {
build.Target = buildObject["target"].StringValue()
Expand Down Expand Up @@ -375,20 +362,6 @@ func marshalArgs(a resource.PropertyValue) map[string]*string {
return args
}

func marshalEnvs(e resource.PropertyValue) map[string]string {
envs := make(map[string]string)
if !e.IsNull() {
for k, v := range e.ObjectValue() {
key := fmt.Sprintf("%v", k)
envs[key] = v.StringValue()
}
}
if len(envs) == 0 {
return nil
}
return envs
}

func marshalBuilder(builder resource.PropertyValue) (types.BuilderVersion, error) {
var version types.BuilderVersion

Expand Down
81 changes: 0 additions & 81 deletions provider/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,64 +125,6 @@ func TestMarshalBuildAndApplyDefaults(t *testing.T) {
assert.NoError(t, err)
})

t.Run("Setting Env", func(t *testing.T) {

expected := Build{
Context: ".",
Dockerfile: "Dockerfile",
Env: map[string]string{
"Strawberry": "fruit",
},
BuilderVersion: "2",
}

input := resource.NewObjectProperty(resource.PropertyMap{
"env": resource.NewObjectProperty(resource.PropertyMap{
"Strawberry": resource.NewStringProperty("fruit"),
}),
})

actual, err := marshalBuildAndApplyDefaults(input)
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})

t.Run("Sets Extra Options", func(t *testing.T) {
expected := Build{
Context: ".",
Dockerfile: "Dockerfile",
ExtraOptions: []string{"cat", "dog", "pot-bellied pig"},
BuilderVersion: "2",
}

input := resource.NewObjectProperty(resource.PropertyMap{
"extraOptions": resource.NewArrayProperty([]resource.PropertyValue{
resource.NewStringProperty("cat"),
resource.NewStringProperty("dog"),
resource.NewStringProperty("pot-bellied pig"),
}),
})

actual, err := marshalBuildAndApplyDefaults(input)
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})

t.Run("Does Not Set Extra Options on Empty Input", func(t *testing.T) {
expected := Build{
Context: ".",
Dockerfile: "Dockerfile",
BuilderVersion: "2",
}

input := resource.NewObjectProperty(resource.PropertyMap{
"extraOptions": resource.NewArrayProperty([]resource.PropertyValue{}),
})

actual, err := marshalBuildAndApplyDefaults(input)
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})
t.Run("Sets Target", func(t *testing.T) {
expected := Build{
Context: ".",
Expand Down Expand Up @@ -256,29 +198,6 @@ func TestMarshalArgs(t *testing.T) {
})
}

func TestMarshalEnvs(t *testing.T) {
t.Run("Set any environment variables", func(t *testing.T) {
expected := map[string]string{
"Strawberry": "fruit",
"Carrot": "veggie",
"Docker": "a bit of a mess tbh",
}
input := resource.NewObjectProperty(resource.PropertyMap{
"Strawberry": resource.NewStringProperty("fruit"),
"Carrot": resource.NewStringProperty("veggie"),
"Docker": resource.NewStringProperty("a bit of a mess tbh"),
})
actual := marshalEnvs(input)
assert.Equal(t, expected, actual)
})
t.Run("Returns nil when no environment variables set", func(t *testing.T) {
expected := map[string]string(nil)
input := resource.NewObjectProperty(resource.PropertyMap{})
actual := marshalEnvs(input)
assert.Equal(t, expected, actual)
})
}

func TestMarshalCachedImages(t *testing.T) {
t.Run("Test Cached Images", func(t *testing.T) {
expected := []string{"apple", "banana", "cherry"}
Expand Down
19 changes: 0 additions & 19 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ func Provider() tfbridge.ProviderInfo {
Ref: "#/types/docker:index/cacheFrom:CacheFrom",
},
},
"env": {
Description: "Environment variables to set on the invocation of docker build, " +
"for example to support DOCKER_BUILDKIT=1 docker build.",
TypeSpec: schema.TypeSpec{
Type: "object",
AdditionalProperties: &schema.TypeSpec{
Type: "string",
},
},
},
"args": {
Description: "An optional map of named build-time argument variables to set " +
"during the Docker build. This flag allows you to pass built-time variables" +
Expand All @@ -178,15 +168,6 @@ func Provider() tfbridge.ProviderInfo {
},
},
},
"extraOptions": {
Description: "A bag of extra options to pass on to the docker SDK.",
TypeSpec: schema.TypeSpec{
Type: "array",
Items: &schema.TypeSpec{
Type: "string",
},
},
},
"target": {
Description: "The target of the Dockerfile to build",
TypeSpec: schema.TypeSpec{Type: "string"},
Expand Down
24 changes: 0 additions & 24 deletions sdk/dotnet/Inputs/DockerBuildArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,6 @@ public InputMap<string> Args
[Input("dockerfile")]
public Input<string>? Dockerfile { get; set; }

[Input("env")]
private InputMap<string>? _env;

/// <summary>
/// Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.
/// </summary>
public InputMap<string> Env
{
get => _env ?? (_env = new InputMap<string>());
set => _env = value;
}

[Input("extraOptions")]
private InputList<string>? _extraOptions;

/// <summary>
/// A bag of extra options to pass on to the docker SDK.
/// </summary>
public InputList<string> ExtraOptions
{
get => _extraOptions ?? (_extraOptions = new InputList<string>());
set => _extraOptions = value;
}

/// <summary>
/// The target of the Dockerfile to build
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions sdk/go/docker/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading