GoogleChrome / lighthouse-ci

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

Lighthouse-ci server not working on AWS elastic beanstalk (autorun fails) #237

Closed otwm closed 4 years ago

otwm commented 4 years ago

Lighthouse-ci server not working on AWS elastic beanstalk (autorun fails)

phenomenon

I installed the server through docker. The server works fine. The project is also registered through the wizard. So far so good. The problem is autorun. Autorun does not work with a 422 error.

autorun error message

Error: Unexpected status code 422
  {"message": "Invalid build"}
    at ApiClient._convertFetchResponseToReturnValue (/usr/local/lib/node_modules/@lhci/cli/node_modules/@lhci/utils/src/api-client.js:55:21)
    at process._tickCallback (internal / process / next_tick.js: 68: 7)

upload error message

Error: Could not find active project with provided token
    at runLHCITarget (/usr/local/lib/node_modules/@lhci/cli/src/upload/upload.js:223:11)
    at process._tickCallback (internal / process / next_tick.js: 68: 7)%

Environment:

aws elastic beanstalk docker This is a common setting. Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "patrickhulce / lhci-server"
  },
  "Ports": [
    {
      "ContainerPort": 9001,
      "HostPort": 9001
    }
  ],
  "Volumes": [
    {
      "HostDirectory": "/ data / lhci-data",
      "ContainerDirectory": "/ data"
    }
  ]
}

analysis

I tried putting the logs in @ lhci / cli / node_modules / @ lhci / utils / src / api-client.js file.

const error = new Error (`Unexpected status code $ {response.status} \ n $ {body}`);
      console.log ('log', body, response.status, response)
log Not Found 404 Body {

A 404 error is returned. I read the code to find out more about it and checked the url routes to check with the server.

POST server / v1 / projects / lookup
Content-Type: application / json

{
  "token": "token"
}

###
GET server / v1 / projects
Content-Type: application / json

###
GET server / v1 / projects / slug: test2
Content-Type: application / json

As I tested each server api, I found something unusual. The server sometimes works fine, but sometimes it returns a 404. I've read the code and I know there's nothing wrong with it. It works fine on my local server.

If someone has experience with this, please share it.

otwm commented 4 years ago

I knew what the problem was. Two aws eb instances were running. I will close this issue.

patrickhulce commented 4 years ago

Thanks for sharing the solution so others can benefit @otwm! Glad you figured it out :)

jared-christensen commented 3 years ago

@otwm Can you tell me how you got this to run in beanstalk? I'm trying but can not figure it out.

kriscoleman commented 2 years ago

@otwm @jared-christensen I am currently trying to get Lighthouse server working in Elastic Beanstalk with docker-compose up and having issues, too. Did you have any luck?

I get docker-compose to work locally but after deploying to EB, console reports the instance is healthy but I can't connect to the url. I just get 504s.

I'm thinking it's something to do with port forwarding. I've been trying to set up a nginx reverse proxy, but no luck.

jared-christensen commented 2 years ago

@kriscoleman I did end up getting it to work but I'm using app runner.

This is what my docker file looks like if that helps at all.

WORKDIR /app
COPY package*.json ./
RUN npm install --unsafe-perm=true
COPY . .
EXPOSE 9001
CMD ["npx", "lhci", "server", "--storage.storageMethod=sql", "--storage.sqlDialect=sqlite", "--storage.sqlDatabasePath=./db.sql"]

And my package.json

{
  "name": "lighthouse-ci",
  "version": "1.0.0",
  "description": "docker volume create lhci-data docker container run --publish 9001:9001 --mount='source=lhci-data,target=/data' --detach patrickhulce/lhci-server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://git@bitbucket.org/dhigroupinc/lighthouse-ci.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "homepage": "https://bitbucket.org/dhigroupinc/lighthouse-ci#readme",
  "devDependencies": {
    "@lhci/cli": "^0.8.0",
    "@lhci/server": "^0.8.0",
    "sqlite3": "^5.0.2"
  }
}
kriscoleman commented 2 years ago

@jared-christensen

Thank you so much!!

I scrapped my docker-compose.yml and just added your docker file (with FROM node:12.18.3-alpine3.11) and your package.json, and it's working!

I have it working in Elastic Beanstalk, too. I unfortunately couldn't seem to use AWS App Runner, as our code was in AWS CodeCommit and AWS App Runner wouldn't let me choose that as a git provider.

I think the storage is ephemeral so I might try to add persistent storage, but this unblocked me and got me going. Thank you for responding so fast!!

jared-christensen commented 2 years ago

@kriscoleman Awesome! It was a struggle for me to get it working so I’m glad it worked for you too!

kriscoleman commented 2 years ago

Gosh, me too. I spent a few days on this trying figure out why EB wasn't playing nice. You saved me a ton of pain and I just got the dopamine of closing a bajillion browser tabs. Thanks again @jared-christensen !!

matmeylan commented 3 months ago

We used the CDK to deploy to AWS using fargate and cloudfront. This might be useful to someone else:

https://github.com/buildigo/lighthouse-ci-server/blob/master/lib/lighthouse-ci-server-stack.ts