Skip to content

Commit

Permalink
Merge pull request #68 from spotify/release-2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
spotify-kai authored Apr 8, 2022
2 parents d726dc4 + 5953410 commit 208a1cd
Show file tree
Hide file tree
Showing 17 changed files with 3,763 additions and 4,632 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ name: Publish
on:
push:
branches:
- master
- master

jobs:
publish:
name: Publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.0
- name: yarn install
run: yarn
- name: lint
run: yarn lint
- name: build
run: yarn build
- name: test
run: yarn test
- name: release
run: yarn release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_USERNAME: ${{ secrets.GH_USERNAME }}
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- name: yarn install
run: yarn install --frozen-lockfile
- name: lint
run: yarn lint
- name: build
run: yarn build
- name: test
run: yarn test
- name: release
run: yarn release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_USERNAME: ${{ secrets.GH_USERNAME }}
32 changes: 16 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Tests
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master

jobs:
test:
Expand All @@ -15,19 +15,19 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [14, 16]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install
run: yarn
- name: lint
run: yarn lint
- name: build
run: yarn build
- name: test
run: yarn test
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: yarn install
run: yarn install --frozen-lockfile
- name: lint
run: yarn lint
- name: build
run: yarn build
- name: test
run: yarn test
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ typings/
# web-scripts paths
types
esm
cjs
cjs

# typescript incremental compilation cache
tsconfig.tsbuildinfo
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn web-scripts commitmsg --edit="$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn web-scripts precommit --no-tests --no-typecheck
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
# everything below sets up and runs lighthouse
FROM node:12

WORKDIR /app
FROM node:16-bullseye-slim

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf dumb-init \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV CHROME_PATH "google-chrome-unstable"

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
USER node

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin

WORKDIR /home/node/app

# install all dev and production dependencies
COPY package.json /app
COPY yarn.lock app/
COPY --chown=node:node package.json .
COPY --chown=node:node yarn.lock .
RUN yarn install

# build and copy the app over
COPY src/ /app/src
COPY tsconfig.json /app
COPY --chown=node:node src ./src
COPY --chown=node:node tsconfig.json .
RUN yarn build

ENV NODE_ENV production

# prune out dev dependencies now that build has completed
RUN yarn install --production

