Jets Managed Dockerfile

The Jets Docker build process adds conveniences such as auto-detecting your web framework, building a managed Dockerfile, auto-tagging the image, and making sure the image is Lambda compatible.

Jets uses a multi-stage Docker build process to help keep the final deployment image small. Here is a simplified version of what the generated Dockerfile looks like:

Dockerfile

FROM ruby:3.2.3-slim as base
# ...
FROM base as build
RUN apt-get update && apt-get install -y build-essential
RUN bundle install
# ...

FROM base as deployment
RUN apt-get update && apt-get install -y curl
COPY --from=build /usr/local/bundle /usr/local/bundle
# ...

ENTRYPOINT [ "aws_lambda_ric" ]
CMD [ "handlers/controller.lambda_handler" ]

The Dockerfile is simplified to help understand. The managed Dockerfile is more complex and optimized. In the version above, you can see that Jets uses a multi-stage Docker build process. This keeps the final image size smaller for deployment.

Jets uses different Docker base images depending on the Lambda Package type:

  • Image Package Type: Jets uses the official DockerHub Ruby image, IE: ruby:3.2.3-slim.
  • Zip Package Type: Jets uses the official AWS Lambda Image, IE: public.ecr.aws/lambda/ruby:3.2

The Image Package Type is recommended and is the default. One reason for the default is that CloudFormation can only change package types by deleting and recreating the app. The default Image Package allows for large packages and is more flexible.

For the Zip Package Type, docker build is still used to gem dependencies, Jets create a Lambda Layer, and the final package is a zip.

Reference

The table below covers each setting. Each option is configured with config.OPTION. The config. portion is not shown for conciseness. IE: logger.level vs config.logger.level.

Name Default Description
docker.image nil Prebuilt Docker Image.
docker.tag “:FRIENDLY_TAG-:TIMESTAMP-:GIT_SHA” Docker tag format string.
docker.show_build_command false Show docker build command in the deploy output.
dockerfile.add_deploy_user true Add deploy user and Docker USER deploy:deploy instruction to near the bottom of the Dockerfile. Turning this off will mean the USER will be root. Can be useful for debugging.
dockerfile.build_args.at_top nil Hash of vars you want Jets to use for docker build --build-arg. Added to the top of the Dockerfile.
dockerfile.build_args.build_stage nil Hash of vars you want Jets to use for docker build --build-arg. Added to the build stage of the Dockerfile.
dockerfile.build_args.deployment_stage nil Hash of vars you want Jets to use for docker build --build-arg. Added to the deployment stage of the Dockerfile.
dockerfile.build_args.enable_aws_creds true Enable auto-generated build-args that pass the CodeBuild IAM role to docker build. This allows the commands within the docker build process to have the same AWS access level as the CodeBuild remote runner.
dockerfile.commands.bootsnap nil For Rails, bundle exec bootsnap precompile app/ lib/. For other frameworks, nil.
dockerfile.custom false Allows you to use your own custom Dockerfile. Note, the Dockefile must be compatiable with Jets and Lambda. You are responsible for maintaining and updating it.
dockerfile.gemfile.force_ruby_platform false Adds a RUN bundle config set force_ruby_platform true before the bundle install in the Gemfile. Sometimes this helps fix some gem issues. This makes bundle install much slower. IE: 90s vs 20s.
dockerfile.install.awscli true Install the AWS CLI within the docker build.
dockerfile.apt.packages.all_stages [] Additional apt packages to install for all Docker stages.
dockerfile.apt.packages.build_stage [] Additional apt packages to install during the build Docker stage.
dockerfile.apt.packages.deployment_stage [] Additional apt packages to install during the deployment Docker stage.
dockerfile.auto_packages true Jets auto-detects required packages based on gems and automatically adds them.
dockerfile.copy_for_bundle nil List of folders to copy before the first bundle install. String or Array of Strings. This can be useful for copying files that are needed for the bundle install. IE: An engines folder with a Gemfile using path: engines/engine_name.
dockerfile.image_package.from_base.docker_image nil Full image name, IE: ruby:3.2.3-slim Overrides other settings.
dockerfile.image_package.from_base.image_name “ruby” Base image name without tag.
dockerfile.image_package.from_base.image_tag nil Auto-detected by default. IE: 3.2.3
dockerfile.image_package.from_base.image_variant “slim” Image variant.
dockerfile.image_package.from_base.ruby_version nil Auto-detected by default. IE: 3.2.3
dockerfile.yum.packages.all_stages [] Additional yum packages to install for all Docker stages.
dockerfile.yum.packages.build_stage [] Additional yum packages to install during the build Docker stage.
dockerfile.yum.packages.deployment_stage [] Additional yum packages to install during the deployment Docker stage
dockerfile.zip_package.from_base.docker_image nil Full image name, IE: public.ecr.aws/lambda/ruby:3.2.3 Overrides other settings.
dockerfile.zip_package.from_base.image_name “public.ecr.aws/lambda/ruby” Base image name without tag.
dockerfile.zip_package.from_base.image_tag nil Auto-detected by default. IE: 3.2.3
dockerfile.zip_package.from_base.image_variant nil IE: “slim”. The AWS Lambda Image do not use variants.
dockerfile.zip_package.from_base.ruby_version nil Auto-detected by default. IE: 3.2.3

See Full Config Reference