Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
nodejs - Optimize copy for buildah (#679)
Browse files Browse the repository at this point in the history
* nodejs - Optimize copy in Dockerfile

* Added comments

* Update Dockerfile

* Update Dockerfile

* Reworked to move copy user-app in first stage

* Update package.json

* Update Dockerfile

* Update Dockerfile
  • Loading branch information
neeraj-laad authored Mar 3, 2020
1 parent 6ceac5f commit c27fffd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions incubator/nodejs/image/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ RUN apt-get update \
&& apt-get clean \
&& echo 'Finished installing dependencies'

# Copying individual files/folders as buildah 1.9.0 does not honour .dockerignore
COPY user-app /project/user-app
# Removing node_modules as we can not make assumptions about file structure of user-app
RUN rm -rf /project/user-app/node_modules && mkdir -p /project/user-app/node_modules

# Install user-app dependencies
WORKDIR "/project/user-app"
COPY ./user-app/package*.json ./
RUN npm install --production
WORKDIR "/project/user-app/node_modules"
WORKDIR /project/user-app
RUN npm install --production

# Creating a tar to work around poor copy performance when using buildah 1.9.0
RUN cd / && tar czf project.tgz project

# Copy the dependencies into a slim Node docker image
FROM node:12-slim
Expand All @@ -22,16 +28,14 @@ RUN apt-get update \
&& apt-get clean \
&& echo 'Finished installing dependencies'

# Copy the project
COPY --chown=node:node . /project

# Copy all dependencies
COPY --chown=node:node --from=0 /project/user-app/node_modules /project/user-app/node_modules
# Copy project with dependencies
COPY --chown=node:node --from=0 /project.tgz .
RUN tar xf project.tgz && chown -R node:node project && rm project.tgz

WORKDIR "/project/user-app"
WORKDIR /project/user-app

ENV NODE_ENV production

USER node

CMD ["npm", "start"]
CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion incubator/nodejs/image/project/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs",
"version": "0.3.3",
"version": "0.3.4",
"description": "Node.js Stack",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion incubator/nodejs/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Node.js
version: 0.3.3
version: 0.3.4
description: Runtime for Node.js applications
license: Apache-2.0
language: nodejs
Expand Down

0 comments on commit c27fffd

Please sign in to comment.