From 9171fda784c9b7badec435cd2f5e5bd3707be75c Mon Sep 17 00:00:00 2001 From: Firq Date: Fri, 1 Nov 2024 15:43:20 +0100 Subject: [PATCH] Unlighthouse rework with docker --- .forgejo/workflows/unlighthouse.yml | 91 ++++++++++------------------- Dockerfile.reports | 7 +++ astro.config.mjs | 2 +- package.json | 2 +- 4 files changed, 39 insertions(+), 63 deletions(-) create mode 100644 Dockerfile.reports diff --git a/.forgejo/workflows/unlighthouse.yml b/.forgejo/workflows/unlighthouse.yml index 0c3ec6c..a3d7ec1 100644 --- a/.forgejo/workflows/unlighthouse.yml +++ b/.forgejo/workflows/unlighthouse.yml @@ -22,7 +22,11 @@ jobs: - name: Checkout repository uses: https://code.forgejo.org/actions/checkout@v3 - name: Check availability - run: curl "http://localhost:8081/" + 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 "http://localhost:8081/" - name: Replace URLs @@ -35,78 +39,43 @@ jobs: name: unlighthouse-reports path: unlighthouse-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: unlighthouse-reports path: public - - name: Install SSH Key - uses: https://github.com/shimataro/ssh-key-action@v2 + - 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 firq_dev-unlighthouse kill - rm -r -f firq_dev/unlighthouse/* - - name: Copy files using rsync - run: rsync -az --stats public/* ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:~/firq_dev/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 firq_dev - find unlighthouse -maxdepth 1 -printf "%p\n" + file: Dockerfile.reports + push: true + tags: forgejo.neshweb.net/firq/firq-dev-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 'firq_dev-unlighthouse' | awk '{print $1}' | xargs -I % -t screen -X -S % quit - cd firq_dev - screen -S firq_dev-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 firq-dev-unlighthouse + dockge update firq-dev-unlighthouse + dockge status firq-dev-unlighthouse diff --git a/Dockerfile.reports b/Dockerfile.reports new file mode 100644 index 0000000..9c71e7f --- /dev/null +++ b/Dockerfile.reports @@ -0,0 +1,7 @@ +FROM forgejo.neshweb.net/ci-docker-images/website-serve:2 AS runtime + +ADD public /public +COPY ./serve.json /public/serve.json + +EXPOSE 8081 +CMD serve public/ -p 8081 diff --git a/astro.config.mjs b/astro.config.mjs index a8162b3..6dfe986 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,8 +1,8 @@ import { defineConfig } from 'astro/config'; +import mdx from "@astrojs/mdx"; import sitemap from "@astrojs/sitemap"; import astroMetaTags from "astro-meta-tags"; -import mdx from "@astrojs/mdx"; // https://astro.build/config export default defineConfig({ diff --git a/package.json b/package.json index bf0a467..6189059 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@firq/fgosite", "type": "module", - "version": "0.2.0-pre.52", + "version": "0.2.0-pre.53", "private": true, "scripts": { "dev": "astro dev",