Skip to content

Commit

Permalink
Merge pull request #13 from ZakisM/feat/playwright
Browse files Browse the repository at this point in the history
Feat/playwright
  • Loading branch information
ZakisM authored Feb 25, 2024
2 parents c5b4b3d + 0373f36 commit ea65031
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 32 deletions.
81 changes: 54 additions & 27 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy
name: Build and Deploy images

on:
push:
Expand All @@ -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 }}
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions playwright_bridge/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit ea65031

Please sign in to comment.