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

Is it possible to install this tool globally (outside the function dir)? #50

Open
danwashusen opened this issue May 11, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@danwashusen
Copy link

danwashusen commented May 11, 2022

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...

# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY myFunction/* ${FUNCTION_DIR}

WORKDIR ${FUNCTION_DIR}

# If the dependency is not in package.json uncomment the following line
# RUN npm install aws-lambda-ric

RUN npm install

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...

# https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/28
RUN mkdir -p /usr/local/lib/node_modules && \
	npm install -g aws-lambda-ric && \
	rm -rf \
	./deps/curl-*/autom4te.cache \
	./deps/curl-*/config.log \
	./deps/curl-*/configure \
	./deps/curl-*/docs \
	./deps/curl-*/projects \
	./deps/curl-*/tests \
	./deps/curl-*/README

RUN mkdir -p "${FUNCTION_DIR}"
COPY ./build/js "${FUNCTION_DIR}"

However this results in errors from the preinstall scripts:

...
#0 22.38 tar: curl-7.78.0/CMake/OtherTests.cmake: Cannot open: No such file or directory
#0 22.38 tar: curl-7.78.0: Cannot mkdir: Permission denied
...

@danwashusen
Copy link
Author

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

@e-tip
Copy link

e-tip commented Sep 23, 2022

Thank's! I'll give it a try

@florentGuiot
Copy link

Can you explain why are you installing in the /tmp folder ?

@lstellway
Copy link

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:

  • Borrowed from @danwashusen's reply to further minimize the image
  • At the time of writing, Alpine 3.17.x doesn't seem to provide the libexecinfo-dev package (hence, using 3.16.x)
  • Note the location of the 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" ]

@andclt andclt added the enhancement New feature or request label Sep 26, 2023
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

5 participants