Jets Dockerfile Stage Hooks
Note: This is experimental feature. Looking for feedback on the feature it may change the way it works. The interface may break.
Jets uses a multi-stage Docker build process. This keeps the final image size small for deployment. You also have the ability to “inject” code right into the Dockerfile at various Dockerfile stage hook points.
Stage Hooks
- config/jets/dockerfile/stage/before_build
- config/jets/dockerfile/stage/after_build
- config/jets/dockerfile/stage/before_deployment
- config/jets/dockerfile/stage/after_deployment
Example
Here’s a simplified example Dockerfile with multiple stages to help explain. There’s a FROM base as build
stage and a FROM base as deployment
stage.
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" ]
Here’s how you add code to a specific stage.
config/jets/dockerfile/stage/before_build
RUN apt-get update && apt-get install -y libpq-dev postgresql-client
The code is literally added to the Dockerfile as one of the first steps to the stage. IE: The code is added to the Dockerfile after the FROM base as build
, Jets installs system packages, and user defined packages from config.docker.packages
. The resulting Dockerfile.
Dockerfile
FROM ruby:3.2.3-slim as base
# ...
FROM base as build
RUN apt-get update && apt-get install -y build-essential
RUN apt-get update && apt-get install -y libpq-dev postgresql-client # <===== ADDED
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" ]
Dockerfile
FROM ruby:3.2.3-slim as base
# ...
FROM base as build
RUN apt-get update && apt-get install -y build-essential
# BEFORE_BUILD POINT # <===== ADDED
RUN bundle install
# ...
# AFTER_BUILD POINT # <===== ADDED
FROM base as deployment
RUN apt-get update && apt-get install -y curl
# BEFORE_DEPLOYMENT POINT # <===== ADDED
COPY --from=build /usr/local/bundle /usr/local/bundle
# ...
# AFTER_DEPLOYMENT POINT # <===== ADDED
ENTRYPOINT [ "aws_lambda_ric" ]
CMD [ "handlers/controller.lambda_handler" ]