question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: ability to enable Docker Buildkit for `sam build`

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
astahlmancommented, Sep 12, 2022

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.

1reaction
aviflatcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam build - AWS Serverless Application Model
Build an AWS SAM application using the sam build command from the AWS SAM CLI. ... to configure Docker image settings that are...
Read more >
BuildKit - Docker Documentation
To enable docker BuildKit by default, set daemon configuration in /etc/docker/daemon.json feature to true and restart the daemon. If the daemon.json file doesn' ......
Read more >
Docker BuildKit: faster builds, new features, and now it's stable
BuildKit is Docker's new system for building images. It's faster, has previously missing security featuers, and it's finally stable.
Read more >
Caching for docker-in-docker builds (#17861) · Issues - GitLab
@gajus We will able to docker pull foo && docker build --cache-from ... I would like to enable the registry pull through cache...
Read more >
Create and upload a Docker image with a Dockerfile
Overview Dockerfiles are text files that store the commands you would execute on the command line inside a container to create a Docker...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found