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

Feature request: ability to enable Docker Buildkit for sam build #3972

Closed
ghost opened this issue Jun 14, 2022 · 8 comments
Closed

Feature request: ability to enable Docker Buildkit for sam build #3972

ghost opened this issue Jun 14, 2022 · 8 comments
Labels
area/build sam build command type/feature Feature request

Comments

@ghost
Copy link

ghost commented Jun 14, 2022

Describe your idea/feature/enhancement

I wish SAM CLI would enable me to enable Docker Buildkit when running sam build for a function with PackageType: Image.

This would enable me to use BuildKit features such as cache mounts for faster and more efficient builds.

Proposal

A very specific approach would be to add a new option along the lines of --use-docker-buildkit or something like that.

That said, something more general might be a good idea.

For example, I tried to enable buildkit by running export DOCKER_BUILDKIT=1 && sam build but it didn’t work.

IIRC docker build supports various other environment variables, so it might be a good idea to have a general purpose mechanism to set environment variables that’d be exposed to the docker build process.

One way to do this might be to simply forward/inherit the environment vars from the user’s shell to/into the docker build process.

Another way could be to add a CLI option like --docker-build-env DOCKER_BUILDKIT=1,FOO=bar

Additional Details

This will not require any updates to the SAM Spec.

@ghost ghost added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/feature Feature request labels Jun 14, 2022
@ghost
Copy link
Author

ghost commented Jun 14, 2022

Huh, I just found docker/docker-py#2230 and it looks like bad news… 😞

@qingchm
Copy link
Contributor

qingchm commented Jun 16, 2022

I know it's going to be an interesting feature to support but since our builds are based on docker API for python, unless docker supports buildkit on python api I don't see a quick solution to this!

@qingchm qingchm removed the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jun 16, 2022
@ghost
Copy link
Author

ghost commented Jun 16, 2022

Makes sense. Thanks.

Maybe it’d help if maintainers of downstream libs would comment on that issue? Or otherwise somehow convey to the maintainers of docker-py that support for Buildkit would be great?

Thanks!

@qingchm
Copy link
Contributor

qingchm commented Jun 20, 2022

@aviflat Yep I would assume opening an issue against their repository would be the way to go!

@qingchm qingchm added area/build sam build command and removed maintainer/need-followup labels Jun 20, 2022
@ghost
Copy link
Author

ghost commented Jun 20, 2022

Well, since docker/docker-py#2230 already exists, I was suggesting that one of the maintainers of this project post a comment to that issue, voicing support for the feature.

@mildaniel
Copy link
Contributor

Since there isn't much we can do on our side, I will close this for now but please re-open when this is actionable for us.

@astahlman
Copy link

The lack of BuildKit caching is currently our biggest pain point with SAM. Given that it's been >3.5 years with no progress on the upstream issue in docker-py, would you be open to a PR that replaces the docker-py build call with the docker build CLI command? FWIW, the maintainers recommend using the CLI for builds. This is the approach that docker-compose project took.

Or if you'd rather make the proposed behavior opt-in we could toggle whether we use docker-py or the CLI via a command line flag like --use-docker-buildkit.

@remidebette
Copy link

Hi,
Alternatively, for using the docker cli without reimplementing the wheel, the project https://github.com/gabrieldemarmiesse/python-on-whales readily provides a python wrapper on the CLI.

It works fine with buildx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command type/feature Feature request
Projects
None yet
Development

No branches or pull requests

5 participants