diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d0e2168 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv + +.git diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..8502c1d --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,57 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ "main", "master" ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} + ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: ${{ github.event_name }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 0000000..f9a8989 --- /dev/null +++ b/BUILD.md @@ -0,0 +1,9 @@ +# Build (Docker) + +Also works with Podman. + +```sh +docker build -t 'chromedriver-http-proxy' . +docker run --rm -p "32323:32323" chromedriver-http-proxy +``` + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fed03b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM ghcr.io/astral-sh/uv:debian-slim + +ENV PROXY_PORT=32323 +ENV PROXY_HOST=0.0.0.0 +ENV SCRAPER_WAIT_TIME=10 +ENV SCRAPER_HEADLESS=True +ENV SCRAPER_USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + +WORKDIR /app +COPY uv.lock pyproject.toml /app +RUN uv sync --locked + +RUN apt-get update && apt-get install -y \ + wget \ + gnupg \ + ca-certificates \ + && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \ + && apt-get update \ + && apt-get install -y google-chrome-stable \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +COPY . /app + +CMD uv run proxy.py \ + --port="$PROXY_PORT"\ + --host="$PROXY_HOST"\ + --wait="$SCRAPER_WAIT_TIME" \ + --headless="$SCRAPER_HEADLESS" \ + --user-agent="$SCRAPER_USER_AGENT" diff --git a/README.md b/README.md index d0d6c88..92de96b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ This proxy has no authentication, and I don't plan to add any (PRs welcome thoug ## TODO -- [ ] Docker image +- [ ] ARM Docker images - [ ] Send JS/CSS to the client - [ ] Custom Chromium binary locations - [ ] More CLI arguments to control ChromeDriver behavior @@ -60,6 +60,7 @@ This proxy has no authentication, and I don't plan to add any (PRs welcome thoug - [ ] Screenshot endpoint - [ ] Allow custom headers - [ ] POST requests +- [x] Docker image ## Similiar Projects