[FEATURE] Remove shaded jar file from the container image
#2 410 ouverte le 19 nov. 2024
Métriques du dépôt
- Stars
- (611 étoiles)
- Métriques de merge PR
- (Métriques PR en attente)
Description
Is your feature request related to a problem? If yes, please describe.
Currently, the jar file is not removed from the container image after unpacking the jar. That unnecessarily bloats the resulting image by 30-40MiB.
Describe the solution you'd like
Use a multistage build to unpack the jar file and then only copy the unpacked files to the final image. Also use build arguments to keep version information in one place (and update the release script accordingly). For example, for the Athena connector:
# Use an intermediate build image to unpack the jar
FROM public.ecr.aws/lambda/java:11 AS build
ARG VERSION="2022.47.1"
RUN mkdir /build
WORKDIR /build
# Copy function code and runtime dependencies from Maven layout
COPY target/athena-postgresql-${VERSION}.jar .
# Unpack the jar
RUN jar xf athena-postgresql-${VERSION}.jar && rm -f athena-postgresql-${VERSION}.jar
# Build the runtime image without any unnecessary layers
FROM public.ecr.aws/lambda/java:11
COPY --from=build /build ${LAMBDA_TASK_ROOT}
# Command can be overwritten by providing a different command in the template directly.
# No need to specify here (already defined in athena-postgresql.yaml because has two different handlers)
Describe alternatives you've considered N/A
Additional context N/A