genuinetools / img

Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
https://blog.jessfraz.com/post/building-container-images-securely-on-kubernetes/
MIT License
3.88k stars 230 forks source link

RUN npm ci --only=production causes exporting layers to fail #286

Closed ChrisTomAlx closed 4 years ago

ChrisTomAlx commented 4 years ago

So I started using img to build dockerfiles from within a docker container. Tried with 0.5.7 but it would not let me run build like some other issues I found that were having problems with 0.5.7 like #250 so I reverted to 0.5.6 and ran my original container (external) with the --privileged flag.

Problem

My dockerfile of the internal container looks like :-

FROM node:10

LABEL maintainer="Nisarg Tuli"

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 8081

ENV NEUTRINOS_APP_ENV=dev

CMD ["node", "./build/index.js"]

Problem Stack Trace

This caused the following error for the docker file :-

[BUILD_SERVER] 20-04-2020 07:01:44 INFO: 
#10 [5/5] COPY . .
#10       digest: sha256:f49c1ebb4b963c1a8b78509db2099e4700d8f6e8960142088cfd4236c33cbaba
#10         name: "[5/5] COPY . ."
#10      started: 2020-04-20 07:01:44.309082592 +0000 UTC m=+185.606374364

[BUILD_SERVER] 20-04-2020 07:01:50 INFO: #10    completed: 2020-04-20 07:01:50.892395454 +0000 UTC m=+192.189687144
#10     duration: 6.58331278s

[BUILD_SERVER] 20-04-2020 07:01:51 INFO: 
#11 exporting to image
#11       digest: sha256:c25e7b16ba59d801a38e69c3cc6c037da6d545fa442513b9204a90105a24f977
#11         name: "exporting to image"
#11      started: 2020-04-20 07:01:51.296016565 +0000 UTC m=+192.593308317
#11 exporting layers

[BUILD_SERVER] 20-04-2020 07:01:58 INFO: #11    completed: 2020-04-20 07:01:58.155144137 +0000 UTC m=+199.452435971
#11     duration: 6.859127654s
#11        error: "failed calculating diff pairs for exported snapshot: mount callback failed on /tmp/containerd-mount761439495: mount callback failed on /tmp/containerd-mount664704698: failed to write compressed diff: failed to create diff tar stream: stat /tmp/containerd-mount664704698/home/user/src/node_modules/resolve: no such file or directory"
#11 exporting layers 6.9s done

[BUILD_SERVER] 20-04-2020 07:01:58 ERROR: failed to solve: failed calculating diff pairs for exported snapshot: mount callback failed on /tmp/containerd-mount761439495: mount callback failed on /tmp/containerd-mount664704698: failed to write compressed diff: failed to create diff tar stream: stat /tmp/containerd-mount664704698/home/user/src/node_modules/resolve: no such file or directory

Solution

Removing just RUN npm ci --only=production from my internal dockerfile fixed the issue and I was able to build. This happens with other npm commands like npm prune --production Seems to be an issue with the --production flag.

Just dropping this here for anyone else. Hope this helps someone. Spent a lot of sleepless nights hunting this problem down.

Excellent work everyone involved in this project Take care guys and Have a nice day!!

ChrisTomAlx commented 4 years ago

Closing since this is just information and not a real issue. !! Or maybe it is a bug. Feel free to reopen if you think its worth any attention. Cheers!!