Open danwashusen opened 2 years ago
For anyone interested the following works:
...
RUN mkdir -p /tmp/ric && cd /tmp/ric && \
npm install aws-lambda-ric && \
rm -rf \
node_modules/aws-lambda-ric/deps/curl-*/autom4te.cache \
node_modules/aws-lambda-ric/deps/curl-*/config.log \
node_modules/aws-lambda-ric/deps/curl-*/configure \
node_modules/aws-lambda-ric/deps/curl-*/docs \
node_modules/aws-lambda-ric/deps/curl-*/projects \
node_modules/aws-lambda-ric/deps/curl-*/tests \
node_modules/aws-lambda-ric/deps/curl-*/README
...
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
COPY --from=build-image /tmp/ric/node_modules ${FUNCTION_DIR}/node_modules
Thank's! I'll give it a try
Can you explain why are you installing in the /tmp folder ?
I had a bit of trouble getting my setup working - just sharing a more recent / complete example in case it can be helpful to anybody:
3.17.x
doesn't seem to provide the libexecinfo-dev
package (hence, using 3.16.x
)npx
binary is in /usr/bin
vs /usr/local/bin
# Define custom function directory
ARG FUNCTION_DIR="/function"
ARG IMAGE_TAG="3.16.5"
FROM alpine:${IMAGE_TAG} as build-step
# Set working directory to function root directory
ARG FUNCTION_DIR
WORKDIR ${FUNCTION_DIR}
# Install dependencies
RUN apk --upgrade --no-cache add \
--virtual build-deps \
g++ \
make \
cmake \
unzip \
curl-dev \
automake \
autoconf \
tar \
gzip \
libtool \
libexecinfo-dev \
python3 \
&& apk --no-cache add nodejs npm \
&& npm install -g aws-lambda-ric \
# Clean unused artifacts to reduce image size
&& apk del build-deps \
&& rm -rf \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/autom4te.cache \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/config.log \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/configure \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/docs \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/projects \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*/tests \
/usr/local/lib/node_modules/aws-lambda-ric/deps/curl-*.tar.gz
COPY app.js package.json ${FUNCTION_DIR}
RUN npm install
ENTRYPOINT ["/usr/bin/npx", "aws-lambda-ric"]
CMD [ "app.handler" ]
In an attempt to reduce the time it takes to re-package, I'm looking at installing this tool globally (
npm install -g aws-lambda-ric
) before my function code it copied into the image to take advantage of dockers caching/layering.The suggested solution (below) has no way of taking advantage of dockers layering. As we have to endure constant cURL rebuilds...
It would be great to install it globally in its own step. Docker could then cache the cURL build and developers could spend their time doing something productive...
However this results in errors from the preinstall scripts: