aws / copilot-cli

The AWS Copilot CLI is a tool for developers to build, release and operate production ready containerized applications on AWS App Runner or Amazon ECS on AWS Fargate.
https://aws.github.io/copilot-cli/
Apache License 2.0
3.48k stars 400 forks source link

Build zstd compressed container images by default #4087

Open efekarakus opened 1 year ago

efekarakus commented 1 year ago

In our internal testing of zstd compressed container images on AWS Fargate, we have seen up to a 27% reduction in Amazon ECS Task or Kubernetes Pod startup times. The reduction in startup time varies by container image, with the larger container images seeing the greatest improvement. https://aws.amazon.com/blogs/containers/reducing-aws-fargate-startup-times-with-zstd-compressed-container-images/

We should explore enabling by default zstd compression while building the container image. We can check if docker buildx is present and if so build with the flags mentioned in the blog post:

docker buildx build \
  --file Dockerfile \
  --output type=image,name=$IMAGE_URI:$IMAGE_TAG,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true,push=true .

Otherwise, we'll default to the regular docker build that's currently done.

For our pipelines, I believe we would need to update the buildspec.yml to automatically download the buildx plugin: https://github.com/docker/buildx#linux-packages

We can test the performance with a sample Ruby on Rails application which should be a pretty large container image.

genbit commented 1 year ago

Is this something that is present in CodeBuild and could be used as is in pipelines?

efekarakus commented 1 year ago

I haven't tested if buildx is present in CodeBuild but I think even if it's not it should be possible to use it in pipelines.
We can download the plugin ourselves in the buildspec so that it's always present for customers. From then on running docker buildx should work.