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

Add Buildkit Option #434

Merged
merged 6 commits into from
Dec 5, 2022
Merged

Add Buildkit Option #434

merged 6 commits into from
Dec 5, 2022

Conversation

guineveresaenger
Copy link
Contributor

This PR makes an opinionated choice about Docker Buildkit.
Background: The Docker client can run in two separate modes, BuilderV1 which is the classic Docker builder, and BuilderBuildKit, which is the version of the client that providers BuildKit support.
These modes are set via the Version field on the ImageBuildOptions. When this field is unset or nil, the Docker client runs in BuilderV1 mode by default.

In general, it appears as though folks are moving away from using the older Docker builder, and therefore this PR implements the buildkit mode as the default behavior for this resource.
Users may still set their builderVersion to the BuilderV1 mode, but must do so explicitly.
Invalid builder versions will return an error on pulumi up.

This functionality in v3.x.x was handled via the env field, which asked users to provide DOCKER_BUILDKIT=1 as an environment variable for the Docker CLI to pick up.
Since this version of Image relies on the Docker client, not the CLI, this particular field is no longer necessary in this form.
I believe making builderVersion its own schematized type field is a lot more user friendly, more tightly scoped, and allows us to explicitly document this feature.
Furthermore, we will be able to deprecate the env field safely, and it is additionally the hope of this PR author that builderVersion is much more intuitive for users than env

Fixes #422.

  • add buildkit types field
  • Add logic for Builder Version on client. Add input marshaling tests
  • Update Image description
  • Regenerate schema and SDKs

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@viveklak
Copy link
Contributor

viveklak commented Dec 3, 2022

This functionality in v3.x.x was handled via the env field, which asked users to provide DOCKER_BUILDKIT=1 as an environment variable for the Docker CLI to pick up.

I imagine there might be other uses of the env field to pass environment variables/flags to the builder? Or does invoking through the docker client not really recognize those environment variables anyway? That might help define whether we deprecate the field. I agree with your reasoning that specifying the builder explicitly is more intuitive.

@@ -3039,6 +3039,11 @@
},
"description": "An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variablesthat can be accessed like environment variables inside the RUN instruction."
},
"builderVersion": {
"type": "string",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"`BuilderV1` - the first generation builder in docker daemon\n" + "" +
"`BuilderBuildKit - the builder based on moby/buildkit project\n " +
"Defaults to `BuilderBuildKit`.",
TypeSpec: schema.TypeSpec{Type: "string"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment on perhaps representing this as an enum instead?

@t0yv0
Copy link
Member

t0yv0 commented Dec 5, 2022

I have filed a feature request for pulumi/pulumi/sdk/go to build some helper methods to simplify or eliminate the marshaling code here pulumi/pulumi#11530


// build can be nil, a string or an object; we will also use reasonable defaults here.
var build Build
if b.IsNull() {
// use the default build context
//// use the default build context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

@@ -162,7 +163,7 @@ func TestMarshalBuildAndApplyDefaults(t *testing.T) {
"extraOptions": resource.NewArrayProperty([]resource.PropertyValue{}),
})

actual := marshalBuildAndApplyDefaults(input)
actual, _ := marshalBuildAndApplyDefaults(input)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more verbose but could use

actual, err := ...
assert.NoError(t, err)

@t0yv0
Copy link
Member

t0yv0 commented Dec 5, 2022

This makes a lot of sense and LGTM except I echo Vivek's desire to try to make it an enum for better discoverability. I also wonder if we accumulate this in pending release notes somewhere? This would be great to highlight to users as part of release notes ("here's how it used to work, and here is how it works now").

@t0yv0
Copy link
Member

t0yv0 commented Dec 5, 2022

I was also curious about this:

type Build struct {
   ...
   Env            map[string]string `pulumi:"env"`
   Args           map[string]*string `pulumi:"args"` // why *string here? is there a special meaning for nil?
}

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@guineveresaenger
Copy link
Contributor Author

guineveresaenger commented Dec 5, 2022

@t0yv0 - re: the string pointer - yes! pretty much exactly this for ImageBuildOptions which we pass to the Docker client.

},
{
"name": "BuilderBuildKit",
"description": "The builder based on moby/buildkit project",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also mention that this is the default in the description?

@guineveresaenger guineveresaenger merged commit 7cfa185 into master Dec 5, 2022
@guineveresaenger guineveresaenger deleted the buildkit branch December 5, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add BuildKit support for Docker Image
3 participants