zfcsoftware / cf-clearance-scraper

This package provides an api that returns cookies (cf-clearance) that you can request on a website protected by Cloudflare WAF (corporate or normal) without being blocked by WAF.
MIT License
86 stars 8 forks source link

Docker container for arm64 #5

Open jairoxyz opened 3 weeks ago

jairoxyz commented 3 weeks ago

Thanks for the great work. Is it possible to create a docker image and run the container on arm64? The package google-chrome-stable would need to be replaced with chromium-browser which is available for ARM. Would that work?

Jx-

zfcsoftware commented 3 weeks ago

It should work without modification. Please let me know if you have problems. I will test and update.

jairoxyz commented 3 weeks ago

Hi there, so far I managed to build on AMD using chromium install from debian repository. I believe wget, gnupg, ca-certs and apt-transport-https are not needed if we don't use the google repo, right? This is the dockerfile I use:

FROM node:22-slim

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETARCH

RUN printf "I am running on ${BUILDPLATFORM}, building for ${TARGETPLATFORM}\n"

# Install necessary dependencies for running Chrome
RUN apt-get update && apt-get install -y \
    xvfb \
    chromium \
    && rm -rf /var/lib/apt/lists/*

# Set up the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install Node.js dependencies
RUN npm install
RUN npm install -g pm2

# Copy the rest of the application code
COPY . .

# Expose the port your app runs on
EXPOSE 3001

# Command to run the application
CMD ["pm2-runtime", "index.js"]

Next I want to try if a smaller alpine base image works too :)

Jx-

zfcsoftware commented 3 weeks ago

Hi there, so far I managed to build on AMD using chromium install from debian repository. I believe wget, gnupg, ca-certs and apt-transport-https are not needed if we don't use the google repo, right? This is the dockerfile I use:

FROM --platform=${BUILDPLATFORM} node:22.2-slim

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETARCH

RUN printf "I am running on ${BUILDPLATFORM}, building for ${TARGETPLATFORM}\n"

# Install necessary dependencies for running Chrome
RUN apt-get update && apt-get install -y \
    xvfb \
    chromium \
    && rm -rf /var/lib/apt/lists/*

# Set up the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install Node.js dependencies
RUN npm install
RUN npm install -g pm2

# Copy the rest of the application code
COPY . .

# Expose the port your app runs on
EXPOSE 3001

# Command to run the application
CMD ["pm2-runtime", "index.js"]

Next I want to try if a smaller alpine base image works too :)

Jx-

Honestly, I didn't care much about the Dockerfile, copilot filled it automatically. I did some tests and started using it. You can test it by deleting dependencies one by one.

jairoxyz commented 3 weeks ago

My build with buildx for arm64 completed and container runs fine on my Rpi but there is an error with Chrome:

Failed to launch the browser process!
/home/admin/.cache/puppeteer/chrome/linux-124.0.6367.201/chrome-linux64/chrome: 3: Syntax error: Unterminated quoted string

I also tried locally with node and installed xvfb and chromium with apt-get but same error.

Maybe I have to tell puppeteer where chromium is:

const browser: puppeteer.Browser = await puppeteer.launch({
  executablePath: '/usr/bin/chromium', <-------
  }); 

Yes, that works. So, strange it would not be able to launch the chrome browser packaged with puppeteer but it works with chromium installed with apt-get.