CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.49k stars 113 forks source link

Exit code 101 "Permission denied" in CI #675

Closed Pinjasaur closed 2 months ago

Pinjasaur commented 2 months ago

I was able to use it locally fine, but when attempting to run in CI I'm getting a "Permission denied" error.

Here's the logs from the CI step:

Running Pagefind v1.1.0 (Extended)
Running from: "/home/runner/work/bic-example/bic-example"
Source:       "build"
Output:       "build/pagefind"
[Walking source directory]
Found 12 files matching **/*.{html}
[Parsing files]
Found a data-pagefind-body element on the site.
↳ Ignoring pages without this tag.
[Reading languages]
Discovered 1 language: en
[Building search indexes]
Total: 
  Indexed 1 language
  Indexed 7 pages
  Indexed 281 words
  Indexed 0 filters
  Indexed 0 sorts
thread 'main' panicked at /home/runner/work/pagefind/pagefind/pagefind/src/output/mod.rs:350:46:
called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Process completed with exit code 101.

And the link to the CI run in full: https://github.com/Pinjasaur/bic-example/actions/runs/10231308426/job/28307113026

Couldn't find any other existing issues that mentioned this issue. Any ideas?

Pinjasaur commented 2 months ago

I added --verbose and RUST_BACKTRACE=1 which provides more verbosity (https://github.com/Pinjasaur/bic-example/actions/runs/10231705686/job/28307936415):

pagefind npm wrapper: Running the executable at /home/runner/.npm/_npx/525b598f4597c196/node_modules/@pagefind/linux-x64/bin/pagefind_extended
Running Pagefind v1.1.0 (Extended)
Running in verbose mode
Running from: "/home/runner/work/bic-example/bic-example"
Source:       "build"
Output:       "build/pagefind"
[Walking source directory]
Found 12 files matching **/*.{html}
[Parsing files]
Found a data-pagefind-body element on the site.
↳ Ignoring pages without this tag.
[Reading languages]
Discovered 1 language: en
  * en: 7 pages
[Building search indexes]
Language en: 
  Indexed 7 pages
  Indexed 281 words
  Indexed 0 filters
  Indexed 0 sorts
Total: 
  Indexed 1 language
  Indexed 7 pages
  Indexed 281 words
  Indexed 0 filters
  Indexed 0 sorts
thread 'main' panicked at /home/runner/work/pagefind/pagefind/pagefind/src/output/mod.rs:350:46:
called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/result.rs:1649:5
   3: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
   4: <futures_util::future::join_all::JoinAll<F> as core::future::future::Future>::poll
   5: pagefind::output::<impl pagefind::index::PagefindIndexes>::write_files::{{closure}}
   6: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
   7: <futures_util::future::join_all::JoinAll<F> as core::future::future::Future>::poll
   8: pagefind::SearchState::write_files::{{closure}}
   9: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
  10: tokio::runtime::park::CachedParkThread::block_on
  11: tokio::runtime::context::runtime::enter_runtime
  12: pagefind::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
pagefind npm wrapper: Process exited with status 101
Error: Process completed with exit code 101.
Pinjasaur commented 2 months ago

OK, figured it out. User error, the Docker container that's generating my static site has a USER nobody directive (to be rootless), but that was causing invalid permissions in CI.

In GitHub Actions, the rest of my filesystem was owned by runner:docker and I needed to change the build directory from nobody:nogroup to that. Here's the snippet I came up with and seems to work OK.

- name: chown
  run: echo "$(whoami):$(id -gn)" | xargs -I {} sudo chown -R {} build

It'd be great to get bit more verbose logging out pagefind to see where an error like that is coming from e.g. what file or directory. Thanks for letting me rubberduck. 🙂