From 28414afd117d068e6695e6a889649c9cb8c7746f Mon Sep 17 00:00:00 2001 From: zak <8143258+ZakisM@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:38:07 +0000 Subject: [PATCH 1/2] feat: use playwright instead of splash --- Dockerfile | 12 ++++++++++-- docker-compose.yml | 2 +- playwright_bridge/index.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94304b4..8c17f18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,21 @@ FROM lukemathwalker/cargo-chef:latest-rust-latest AS chef WORKDIR /app FROM chef AS planner -COPY . . +COPY Cargo.lock . +COPY Cargo.toml . +COPY /src ./src RUN cargo chef prepare --recipe-path recipe.json FROM chef AS builder +ENV SQLX_OFFLINE='true' COPY --from=planner /app/recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json -COPY . . +COPY Cargo.lock . +COPY Cargo.toml . +COPY /.sqlx ./.sqlx +COPY /.env ./.env +COPY /migrations ./migrations +COPY /src ./src RUN mkdir -p data RUN cargo build --release diff --git a/docker-compose.yml b/docker-compose.yml index 6d00853..ac07395 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: environment: - DISCORD_TOKEN=$DISCORD_TOKEN volumes: - - ./general_notifier_data:/data + - ./general_notifier_data:/app/data playwright: image: zakism/general-notifier-playwright:latest diff --git a/playwright_bridge/index.ts b/playwright_bridge/index.ts index 31c442b..b5aab08 100644 --- a/playwright_bridge/index.ts +++ b/playwright_bridge/index.ts @@ -1,4 +1,4 @@ -import {webkit, type Browser} from 'playwright'; +import {chromium, type Browser} from 'playwright'; function invariant(condition: any, message: string): asserts condition { if (condition) return; @@ -11,7 +11,7 @@ let browser: Browser; const getPageSource = async (url: string, timeout: number) => { if (!browser) { try { - browser = await webkit.launch(); + browser = await chromium.launch({headless: true}); } catch (error) { console.error(error); process.exit(1); @@ -22,6 +22,10 @@ const getPageSource = async (url: string, timeout: number) => { try { const page = await browser.newPage(); + await page.route( + '**/*.{css,png,jpg,jpeg,mp4,mp3,ttf,ttf2,woff,woff2,webp,svg,xml}', + (route) => route.abort(), + ); await page.goto(url, {timeout: timeout * 1000}); res = await page.content(); From 0373f36779385f7bf034f3cdfb6890b9e125bf09 Mon Sep 17 00:00:00 2001 From: zak <8143258+ZakisM@users.noreply.github.com> Date: Sun, 25 Feb 2024 17:38:34 +0000 Subject: [PATCH 2/2] feat: use playwright inside GitHub workflow --- .github/workflows/deploy.yml | 81 ++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 693fcb7..eddee81 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy +name: Build and Deploy images on: push: @@ -7,29 +7,56 @@ on: branches: [ master ] jobs: - build: - name: Deploy - runs-on: ubuntu-latest - env: - SQLX_OFFLINE: true - steps: - - uses: actions/checkout@v2 - - name: Download Sqlite3 - run: sudo apt-get install libsqlite3-dev - - name: Run tests - run: cargo test --verbose - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1.3.0 - - name: Login to DockerHub - uses: docker/login-action@v1.9.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and Push to Docker - uses: docker/build-push-action@v2.5.0 - with: - file: ./Dockerfile - push: true - cache-from: type=registry,ref=zakism/general-notifier:latest - cache-to: type=inline - tags: zakism/general-notifier:latest + - build-and-push-general-notifier: + name: Build and Deploy general-notifier + runs-on: ubuntu-latest + env: + SQLX_OFFLINE: true + steps: + - uses: actions/checkout@v2 + - name: Download Sqlite3 + run: sudo apt-get install libsqlite3-dev + - name: Run tests + run: cargo test --verbose + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1.3.0 + - name: Login to DockerHub + uses: docker/login-action@v1.9.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and Push to Docker + uses: docker/build-push-action@v2.5.0 + with: + file: ./Dockerfile + push: true + cache-from: type=registry,ref=zakism/general-notifier:latest + cache-to: type=inline + tags: zakism/general-notifier:latest + - build-and-push-general-notifier-playwright: + name: Build and Deploy general-notifier-playwright + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GHCR_PASSWORD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: ./playwright_bridge + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}