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

docker: npm errors (linux) #12970

Closed
jmooring opened this issue Oct 20, 2024 · 3 comments
Closed

docker: npm errors (linux) #12970

jmooring opened this issue Oct 20, 2024 · 3 comments

Comments

@jmooring
Copy link
Member

This is a regression from v0.136.1.

error log
npm error code EACCES
npm error syscall mkdir
npm error path /var/hugo/.npm
npm error errno -13
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 1000:1000 "/var/hugo/.npm"
npm error Log files were not written due to an error writing to the directory: /var/hugo/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
Watching for changes in /project/{archetypes,assets,content,layouts,package.json,postcss.config.js,static}
Watching for config changes in /project/config/_default, /project/go.mod
Start building sites … 
hugo v0.136.2+extended linux/amd64 BuildDate=unknown VendorInfo=docker

ERROR render of "page" failed: "/project/layouts/_default/tailwindcss.html:16:23": execute of template failed: template: _default/tailwindcss.html:16:23: executing "main" at <.Content>: error calling Content: TAILWINDCSS: failed to transform "/temp/css" (application/octet-stream): npm error code EACCES
npm error syscall mkdir
npm error path /var/hugo/.npm
npm error errno EACCES
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 1000:1000 "/var/hugo/.npm"
npm error Log files were not written due to an error writing to the directory: /var/hugo/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
ERROR POSTCSS: failed to transform "/temp/css" (application/octet-stream): npm error code EACCES
npm error syscall mkdir
npm error path /var/hugo/.npm
npm error errno EACCES
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 1000:1000 "/var/hugo/.npm"
npm error Log files were not written due to an error writing to the directory: /var/hugo/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
ERROR TAILWINDCSS: failed to transform "/temp/css" (application/octet-stream): npm error code EACCES
npm error syscall mkdir
npm error path /var/hugo/.npm
npm error errno EACCES
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 1000:1000 "/var/hugo/.npm"
npm error Log files were not written due to an error writing to the directory: /var/hugo/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
Built in 580 ms
Error: error building site: render: failed to render pages: render of "page" failed: "/project/layouts/_default/postcss.html:20:23": execute of template failed: template: _default/postcss.html:20:23: executing "main" at <.Content>: error calling Content: POSTCSS: failed to transform "/temp/css" (application/octet-stream): npm error code EACCES
npm error syscall mkdir
npm error path /var/hugo/.npm
npm error errno EACCES
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 1000:1000 "/var/hugo/.npm"
npm error Log files were not written due to an error writing to the directory: /var/hugo/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

To test:

mkdir -p $HOME/.cache/hugo_cache
git clone https://github.com/jmooring/hugo-docker-test
cd hugo-docker-test
docker run --rm -v .:/project -v $HOME/.cache/hugo_cache:/cache -p 1313:1313 ghcr.io/gohugoio/hugo:v0.136.2 server --bind="0.0.0.0"

cc: @dvdksn

@jmooring
Copy link
Member Author

jmooring commented Oct 20, 2024

Maybe the expedient way to fix this issue and #12971 is to remove the npm install stuff from the image. Users would have to run npm ci themselves before running the docker run ... command. An added benefit is that they can run npm ci (recommended) instead of npm install.

EDIT: This seems to resolve the problem with Linux, but not with Windows (which now emits a different error).

@bep
Copy link
Member

bep commented Oct 20, 2024

Users would have to run npm ci themselves before running the docker run ... command.

That doesn't (always) work if the host OS is different from container OS, which is fairly common ...

@bhavin192
Copy link
Contributor

I observed something similar on the latest image. Somehow the the home /var/hugo on ghcr.io/gohugoio/hugo:v0.136.2 is owned by root and not by hugo.

In my case git config was failing as it was not able to create a lock file. Ref: git/git-scm.com#835 (comment) And this happens on GitLab CI runner as well which uses Docker, so Podman use has nothing to do with this error.

$ podman run -it --rm --entrypoint "sh" ghcr.io/gohugoio/hugo:v0.136.2
/project $ git config --global user.name Test
error: could not lock config file /var/hugo/.gitconfig: Permission denied

In this particular case npm is trying to save its cache and failing to create that folder.

$ podman run -it --rm --entrypoint "sh" ghcr.io/gohugoio/hugo:v0.136.2
/project $ ls -lld /var/hugo
drwxr-xr-x    3 root     root          4096 Oct 17 14:45 /var/hugo
$ podman run -it --rm --entrypoint "sh" ghcr.io/gohugoio/hugo:v0.136.1
/project $ ls -lld /var/hugo
drwxr-xr-x    3 hugo     nogroup       4096 Oct 20 16:03 /var/hugo

From the Dockerfile, my suspicion was the use of chown on two files, but that works fine when I tried similar command on my machine (Fedora Linux).

chown -R hugo: /var/hugo /cache && \

Then I tried to build latest master using podman, resulting image had home directory with correct owner, not sure what's going on 🤷

I don't have access to a Docker installation at the moment, so if someone can try building the image again and see who is owner of /var/hugo, that would be great.

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

No branches or pull requests

3 participants