Skip to content

Commit

Permalink
Update node12 permissions for npm install
Browse files Browse the repository at this point in the history
Moves to an npm install without using a root user and chmod.

This was causing significant delay when using huge modules like
the AWS SDK.

If this affects you in some way, just raise an issue and we
will look into it.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Feb 15, 2021
1 parent a7cda77 commit d50ca50
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions template/node12/Dockerfile
Expand Up @@ -10,24 +10,21 @@ RUN chmod +x /usr/bin/fwatchdog
RUN apk --no-cache add curl ca-certificates \
&& addgroup -S app && adduser -S -g app app

WORKDIR /root/

# Turn down the verbosity to default level.
ENV NPM_CONFIG_LOGLEVEL warn

RUN mkdir -p /home/app
RUN chmod 777 /tmp

USER app

RUN mkdir -p /home/app/function

# Wrapper/boot-strapper
WORKDIR /home/app
COPY package.json ./

# This ordering means the npm installation is cached for the outer function handler.
RUN npm i
# chmod for tmp is for a buildkit issue (@alexellis)
RUN chown app:app -R /home/app \
&& chmod 777 /tmp

USER app

# Copy outer function handler
COPY index.js ./
Expand All @@ -38,7 +35,7 @@ COPY index.js ./
WORKDIR /home/app/function
COPY function/*.json ./

RUN npm i || :
RUN npm i

This comment has been minimized.

Copy link
@mrsimonemms

mrsimonemms Feb 18, 2021

If we want to make this faster, we should use npm ci. This puts a requirement on there being a package-lock.json file, although that's been standard for some time


# COPY function files and folders
COPY function/ ./
Expand All @@ -57,9 +54,9 @@ ENV upstream_url="http://127.0.0.1:3000"
ENV exec_timeout="10s"
ENV write_timeout="15s"
ENV read_timeout="15s"

ENV prefix_logs="false"

HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]

0 comments on commit d50ca50

Please sign in to comment.