awslabs/aws-athena-query-federation

[FEATURE] Remove shaded jar file from the container image

Aberta

#2.410 aberto em 19 de nov. de 2024

 (2 comentários) (0 reação) (0 responsável)Java (346 forks)auto 404
enhancementgood first issue

Métricas do repositório

Stars
 (611 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

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

Guia do colaborador