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

fix: Resolve docker build failure of NodeJS application #1017

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

Akash-Nayak
Copy link
Contributor

@Akash-Nayak Akash-Nayak commented Apr 6, 2023

Fixes- #1016

Old Dockerfile

FROM registry.access.redhat.com/ubi8/nodejs-16
COPY . .
RUN npm install
USER root
RUN mkdir -p /opt/app-root/src/.npm
RUN chown -R 1001:0 /opt/app-root/src/.npm
RUN chmod -R 775 /opt/app-root/src/.npm
USER 1001
EXPOSE 8080
CMD npm run start
✗ ./buildimages.sh
building image cfnodejsapp
[+] Building 1.2s (7/10)                                                                           
 => [internal] load build definition from Dockerfile                                          0.0s
 => => transferring dockerfile: 879B                                                          0.0s
 => [internal] load .dockerignore                                                             0.0s
 => => transferring context: 2B                                                               0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi8/nodejs-16:latest             0.0s
 => [internal] load build context                                                             0.0s
 => => transferring context: 1.00kB                                                           0.0s
 => CACHED [1/6] FROM registry.access.redhat.com/ubi8/nodejs-16                               0.0s
 => [2/6] COPY . .                                                                            0.0s
 => ERROR [3/6] RUN npm install                                                               1.0s
------
 > [3/6] RUN npm install:
#7 0.893 npm WARN ancient lockfile 
#7 0.894 npm WARN ancient lockfile The package-lock.json file was created with an old version of npm,
#7 0.894 npm WARN ancient lockfile so supplemental metadata must be fetched from the registry.
#7 0.895 npm WARN ancient lockfile 
#7 0.895 npm WARN ancient lockfile This is a one-time fix-up, please be patient...
#7 0.896 npm WARN ancient lockfile 
#7 0.918 npm ERR! code EACCES
#7 0.918 npm ERR! syscall open
#7 0.919 npm ERR! path /opt/app-root/src/package-lock.json
#7 0.920 npm ERR! errno -13
#7 0.925 npm ERR! Error: EACCES: permission denied, open '/opt/app-root/src/package-lock.json'
#7 0.925 npm ERR!  [Error: EACCES: permission denied, open '/opt/app-root/src/package-lock.json'] {
#7 0.925 npm ERR!   errno: -13,
#7 0.925 npm ERR!   code: 'EACCES',
#7 0.926 npm ERR!   syscall: 'open',
#7 0.926 npm ERR!   path: '/opt/app-root/src/package-lock.json'
#7 0.926 npm ERR! }
#7 0.926 npm ERR! 
#7 0.926 npm ERR! The operation was rejected by your operating system.
#7 0.926 npm ERR! It is likely you do not have the permissions to access this file as the current user
#7 0.926 npm ERR! 
#7 0.926 npm ERR! If you believe this might be a permissions issue, please double-check the
#7 0.926 npm ERR! permissions of the file and its containing directories, or try running
#7 0.926 npm ERR! the command again as root/Administrator.
#7 0.929 
#7 0.929 npm ERR! A complete log of this run can be found in:
#7 0.929 npm ERR!     /opt/app-root/src/.npm/_logs/2023-04-06T10_45_50_809Z-debug-0.log
------
executor failed running [/bin/sh -c npm install]: exit code: 243
/Users/akash/move2kube-demos/samples/myproject3
done

New Dockerfile

FROM registry.access.redhat.com/ubi8/nodejs-16
COPY . .
USER root
RUN mkdir -p /opt/app-root/src/.npm
RUN chown -R 1001:0 /opt/app-root/src/
RUN chmod -R 775 /opt/app-root/src/
USER 1001
RUN npm install
EXPOSE 8080
CMD npm run start
✗ ./buildimages.sh
building image cfnodejsapp
[+] Building 4.7s (11/11) FINISHED                                                                 
 => [internal] load build definition from Dockerfile                                          0.6s
 => => transferring dockerfile: 878B                                                          0.1s
 => [internal] load .dockerignore                                                             0.5s
 => => transferring context: 2B                                                               0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi8/nodejs-16:latest             0.0s
 => [internal] load build context                                                             0.5s
 => => transferring context: 2.17kB                                                           0.2s
 => [1/6] FROM registry.access.redhat.com/ubi8/nodejs-16                                      0.0s
 => CACHED [2/6] COPY . .                                                                     0.0s
 => CACHED [3/6] RUN mkdir -p /opt/app-root/src/.npm                                          0.0s
 => CACHED [4/6] RUN chown -R 1001:0 /opt/app-root/src/                                       0.0s
 => CACHED [5/6] RUN chmod -R 775 /opt/app-root/src/                                          0.0s
 => CACHED [6/6] RUN npm install                                                              0.0s
 => exporting to image                                                                        0.5s
 => => exporting layers                                                                       0.0s
 => => writing image sha256:2a350133934aa7ee363fe8cd1d548b979951f162cb75789438f4e718b569b7e7  0.0s
 => => naming to docker.io/library/cfnodejsapp

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
@github-actions
Copy link

github-actions bot commented Apr 6, 2023

Thanks for making a pull request! 😃
One of the maintainers will review and advise on the next steps.

@github-actions github-actions bot added the fix label Apr 6, 2023
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (205a4f5) 17.66% compared to head (3cbf87f) 17.66%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1017   +/-   ##
=======================================
  Coverage   17.66%   17.66%           
=======================================
  Files          63       63           
  Lines        5249     5249           
=======================================
  Hits          927      927           
  Misses       4074     4074           
  Partials      248      248           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants