Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Remove shaded jar file from the container image #2410

Open
sergei-ivanov opened this issue Nov 19, 2024 · 1 comment
Open

[FEATURE] Remove shaded jar file from the container image #2410

sergei-ivanov opened this issue Nov 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@sergei-ivanov
Copy link

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

@sergei-ivanov sergei-ivanov added the enhancement New feature or request label Nov 19, 2024
@macohen
Copy link
Contributor

macohen commented Dec 11, 2024

@sergei-ivanov thanks for submitting an issue. Are you willing/able to submit a PR to make this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants