Giter VIP home page Giter VIP logo

lhci-fargate's Introduction

LHCI-Fargate v1.70

lhci-cli v0.13.0

Deployment of Lighthouse CI through AWS-CDK onto AWS Fargate.

Table of Contents

Setup

  1. Configure cdk.json with your Route 53 forward zone and desired CNAME record name
  2. npm i
  3. npm run build
  4. cdk deploy
  5. lhci wizard will yield something similar to:

troy:/mnt/c/coderepo/lhci-fargate$ lhci wizard

? Which wizard do you want to run? new-project

? What is the URL of your LHCI server? https://lhci.example.com

? What would you like to name the project? lhci-fargate

? Where is the project's code hosted? https://github.com/example/lhci-fargate

? What branch is considered the repo's trunk or main branch? main

  1. Modify your lighthouserc.js file accordingly:
module.exports = {
    ci: {
    collect: {
        url: "https://www.example.com",
        maxAutodiscoverUrls: 3,
        numberOfRuns: 2,
        settings: {
            chromeFlags: "--no-sandbox",
            onlyCategories: ["performance", "best-practices", "accessibility", "seo"],
            skipAudits: ['uses-http2', 'uses-long-cache-ttl', 'link-text']
            // hostname: "127.0.0.1"
        }
    },
    // assert: {
    //     assertions: {
    //       'categories:performance': [
    //         'error',
    //         { minScore: 0.9, aggregationMethod: 'median-run' },
    //       ],
    //       'categories:accessibility': [
    //         'error',
    //         { minScore: 1, aggregationMethod: 'pessimistic' },
    //       ],
    //       'categories:best-practices': [
    //         'error',
    //         { minScore: 1, aggregationMethod: 'pessimistic' },
    //       ],
    //       'categories:seo': [
    //         'error',
    //         { minScore: 1, aggregationMethod: 'pessimistic' },
    //       ],
    //     },
    //   },
    upload: {
        target: 'lhci',
        serverBaseUrl: 'https://lhci.example.com',
        token: 'REPLACE-ME-WITH-LHCI-WIZARD-BUILD-TOKEN-VALUE',
        ignoreDuplicateBuildFailure: true,
        allowOverwriteOfLatestBranchBuild: true
    },
    },
};
  1. Replace the buildToken value provided by lhci-wizard in the lighthouserc.js file with the token value as seen above (shown under upload)

  2. Browse to the LHCI server (for example, https://lhci.example.com , click the left navigational\drop down pane (looking for the value set previously and click the gear in the upper-hand left corner)

  3. Add in the adminToken to the field in the settings for the LH project

  4. Run lhci autorun to run the lh-cli with the settings defined in the .lighthouserc.js file

    PS C:\coderepo\lhci-fargate> lhci autorun
    ✅  .lighthouseci/ directory writable
    ✅  Configuration file found
    ✅  Chrome installation found
    ⚠️   GitHub token not set
    ✅  Ancestor hash determinable
    ✅  LHCI server reachable
    ✅  LHCI server API-compatible
    ✅  LHCI server token valid
    ✅  LHCI server can accept a build for this commit hash
    Healthcheck passed!
    
    Running Lighthouse 2 time(s) on https://www.example.com
    Run #1...done.
    Run #2...done.
    Done running Lighthouse!
    
    Saving CI project lhci-fargate (780548b4-d479-4403-9500-e57f87b64d8d)
    Saving CI build (9e77cb40-546e-4c64-b7b1-0ad538255d9b)
    Saved LHR to https://lhci.example.com (2d027171-faf1-40af-bbdb-a4cc8a04a4d5)
    Saved LHR to https://lhci.example.com (eef82c8e-cf94-4b3d-a76e-b4e7044e2096)
    Done saving build results to Lighthouse CI
    View build diff at https://lhci.example.com/app/projects/lhci-fargate/compare/9e77cb40-546e-4c64-b7b1-0ad538255d9b
    No GitHub token set, skipping GitHub status check.
    
    Done running autorun.
    
  5. Observe the results on the lhci server. Browse to: https://lhci.example.com

    results

Diagram (example)

diagram

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

lhci-fargate's People

Contributors

renovate-bot avatar renovate[bot] avatar troydieter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

knoxilla

lhci-fargate's Issues

403 forbidden on lhci-wizard

Currently hitting a 403 Forbidden on lhci wizard:

example@DESKTOP-GNNVV9P:/mnt/c/coderepo/lhci-fargate$ lhci wizard
? Which wizard do you want to run? new-project
? What is the URL of your LHCI server? https://lighthouse.example.com
? What would you like to name the project? lhci-fargate
? Where is the project's code hosted? https://github.com/example/lhci-fargate
? What branch is considered the repo's trunk or main branch? newbranch
Error: Unexpected status code 403
  <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
</body>
</html>

    at ApiClient._convertFetchResponseToReturnValue (/home/tdieter/.nvm/versions/node/v16.17.0/lib/node_modules/@lhci/cli/node_modules/@lhci/utils/src/api-client.js:79:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runNewProjectWizard (/home/tdieter/.nvm/versions/node/v16.17.0/lib/node_modules/@lhci/cli/src/wizard/wizard.js:64:19)
    at async Object.runCommand (/home/tdieter/.nvm/versions/node/v16.17.0/lib/node_modules/@lhci/cli/src/wizard/wizard.js:164:7)
    at async run (/home/tdieter/.nvm/versions/node/v16.17.0/lib/node_modules/@lhci/cli/src/cli.js:125:7)

CDK script for deploying LHCI server (without runner + code deploy) ?

Firstly, this example is awesome and the best one i've seen for running lighthouse CI on AWS 👌

I was wondering if you'd be willing to share a separate CDK for deploying just the server part (serverless)? i.e. lhci/server + db.?
Then we could delegate the CI runner e.g. to a Gitlab Action to send results to server (for those that don't want to host their own CI runner.)
Would save some on infra costs too for personal projects!

I think you'd then cover quite nicely this issue raised on the main project around AWS deployment documentation: GoogleChrome/lighthouse-ci#382

Cheers!

Configure LHCI Server to save to PostgreSQL

Hello! I successfully deployed lhci-fargate to AWS.

Next step: I would like to change the output source from EFS to PostgreSQL. Can you point me to the places in the codebase that I would need to tweak to enable this?

Thx!

cdk deploy yields 'no such file' for ./lib/lambda.js

Followed the docs all the way up to cdk deploy and ran into

 $ cdk deploy
Error: ENOENT: no such file or directory, open './lib/lambda.js'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at new FargateEfsCustomResource (/Users/tknox/git/lhci-fargate/lib/efs-mount-fargate-cr.ts:28:38)
    at new LHCIStack (/Users/tknox/git/lhci-fargate/lib/lhci-stack.ts:125:22)
    at Object.<anonymous> (/Users/tknox/git/lhci-fargate/bin/lhci-fargate.ts:7:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/Users/tknox/git/lhci-fargate/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/tknox/git/lhci-fargate/node_modules/ts-node/src/index.ts:1458:12)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: './lib/lambda.js'
}

The EFS mount scripts under ./lib do reference such a file:

 $ ack lambda.js
lib/efs-mount-fargate-cr.ts
28:      code: new lambda.InlineCode(fs.readFileSync('./lib/lambda.js', { encoding: 'utf-8' })),

lib/efs-mount-fargate-cr.js
15:            code: new lambda.InlineCode(fs.readFileSync('./lib/lambda.js', { encoding: 'utf-8' })),

I can see that lambda.js was added here on May 12

git show a9e406a --stat

But then deleted two commits later - same day!

git show 7133daf --stat

Maybe the intent was to move the js file from ./ to ./lib and it accidentally got deleted?

I've tried

git checkout a9e406a -- ./lambda.ja && mv ./lambda.js ./lib

and then cdk deploy but I'm not sure that's doing the job. The stack is stuck in and ECS Service healthcheck spiral - can't get the LHCI tasks to pass the healthchecks, so we keep registering/deregistering targets.

So I suspect there is still some plumbing re the EFS mounts for the tasks that I'm missing. Can you advise?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • aws-cdk-lib 2.115.0
  • constructs 10.3.0
  • source-map-support 0.5.21
  • @lhci/cli 0.13.0
  • @types/jest 29.5.11
  • aws-cdk 2.115.0
  • cdk-watchful 0.6.458
  • jest 29.7.0
  • ts-jest 29.1.1
  • typescript 5.3.3

  • Check this box to trigger a request for Renovate to run again on this repository

502 Bad Gateway on push to LHCI server

Currently investigating the following 502 Bad Gateway response:

Saved LHR to http://lhci.troydieter.com (a17953ee-1538-49be-b4f9-94f1ee75ef81)
Saved LHR to http://lhci.troydieter.com (c8cbaec7-276f-4328-bef7-f245c617ac70)
Saved LHR to http://lhci.troydieter.com (4a00748b-0744-4538-8c05-56c703a92fe1)
Saved LHR to http://lhci.troydieter.com (6b4612a8-d68f-49cb-bd06-d9c150b02f3e)
Saved LHR to http://lhci.troydieter.com (29870b62-d145-47b5-8782-9866a4cda9ae)
Saved LHR to http://lhci.troydieter.com (5a99d53c-f84b-4bfd-b23d-853a15c49a78)
Saved LHR to http://lhci.troydieter.com (70df412a-ae70-488a-9c63-09e0eae6c372)
Saved LHR to http://lhci.troydieter.com (7cc3716a-fd54-45cb-b5f7-ecaf1de8fc21)
Error: Unexpected status code 502

<title>502 Bad Gateway</title>

502 Bad Gateway

at ApiClient._convertFetchResponseToReturnValue (C:\Users\troy.dieter\AppData\Roaming\npm\node_modules\@lhci\cli\node_modules\@lhci\utils\src\api-client.js:79:21)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runLHCITarget (C:\Users\troy.dieter\AppData\Roaming\npm\node_modules\@lhci\cli\src\upload\upload.js:452:3)        
at async Object.runCommand (C:\Users\troy.dieter\AppData\Roaming\npm\node_modules\@lhci\cli\src\upload\upload.js:589:16)   
at async run (C:\Users\troy.dieter\AppData\Roaming\npm\node_modules\@lhci\cli\src\cli.js:109:7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.