|
1 | | -# Use Amazon Linux 2 base image explicitly |
2 | | -FROM amazonlinux:2 |
| 1 | +# Stage 1: Build dependencies |
| 2 | +FROM amazonlinux:2 AS builder |
3 | 3 |
|
4 | | -# Install Node.js 20 (to match AWS Lambda runtime) |
5 | | -RUN curl -fsSL https://rpm.nodesource.com/setup_20.x | bash - && \ |
6 | | - yum install -y nodejs && \ |
7 | | - npm install -g npm@latest |
8 | | - |
9 | | -WORKDIR /build |
10 | | - |
11 | | -# Declare build arguments |
12 | | -ARG TARGET_ARCH |
13 | | -ARG TARGET_PLATFORM=linux |
14 | | - |
15 | | -# Install build dependencies for sharp and libvips |
| 4 | +# Install dependencies for libvips |
16 | 5 | RUN yum update -y && \ |
17 | 6 | yum install -y gcc-c++ make python3 pkgconf tar gzip && \ |
18 | 7 | # Install libvips and its dependencies |
19 | 8 | yum install -y libvips libvips-devel && \ |
20 | 9 | # Clean up to reduce layer size |
21 | 10 | yum clean all && rm -rf /var/cache/yum |
22 | 11 |
|
| 12 | +# Stage 2: Final image |
| 13 | +FROM public.ecr.aws/lambda/nodejs:20 |
| 14 | + |
| 15 | +WORKDIR /build |
| 16 | + |
| 17 | +# Copy libvips libraries from builder stage |
| 18 | +COPY --from=builder /usr/lib64/libvips*.so* /usr/lib64/ |
| 19 | +COPY --from=builder /usr/lib64/libglib-2.0*.so* /usr/lib64/ |
| 20 | +COPY --from=builder /usr/lib64/libgobject-2.0*.so* /usr/lib64/ |
| 21 | +COPY --from=builder /usr/lib64/libgmodule-2.0*.so* /usr/lib64/ |
| 22 | +COPY --from=builder /usr/lib64/libffi*.so* /usr/lib64/ |
| 23 | + |
| 24 | +# Declare build arguments |
| 25 | +ARG TARGET_ARCH |
| 26 | +ARG TARGET_PLATFORM=linux |
| 27 | + |
23 | 28 | # Verify build environment |
24 | 29 | RUN echo "Building for architecture: ${TARGET_ARCH}" && \ |
25 | 30 | echo "Target platform: ${TARGET_PLATFORM}" |
|
0 commit comments