-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #599 from dzcode-io/lighthouse-setup
feat: Lighthouse setup
- Loading branch information
Showing
12 changed files
with
248 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
testBaseUrl: | ||
required: true | ||
type: string | ||
serverBaseUrl: | ||
required: true | ||
type: string | ||
stage: | ||
required: true | ||
type: string | ||
description: "staging or production" | ||
secrets: | ||
LH_SERVER_TOKEN_STG: | ||
required: true | ||
LH_SERVER_TOKEN_PRD: | ||
required: true | ||
|
||
jobs: | ||
urls-for-lighthouse: | ||
runs-on: ubuntu-latest | ||
env: | ||
LH_TEST_BASE_URL: ${{ inputs.testBaseUrl }} | ||
steps: | ||
- name: "Git" | ||
uses: actions/checkout@v4 | ||
- name: "Nodejs" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: "npm" | ||
- run: npm ci | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: build output (ubuntu-latest, 20) | ||
- name: Define Urls | ||
id: define-urls | ||
run: | | ||
node web/lighthouserc.cjs --output-urls >> "$GITHUB_OUTPUT" | ||
outputs: | ||
urls: ${{ steps.define-urls.outputs.urls }} | ||
|
||
lighthouse-collect: | ||
needs: urls-for-lighthouse | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
url: ${{fromJson(needs.urls-for-lighthouse.outputs.urls)}} | ||
env: | ||
LH_TEST_BASE_URL: ${{ inputs.testBaseUrl }} | ||
LH_OVERWRITE_URL: ${{ matrix.url }} | ||
|
||
steps: | ||
- name: "Git" | ||
uses: actions/checkout@v4 | ||
- name: "Nodejs" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: "npm" | ||
- run: npm ci | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: build output (ubuntu-latest, 20) | ||
- run: npx lerna run lh:collect --scope "@dzcode.io/web" | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: lighthouse output (${{ hashFiles('web/.lighthouseci/**') }}) | ||
path: ./web/.lighthouseci/** | ||
if-no-files-found: error | ||
include-hidden-files: true | ||
retention-days: 1 | ||
|
||
lighthouse-upload: | ||
needs: lighthouse-collect | ||
runs-on: ubuntu-latest | ||
env: | ||
LH_SERVER_BASE_URL: ${{ inputs.serverBaseUrl }} | ||
LH_SERVER_TOKEN: ${{ inputs.stage == 'staging' && secrets.LH_SERVER_TOKEN_STG || secrets.LH_SERVER_TOKEN_PRD }} | ||
steps: | ||
- name: "Git" | ||
uses: actions/checkout@v4 | ||
- name: "Nodejs" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: "npm" | ||
- run: npm ci | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: build output (ubuntu-latest, 20) | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: lighthouse* | ||
merge-multiple: true | ||
path: ./web/.lighthouseci | ||
- run: npx lerna run lh:upload --scope "@dzcode.io/web" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
version: "3" | ||
services: | ||
reverse-proxy: | ||
image: nginx | ||
ports: | ||
- "80:80" | ||
depends_on: | ||
- api | ||
- lhserver | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf | ||
api: | ||
build: "." | ||
# restart: always | ||
ports: | ||
- "80:7070" | ||
- "7070:7070" | ||
env_file: | ||
- /home/ubuntu/app-env/api.env | ||
volumes: | ||
- /home/ubuntu/app-data/api/fetch_cache:/usr/src/repo/api/fetch_cache | ||
- /home/ubuntu/app-data/api/sqlite_db:/usr/src/repo/api/sqlite_db | ||
lhserver: | ||
image: patrickhulce/lhci-server | ||
ports: | ||
- "9001:9001" | ||
volumes: | ||
- /home/ubuntu/app-data/web/lh_data:/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
events { | ||
} | ||
|
||
|
||
http { | ||
server { | ||
client_max_body_size 10M; | ||
listen 80; | ||
# redirect traffic from lh-stage.dzcode.io, lh_stage.dzcode.io, lh.dzcode.io to lhserver:9001 | ||
# and from api-stage.dzcode.io, api_stage.dzcode.io, api.dzcode.io to api:7070 | ||
location / { | ||
if ($host ~* ^lh-stage.dzcode.io$) { | ||
proxy_pass http://lhserver:9001; | ||
} | ||
if ($host ~* ^lh_stage.dzcode.io$) { | ||
proxy_pass http://lhserver:9001; | ||
} | ||
if ($host ~* ^lh.dzcode.io$) { | ||
proxy_pass http://lhserver:9001; | ||
} | ||
if ($host ~* ^api-stage.dzcode.io$) { | ||
proxy_pass http://api:7070; | ||
} | ||
if ($host ~* ^api_stage.dzcode.io$) { | ||
proxy_pass http://api:7070; | ||
} | ||
if ($host ~* ^api.dzcode.io$) { | ||
proxy_pass http://api:7070; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ nodemon.json | |
*.ts-prunerc | ||
*.patch | ||
*.sql | ||
*.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const { allLanguages } = require("@dzcode.io/models/dist/language"); | ||
|
||
const baseUrl = process.env.LH_TEST_BASE_URL; | ||
const serverBaseUrl = process.env.LH_SERVER_BASE_URL; | ||
const token = process.env.LH_SERVER_TOKEN; | ||
const overwriteURL = process.env.LH_OVERWRITE_URL; | ||
|
||
let urls = ["", "/contribute", "/team", "/projects", "/faq"]; | ||
|
||
const args = process.argv.slice(2); | ||
if (args.includes("--output-urls")) { | ||
console.log(`urls=${JSON.stringify(urls)}`); | ||
} else if (typeof overwriteURL !== "undefined") { | ||
urls = [overwriteURL]; | ||
} | ||
|
||
module.exports = { | ||
ci: { | ||
collect: { | ||
url: urls.reduce((acc, path) => { | ||
return acc.concat( | ||
allLanguages.map(({ code }) => `${baseUrl}${code === "en" ? "" : `/${code}`}${path}`), | ||
); | ||
}, []), | ||
}, | ||
upload: { | ||
target: "lhci", | ||
serverBaseUrl, | ||
token, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters