GoogleChrome / lighthouse-ci

Automate running Lighthouse for every commit, viewing the changes, and preventing regressions
Apache License 2.0
6.4k stars 641 forks source link

`EACCES: permission denied, open '/home/lhci/reports/.lighthouseci/[...].json' #742

Open steren opened 2 years ago

steren commented 2 years ago

I am trying to follow the Docker client docs.

On google Cloud Shell or GitHub Codespaces, I run:

docker container run --cap-add=SYS_ADMIN \
  -v "$(pwd)/lhci-data:/home/lhci/reports/.lighthouseci" \
  patrickhulce/lhci-client \
  lhci collect --url="https://example.com"

I get this error:

Running Lighthouse 3 time(s) on https://example.com
Run #1...Error: EACCES: permission denied, open '/home/lhci/reports/.lighthouseci/flags-eed892e7-d017-4c61-a984-8f1ceb67a96c.json'
    at Object.openSync (fs.js:458:3)
    at Object.writeFileSync (fs.js:1355:35)
    at Function.computeArgumentsAndCleanup (/usr/local/lib/node_modules/@lhci/cli/src/collect/node-runner.js:69:10)
    at LighthouseRunner.run (/usr/local/lib/node_modules/@lhci/cli/src/collect/node-runner.js:97:48)
    at LighthouseRunner.runUntilSuccess (/usr/local/lib/node_modules/@lhci/cli/src/collect/node-runner.js:140:27)
    at runOnUrl (/usr/local/lib/node_modules/@lhci/cli/src/collect/collect.js:124:32)
    at Object.runCommand (/usr/local/lib/node_modules/@lhci/cli/src/collect/collect.js:245:13)
    at async run (/usr/local/lib/node_modules/@lhci/cli/src/cli.js:103:7)failed!
steren commented 2 years ago

I have the same error if I docker build the image myself from the Dockerfile

saunter511 commented 2 years ago

I have the same issue when running lighthouse in docker compose on Azure DevOps pipeline.

services:
  lhci:
    depends_on:
      - frontend
    user: "${UID}:${GID}" 
    container_name: lighthouse-ci
    build:
      context: .
      shm_size: 2g
    volumes:
      - "./lhci-data:/home/lhci/reports/.lighthouseci"
    cap_add: 
      - ALL
    command: lhci collect --no-sandbox 

The Dockerfile is a bit modified file from here

FROM node:16-bullseye-slim

# Install utilities
RUN apt-get update --fix-missing && apt-get -y upgrade && apt-get install -y git wget gnupg && apt-get clean

# Install latest chrome stable package.
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update \
    && apt-get install -y google-chrome-stable --no-install-recommends \
    && apt-get clean

# Install npm dependencies.
RUN npm install -g @lhci/cli@0.9.0 
RUN npm install -g lighthouse
RUN npm install -g puppeteer 

# Setup a user to avoid doing everything as root
RUN groupadd --system lhci && \
  useradd --system --create-home --gid lhci lhci && \
  mkdir --parents /home/lhci/reports && \
  chown --recursive lhci:lhci /home/lhci

RUN mkdir -p /home/lhci/reports
COPY lighthouserc.js puppeteerScript.js  /home/lhci/reports/

USER lhci
WORKDIR /home/lhci/reports

CMD [  "lhci", 'autorun' ]

The crash happens randomly, with no particular reason. Sometimes it passes, sometimes it throws an EACCES error.

andisan86 commented 1 year ago

Seems that docker does not have permission to mount local directory. Try to open the permission of lhci-data directory.