ENTRYPOINT [ "yarn" ]
CMD [ "start" ]
CMD ["dumb-init", "node", "cjs/run.js"]
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ Be sure to see "Configuring Postgres" - you will likely need to configure the Po
- `LAS_CORS`: if true, enables the [cors express middleware](https://expressjs.com/en/resources/middleware/cors.html).
- all [environment variables from pg](https://node-postgres.com/features/connecting#Environment%20variables), which should be used to set credentials for accessing the db.

#### With Docker Compose

A simple way to trial this tool is with the following docker compose file which spins up a postgres container and connects it with the lighthouse image. This would not be a great way to run this in a production environment, but a fast way to test out this tool and see if it meets your needs.

```yaml
# docker-compose.yml
version: '3.1'

services:

db:
image: postgres:latest
restart: always
environment:
POSTGRES_USER: dbuser
POSTGRES_PASSWORD: example

lighthouse:
image: spotify/lighthouse-audit-service:latest
environment:
PGHOST: db
PGUSER: dbuser
PGPASSWORD: example
LAS_PORT: 4008
ports:
- "4008:4008"
```
### As an npm package
Install the project:
Expand Down Expand Up @@ -52,7 +81,7 @@ You may nest the [express app](https://expressjs.com/) that the lighthouse-audit

```js
import express from 'express';
import { getApp as getLighthouseAuditServerApp } from '@spotify/lighthouse-audit-server';
import { getApp as getLighthouseAuditServerApp } from '@spotify/lighthouse-audit-service';

async function startup() {
const app = express();
Expand Down
62 changes: 28 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,52 @@
"format": "web-scripts format",
"commit": "web-scripts commit",
"release": "web-scripts release",
"prepare": "web-scripts audit"
},
"husky": {
"hooks": {
"commit-msg": "web-scripts commitmsg",
"pre-commit": "web-scripts precommit"
}
"prepare": "husky install"
},
"devDependencies": {
"@spotify/eslint-config-oss": "^1.0.2",
"@spotify/web-scripts": "^10.0.1",
"@types/async-retry": "^1.4.1",
"@types/compression": "^1.7.0",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.3",
"@types/morgan": "^1.9.0",
"@types/node": "^13.9.3",
"@types/pg": "^7.14.11",
"@types/supertest": "^2.0.11",
"@types/uuid": "^8.3.0",
"@types/wait-on": "^5.2.0",
"@spotify/web-scripts": "^13.0.0",
"@types/async-retry": "^1.4.3",
"@types/compression": "^1.7.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/morgan": "^1.9.3",
"@types/node": "^16.9.6",
"@types/pg": "^8.6.5",
"@types/supertest": "^2.0.12",
"@types/uuid": "^8.3.4",
"@types/wait-on": "^5.3.1",
"copyfiles": "^2.4.1",
"dotenv": "^8.2.0",
"dotenv": "^16.0.0",
"get-port": "^5.1.1",
"husky": "^4.0.0",
"husky": "^7.0.4",
"node-duration": "^2.0.0",
"nodemon": "^2.0.7",
"supertest": "^6.1.3",
"testcontainers": "^7.8.0",
"ts-node": "^9.1.1"
"nodemon": "^2.0.15",
"supertest": "^6.2.2",
"testcontainers": "^8.6.1",
"ts-node": "^10.7.0"
},
"dependencies": {
"async-retry": "^1.3.1",
"body-parser": "^1.19.0",
"async-retry": "^1.3.3",
"body-parser": "^1.20.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"lighthouse": "^7.4.0",
"express": "^4.17.3",
"express-promise-router": "^4.1.1",
"lighthouse": "^9.5.0",
"morgan": "^1.10.0",
"node-fetch": "^2.6.1",
"pg": "^8.6.0",
"puppeteer": "^9.0.0",
"pg": "^8.7.3",
"puppeteer": "^13.5.2",
"sql-template-strings": "^2.2.2",
"uuid": "^8.3.2",
"wait-on": "^5.3.0",
"winston": "^3.3.3"
"wait-on": "^6.0.1",
"winston": "^3.7.2"
},
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=12"
"node": ">=14.17"
}
}
3 changes: 2 additions & 1 deletion src/api/audits/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import path from 'path';

import { Audit, AuditStatus } from './models';

const UUID_RE = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const UUID_RE =
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;

const LIGHTHOUSE_REPORT_FIXTURE = fs
.readFileSync(path.join(__dirname, '__fixtures__', 'lighthouse-report.json'))
Expand Down
6 changes: 4 additions & 2 deletions src/api/audits/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import { Audit, AuditListItem } from './models';
import { configureErrorMiddleware } from '../../server';
import { InvalidRequestError } from '../../errors';

const UUID_RE = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const ISO_DATETIME_RE = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
const UUID_RE =
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const ISO_DATETIME_RE =
/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;

const LIGHTHOUSE_REPORT_FIXTURE = fs
.readFileSync(path.join(__dirname, '__fixtures__', 'lighthouse-report.json'))
Expand Down
2 changes: 1 addition & 1 deletion src/api/audits/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { Router, Request, Response } from 'express';
// @ts-ignore
import ReportGenerator from 'lighthouse/lighthouse-core/report/report-generator';
import ReportGenerator from 'lighthouse/report/generator/report-generator';

import logger from '../../logger';
import { DbConnectionType } from '../../db';
Expand Down
6 changes: 2 additions & 4 deletions src/api/listHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ export function listOptionsFromQuery(
defaultLimit = 25,
defaultOffset = 0,
): ListRequest {
const {
limit: limitStr = defaultLimit,
offset: offsetStr = defaultOffset,
} = query;
const { limit: limitStr = defaultLimit, offset: offsetStr = defaultOffset } =
query;
const limit = +limitStr;
const offset = +offsetStr;

Expand Down
14 changes: 11 additions & 3 deletions src/jest/global_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ import logger from '../logger';
import { awaitDbConnection, runDbMigrations } from '../db';
import globalTeardown from './global_teardown';

declare global {
namespace NodeJS {
interface Global {}
}
}

export interface GlobalWithPostgres extends NodeJS.Global {
__POSTGRES__?: StartedTestContainer;
}

const dbGlobal: GlobalWithPostgres = global;
const dbGlobal = globalThis as GlobalWithPostgres;

export default async () => {
const name = `las_test_container_${Math.random()
Expand All @@ -45,8 +51,10 @@ export default async () => {
// We have to use global setup because it's the only way in Jest to run code once before suite.
// Unfortuantely Jest prevents us from writing globals that are read by the sutite.
// So, we are forced to write the connection info to the ENV.
process.env.PGUSER = process.env.PGPASSWORD = process.env.PGDATABASE =
'postgres';
process.env.PGUSER =
process.env.PGPASSWORD =
process.env.PGDATABASE =
'postgres';
process.env.PGHOST = container.getHost();
process.env.PGPORT = `${container.getMappedPort(5432)}`;

Expand Down
2 changes: 1 addition & 1 deletion src/jest/global_teardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { StopOptions } from 'testcontainers/dist/test-container';

import { GlobalWithPostgres } from './global_setup';

const dbGlobal: GlobalWithPostgres = global;
const dbGlobal = globalThis as GlobalWithPostgres;

export default async function globalTeardown(
options?: StopOptions,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": ["src"],
"exclude": ["src/jest", "src/**/*.test.ts"],
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./src/@types"]
"typeRoots": ["./node_modules/@types", "./src/@types"],
"skipLibCheck": true
}
}
Loading

0 comments on commit 208a1cd

Please sign in to comment.