From a8815648cb7769b1ffb37b13d5e86abc5d4c941d Mon Sep 17 00:00:00 2001 From: Firq <firelp42@gmail.com> Date: Wed, 2 Oct 2024 00:01:21 +0200 Subject: [PATCH 1/2] Added font preloading --- package.json | 2 +- serve.json | 9 +++++++++ src/layouts/Layout.astro | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d40902c..672603c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fgo-ta-com-website", "type": "module", - "version": "0.2.2-pre.20", + "version": "0.2.2-pre.21", "scripts": { "dev": "astro dev", "start": "astro dev", diff --git a/serve.json b/serve.json index eb10f13..4b422d7 100644 --- a/serve.json +++ b/serve.json @@ -12,6 +12,15 @@ } ] }, + { + "source": "**/*.woff2", + "headers": [ + { + "key": "Cache-Control", + "value": "no-cache" + } + ] + }, { "source": "404.html", "headers": [ diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index eecae04..39e99c5 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -9,6 +9,9 @@ import databasestar from 'iconoir/icons/database-star.svg' import mail from 'iconoir/icons/mail.svg' import type { IconsLookup } from '../types/generic' +import workSans800 from '@fontsource/work-sans/files/work-sans-latin-800-normal.woff2?url'; +import workSans600 from '@fontsource/work-sans/files/work-sans-latin-600-normal.woff2?url'; + export interface Props { title: string currentpage: string @@ -61,6 +64,8 @@ const mapped_navdata = navdata.map((item) => ({ <!-- Disable DarkReader, as site is already in dark mode --> <meta name="darkreader-lock" content="this site only has darkmode"> <!-- Links --> + <link rel="preload" as="font" type="font/woff2" href={workSans600} crossorigin="anonymous" /> + <link rel="preload" as="font" type="font/woff2" href={workSans800} crossorigin="anonymous" /> <link rel="icon" type="image/ico" href="/favicon.ico" /> <link rel="sitemap" href="/sitemap-index.xml" /> <link href="https://mastodon.neshweb.net/@Firq" rel="me" /> From a4e45ab2b83f43af6d293dd66d3a59f8751604c8 Mon Sep 17 00:00:00 2001 From: Firq <firelp42@gmail.com> Date: Fri, 1 Nov 2024 16:34:51 +0100 Subject: [PATCH 2/2] Unlighthouse rework with docker --- .forgejo/workflows/build_preview.yml | 15 ++++ .forgejo/workflows/unlighthouse.yml | 126 +++++++++++++-------------- Dockerfile.reports | 6 ++ package.json | 2 +- unlighthouse.config.ts | 26 +++++- 5 files changed, 106 insertions(+), 69 deletions(-) create mode 100644 Dockerfile.reports diff --git a/.forgejo/workflows/build_preview.yml b/.forgejo/workflows/build_preview.yml index 727892d..36d6eb5 100644 --- a/.forgejo/workflows/build_preview.yml +++ b/.forgejo/workflows/build_preview.yml @@ -80,3 +80,18 @@ jobs: dockge status fgo-ta-com-preview dockge update fgo-ta-com-preview dockge status fgo-ta-com-preview + + run-unlighthouse: + needs: [ build-site ] + if: success() + runs-on: docker + steps: + - name: Launch workflow + run: | + payload="{\"ref\": \"${GITHUB_REF_NAME}\", \"inputs\": { \"containertag\": \"${GITHUB_REF_NAME}\" }}" + curl -X "POST" \ + -H "accept: application/json" \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -d "${payload}" \ + "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/workflows/unlighthouse.yml/dispatches" -v diff --git a/.forgejo/workflows/unlighthouse.yml b/.forgejo/workflows/unlighthouse.yml index 4235b01..1222bce 100644 --- a/.forgejo/workflows/unlighthouse.yml +++ b/.forgejo/workflows/unlighthouse.yml @@ -1,17 +1,36 @@ +name: Run unlighthouse-tests [Downstream pipeline] +run-name: Run unlighthouse-tests [Downstream pipeline] for version ${{ inputs.containertag }} on: - push: - tags: - - '[0-9]+\.[0-9]+\.[0-9]+-ulh\.[0-9]+' + workflow_dispatch: + inputs: + containertag: + description: "Tag of the container to test" + default: "preview" + type: "string" jobs: unlighthouse: runs-on: docker - container: forgejo.neshweb.net/ci-docker-images/unlighthouse:0.2.1 + container: + image: forgejo.neshweb.net/ci-docker-images/unlighthouse:0.3.0 + services: + website: + image: forgejo.neshweb.net/firq/fgo-ta-com-website:${{ inputs.containertag }} + options: >- + --workdir / steps: - name: Checkout repository uses: https://code.forgejo.org/actions/checkout@v3 + - name: Check availability + run: | + while [ "$(curl -o /dev/null -s -w '%{http_code}' http://localhost:8081/)" -ne 200 ]; + do echo "Waiting..."; + sleep 5; + done; - name: Run unlighthouse - run: unlighthouse-ci --site "https://preview.fgo-ta.com/" --disable-dynamic-sampling + run: unlighthouse-ci --site "http://localhost:8081/" + - name: Replace URLs + run: find ./unlighthouse-reports -type f | xargs sed -i "s|http://localhost:8081|https://preview.fgo-ta.com|g"; - name: Prepare artifacts run: cp serve.json unlighthouse-reports - name: Upload reports @@ -19,79 +38,54 @@ jobs: with: name: unlighthouse-reports path: unlighthouse-reports/ + - name: Upload Dockerfile + uses: actions/upload-artifact@v3 + with: + name: dockerfile + path: Dockerfile.reports - deploy-unlighthouse-files: + build-site: needs: [ unlighthouse ] if: success() - runs-on: docker - env: - DEPLOY_USER: ${{ secrets.DEPLOY_USER }} - DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + runs-on: dind steps: - - name: Install and update ssh + rsync - run: | - which rsync || ( apt update -y && apt install rsync -y) - which ssh-agent || ( apt update -y && apt install openssh-client -y) + - name: Downloading static site artifacts + uses: actions/download-artifact@v3 + with: + name: dockerfile - name: Downloading static site artifacts uses: actions/download-artifact@v3 with: name: unlighthouse-reports - path: public - - name: Install SSH Key - uses: https://github.com/shimataro/ssh-key-action@v2 + path: reports + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log into Docker Package Registry + uses: docker/login-action@v3 with: - key: ${{ secrets.SSH_PRIVATE_KEY }} - known_hosts: unnecessary - - name: Adding Known Hosts - run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts - - name: Stop screen session, delete old files - uses: https://github.com/appleboy/ssh-action@master + registry: forgejo.neshweb.net + username: ${{ secrets.FORGEJO_USERNAME }} + password: ${{ secrets.FORGEJO_TOKEN }} + - name: Build and push to Docker Package Registry + uses: docker/build-push-action@v5 with: - host: ${{ env.DEPLOY_HOST }} - username: ${{ env.DEPLOY_USER }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - script: | - screen -X -S fgo_ta_com-unlighthouse kill - rm -r -f fgo_ta_com/unlighthouse/* - - name: Copy files using rsync - run: rsync -az --stats public/* ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:~/fgo_ta_com/unlighthouse - - name: Check files on deploy target - uses: https://github.com/appleboy/ssh-action@master - with: - host: ${{ env.DEPLOY_HOST }} - username: ${{ env.DEPLOY_USER }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - script: | - cd fgo_ta_com - find unlighthouse -maxdepth 1 -printf "%p\n" + context: . + file: Dockerfile.reports + push: true + tags: forgejo.neshweb.net/firq/fgo-ta-com-website-unlighthouse:latest - deploy-unlighthouse-site: - needs: [ deploy-unlighthouse-files ] + auto-deploy-dockge: + needs: [ build-site ] if: success() runs-on: docker - env: - DEPLOY_USER: ${{ secrets.DEPLOY_USER }} - DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + container: forgejo.neshweb.net/firq/dockge-cli:0.1.2 steps: - - name: Install and update ssh + rsync + - name: Configure Dockge CLI run: | - which rsync || ( apt update -y && apt install rsync -y) - which ssh-agent || ( apt update -y && apt install openssh-client -y) - - name: Install SSH Key - uses: https://github.com/shimataro/ssh-key-action@v2 - with: - key: ${{ secrets.SSH_PRIVATE_KEY }} - known_hosts: unnecessary - - name: Adding Known Hosts - run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts - - name: Start new screen session - uses: https://github.com/appleboy/ssh-action@master - with: - host: ${{ env.DEPLOY_HOST }} - username: ${{ env.DEPLOY_USER }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - script: | - PATH="$HOME/.local/bin:$PATH" - screen -ls | grep 'fgo_ta_com-unlighthouse' | awk '{print $1}' | xargs -I % -t screen -X -S % quit - cd fgo_ta_com - screen -S fgo_ta_com-unlighthouse -dm serve unlighthouse/ -p ${{ secrets.UNLIGHTHOUSE_DEPLOY_PORT }} + dockge host '${{ vars.DOCKGE_HOST }}' + dockge login --user '${{ secrets.DOCKGE_USER }}' --password '${{ secrets.DOCKGE_CREDENTIAL }}' + - name: Check status and redeploy + run: | + dockge status fgo-ta-com-unlighthouse + dockge update fgo-ta-com-unlighthouse + dockge status fgo-ta-com-unlighthouse diff --git a/Dockerfile.reports b/Dockerfile.reports new file mode 100644 index 0000000..f745d5e --- /dev/null +++ b/Dockerfile.reports @@ -0,0 +1,6 @@ +FROM forgejo.neshweb.net/ci-docker-images/website-serve:2 AS runtime + +ADD reports /public + +EXPOSE 8081 +CMD serve public/ -p 8081 diff --git a/package.json b/package.json index 672603c..0420254 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fgo-ta-com-website", "type": "module", - "version": "0.2.2-pre.21", + "version": "0.2.2-pre.22", "scripts": { "dev": "astro dev", "start": "astro dev", diff --git a/unlighthouse.config.ts b/unlighthouse.config.ts index 4d2881a..6f7d007 100644 --- a/unlighthouse.config.ts +++ b/unlighthouse.config.ts @@ -1,10 +1,32 @@ export default { + lighthouseOptions: { + throttlingMethod: "devtools", + throttling: { + cpuSlowdownMultiplier: 4, + requestLatencyMs: 150, + downloadThroughputKbps: 1638.4, + uploadThroughputKbps: 1638.4, + }, + screenEmulation: { + width: 412, + height: 823, + deviceScaleFactor: 1.75, + } + }, puppeteerOptions: { - args: ["--no-sandbox", "--disable-setuid-sandbox"], + args: [ + "--no-sandbox", + "--disable-setuid-sandbox" + ], }, ci: { budget: 50, - buildStatic: true + buildStatic: true, + }, + scanner: { + sitemap: true, + dynamicSampling: false, + samples: 3, }, outputPath: "unlighthouse-reports", }