sahat / hackathon-starter

A boilerplate for Node.js web applications
MIT License
34.8k stars 8.16k forks source link

Error building docker image #1247

Closed robbrad591 closed 10 months ago

robbrad591 commented 1 year ago

We seem to have an issue building the docker image. M1 Mac with the latest docker (4.22.0 (117440)).

The error is as follows:

` => ERROR [web 5/7] RUN npm install --production 72.9s

[web 5/7] RUN npm install --production: 0.385 npm WARN config production Use --omit=dev instead. 72.16 72.16 > hackathon-starter@8.0.0 postinstall 72.16 > patch-package && npm run scss 72.16 72.26 patch-package 7.0.2 72.26 Applying patches... 72.26 No patch files found 72.40 72.40 > hackathon-starter@8.0.0 scss 72.40 > sass --no-source-map --load-path=./ --update ./public/css:./public/css 72.40 72.57 Error reading public/css: no such file or directory. 72.58 npm ERR! code 66 72.58 npm ERR! path /starter 72.58 npm ERR! command failed 72.58 npm ERR! command sh -c patch-package && npm run scss 72.58 72.58 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-08-10T08_29_39_308Z-debug-0.log

failed to solve: process "/bin/sh -c npm install --production" did not complete successfully: exit code: 66`

Post install steps seem to fail. It's strange because if i take out the npm install step, then shell into the container and run the steps manually, it all works.

YasharF commented 1 year ago

If I am reading the error log correctly, it looks like the new scss build process isn't working in docker because docker has a different path during the install step. I don't actively use docker, but would be glad to accept a PR if you can come up with change that you have tested and is working. I suspect, you would need to figure out what the path is during the docker installs, and come up with docker script or changes/additions to the npm scripts to handle the path. It looks like currently it can't find public/css when it tries to run the following during the docker install: sass --no-source-map --load-path=./ --update ./public/css:./public/css

robbrad591 commented 1 year ago

Looks like we just need to copy the file structure before we run npm install. I've got that fixed, however there's an issue with the prepare step in the package.json not running when installing for production. I'll put up a PR when i've got around that. Seems to be a common thing

vimark1 commented 1 year ago

Hey @YasharF and @robbrad591

I fixed this in https://github.com/sahat/hackathon-starter/pull/1256

See my comments on the PR

YasharF commented 10 months ago

The reason behind the issue with husky is that package.json has a call to it, but since it is a dev dependency. The docker image doesn't include dev dependencies by design to keep its size small. We don't want to bloat the image because of a dev dependency. We also can't use ignore-script to skip prepare scripts because ignore-script will also prevent execution of the postinstall scripts. The postinstall scripts include patch-package and sass builds, both of which are needed.

I am looking for a fix to the issue with husky

YasharF commented 10 months ago

The other thing that I noticed is that the error is about the sass build, but the PRs that suppress the error mentioned husky. Hence more investigation of the root cause is needed.

YasharF commented 10 months ago

The reason the public/css files ends up being empty is because were are overwriting the starter folder by mounting over it here: https://github.com/sahat/hackathon-starter/blob/c7249e9f240f1036f6866f7452d9e3dc28c39db4/docker-compose.yml#L16

YasharF commented 10 months ago

Fixed with https://github.com/sahat/hackathon-starter/commit/cf2f40f4541faddf188b0febc481b98f3fdeb5ca