diff --git a/.env.example b/.env.example index 8606186..f98183b 100644 --- a/.env.example +++ b/.env.example @@ -14,14 +14,15 @@ HMAC_MAX_SKEW=300 REDIS_URL=redis://redis:6379/0 # ---- AWS / S3 ---- -# DEV: points to local MinIO. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are also -# used as MinIO root credentials — change them from the defaults before exposing MinIO. -# PROD: leave S3_ENDPOINT_URL empty and S3_USE_PATH_STYLE=false. +# DEV: points to the local LocalStack container (S3 API on :4566). LocalStack +# accepts any credentials in dev. The bucket is created automatically at startup +# (see localstack/init-s3.sh). +# PROD: leave S3_ENDPOINT_URL empty and set S3_USE_PATH_STYLE=false. AWS_ACCESS_KEY_ID=minioadmin AWS_SECRET_ACCESS_KEY=minioadmin AWS_REGION=us-east-1 S3_BUCKET=nome-do-bucket -S3_ENDPOINT_URL=http://minio:9000 +S3_ENDPOINT_URL=http://localstack:4566 S3_USE_PATH_STYLE=true # ---- CloudFront ---- diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0c27851..07a5c81 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -20,13 +20,13 @@ jobs: contents: read security-events: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - - uses: github/codeql-action/init@v3 + - uses: github/codeql-action/init@v4 with: languages: python # Python does not require a build step — go straight to analysis. - - uses: github/codeql-action/analyze@v3 + - uses: github/codeql-action/analyze@v4 with: category: "/language:python" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0c48cfb..d79126b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,14 +25,12 @@ jobs: test: name: Tests runs-on: ubuntu-latest - env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: - python-version: "3.12" + python-version: "3.14" cache: pip - name: Install dependencies @@ -51,7 +49,7 @@ jobs: environment: production steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Configure SSH run: | diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 5c0f0d2..b3c708b 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -6,15 +6,12 @@ on: tags: - "v*.*.*" -env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" - jobs: test: name: Tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Run tests inside worker container run: | @@ -23,7 +20,7 @@ jobs: -v "$(pwd)/worker:/app/worker" \ -v "$(pwd)/tests:/app/tests" \ -w /app \ - python:3.12-slim \ + python:3.14-slim \ bash -c " apt-get update >/dev/null && apt-get install -y --no-install-recommends wget ca-certificates gcc python3-dev >/dev/null 2>&1 && rm -rf /var/lib/apt/lists/* && pip install --quiet -r api/requirements.txt -r worker/requirements.txt -r tests/requirements.txt && @@ -36,11 +33,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Docker meta for API id: meta-api - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v6 with: images: ${{ secrets.DOCKERHUB_USERNAME }}/make-it-static-api tags: | @@ -50,7 +47,7 @@ jobs: - name: Docker meta for Worker id: meta-worker - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v6 with: images: ${{ secrets.DOCKERHUB_USERNAME }}/make-it-static-worker tags: | @@ -59,19 +56,19 @@ jobs: type=semver,pattern={{major}}.{{minor}} - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v4 - name: Login to Docker Hub - uses: docker/login-action@v3 + uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push API image - uses: docker/build-push-action@v6 + uses: docker/build-push-action@v7 with: context: ./api push: true @@ -82,7 +79,7 @@ jobs: cache-to: type=gha,mode=max - name: Build and push Worker image - uses: docker/build-push-action@v6 + uses: docker/build-push-action@v7 with: context: ./worker push: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 032604c..15509e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,20 +6,17 @@ on: pull_request: branches: ["main"] -env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" - jobs: test: name: pytest runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: - python-version: "3.12" + python-version: "3.14" cache: pip - name: Install dependencies @@ -30,7 +27,7 @@ jobs: - name: Lint with pylint run: | - pip install "pylint==3.3.*" + pip install "pylint==4.1.*" pylint api worker tests - name: Run tests @@ -42,7 +39,7 @@ jobs: --cov-report=xml - name: Upload coverage report - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 if: always() with: name: coverage-report diff --git a/.opencode/skills/docker-dev/SKILL.md b/.opencode/skills/docker-dev/SKILL.md index 3ba68b2..aa58803 100644 --- a/.opencode/skills/docker-dev/SKILL.md +++ b/.opencode/skills/docker-dev/SKILL.md @@ -15,7 +15,7 @@ docker network create make-it-static-network cp .env.example .env ``` -## Dev environment (with MinIO) +## Dev environment (with LocalStack) ```bash docker compose up --build @@ -25,9 +25,8 @@ Services: | Service | Address | Notes | |---------|---------|-------| | API | http://localhost:8123 | FastAPI on port 8123 | -| Site preview | http://localhost:8080 | nginx serving from MinIO | -| MinIO console | http://localhost:9001 | login: `minioadmin` / `minioadmin` | -| MinIO S3 API | http://localhost:9000 | Path-style URLs | +| Site preview | http://localhost:8080 | nginx proxying to LocalStack | +| LocalStack S3 API | http://localhost:4566 | Path-style URLs; bucket auto-created at startup | ### Verify it's working ```bash @@ -41,10 +40,9 @@ docker compose logs -f worker ``` ### Browse uploaded files +The dev S3 (LocalStack) has no web console — use `awslocal` inside the container: ```bash -# Via MinIO console: http://localhost:9001/browser/my-static-site -# Or CLI: -docker compose exec minio mc ls local/my-static-site --recursive +docker compose exec localstack awslocal s3 ls s3://my-static-site --recursive ``` ## Production environment (real S3 + CloudFront) @@ -54,7 +52,7 @@ docker compose -f docker-compose.prod.yml up -d --build ``` Differences from dev: -- **No MinIO** — uses real AWS S3. +- **No LocalStack** — uses real AWS S3. - **No nginx preview** — CloudFront serves the bucket. - API exposed only on `127.0.0.1:8000` (Caddy/nginx handles TLS externally). @@ -73,9 +71,9 @@ ORIGIN_HOST=staging.yourdomain.com ## Critical gotchas - **External network required**: `make-it-static-network` must exist before any `docker compose` command. Compose declares it as `external: true` and fails if missing. -- **MinIO credentials**: `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` double as MinIO root credentials in dev. Change defaults if exposing MinIO. -- **Bucket auto-creation**: The `minio-init` service creates the bucket on startup in dev only. -- **Path-style URLs**: Dev uses `S3_USE_PATH_STYLE=true` because MinIO doesn't support virtual-hosted style. +- **Dev credentials**: LocalStack accepts any credentials in dev; `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` are passed to boto3 but ignored by LocalStack. +- **Bucket auto-creation**: `localstack/init-s3.sh` (mounted into the container at `/etc/localstack/init/ready.d/`) creates the bucket and an anonymous-read policy on startup in dev only. +- **Path-style URLs**: Dev uses `S3_USE_PATH_STYLE=true` for LocalStack; real AWS uses virtual-hosted style. - **`.env` is gitignored**: Never commit secrets. ## Dockerfiles diff --git a/.opencode/skills/security/SKILL.md b/.opencode/skills/security/SKILL.md index 59e17f0..46e3805 100644 --- a/.opencode/skills/security/SKILL.md +++ b/.opencode/skills/security/SKILL.md @@ -35,12 +35,12 @@ cp .env.example .env ### Secrets that MUST be changed in production - `HMAC_SECRET`: Generate with `openssl rand -hex 32`. Shared with all clients. -- `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`: MinIO root credentials in dev; real AWS in prod. +- `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`: any value works in dev (LocalStack ignores them); real AWS in prod. ### Dev vs Prod S3 configuration | Env | `S3_ENDPOINT_URL` | `S3_USE_PATH_STYLE` | `AWS_ACCESS_KEY_ID` | |-----|-------------------|---------------------|---------------------| -| Dev | `http://minio:9000` | `true` | `minioadmin` | +| Dev | `http://localstack:4566` | `true` | (any) | | Prod | **empty** | `false` | Real AWS key | ## CORS diff --git a/.pylintrc b/.pylintrc index 3df0df9..e7799d8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -6,7 +6,7 @@ # resolution for site-packages) so pylint can resolve those imports. [MAIN] -py-version = 3.12 +py-version = 3.14 init-hook = 'import sys, os; sys.path[:0] = [os.path.join(os.getcwd(), "api"), os.path.join(os.getcwd(), "worker")]' # Use multiple processes to speed up Pylint (0 = auto-detect, capped at 4). diff --git a/AGENTS.md b/AGENTS.md index 7d1516f..828541c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,10 +11,10 @@ This file is written for AI coding agents. It assumes no prior knowledge of the docker network create make-it-static-network # REQUIRED — compose won't create it cp .env.example .env -# Start dev (API + Worker + Redis + MinIO + nginx preview) +# Start dev (API + Worker + Redis + LocalStack + nginx preview) docker compose up --build -# Start prod (no MinIO) +# Start prod (no LocalStack) docker compose -f docker-compose.prod.yml up -d --build # Run tests inside a temporary container (worker image does not include api/ or tests/) @@ -40,21 +40,21 @@ docker compose logs -f worker ## Project overview -**Make it Static** is a webhook-driven service that captures a rendered web page, turns it into a static site, optimizes the assets, and uploads the result to S3 (real AWS S3 or MinIO) with an optional CloudFront invalidation. +**Make it Static** is a webhook-driven service that captures a rendered web page, turns it into a static site, optimizes the assets, and uploads the result to S3 (real AWS S3 or LocalStack in dev) with an optional CloudFront invalidation. A client sends a signed `POST /publish` request with a URL and a `post_id`. The API validates the HMAC signature, enqueues a job in Redis, and an RQ worker executes the pipeline asynchronously. ## Technology stack -- **API**: Python 3.12, FastAPI 0.115, Uvicorn, Redis, RQ -- **Worker**: Python 3.12, RQ, boto3, BeautifulSoup 4, rcssmin, rjsmin, minify-html, fonttools, Pillow +- **API**: Python 3.14, FastAPI 0.165, Uvicorn, Redis, RQ +- **Worker**: Python 3.14, RQ, boto3, BeautifulSoup 4, rcssmin, rjsmin, minify-html, fonttools, Pillow - **External tools inside the worker container**: `wget` (website scraping) - **Queue / cache**: Redis 7 -- **Object storage (dev)**: MinIO (S3-compatible) +- **Object storage (dev)**: LocalStack (S3-compatible, pinned image `localstack/localstack:4.6.0`) - **Static preview (dev)**: nginx with an `envsubst`-processed template - **Container runtime**: Docker / Docker Compose v2 - **CI / CD**: GitHub Actions (pytest + pylint, CodeQL security scan, optional EC2 deploy) -- **Target Python version**: 3.12 (the Docker images use `python:3.12-slim`) +- **Target Python version**: 3.14 (the Docker images use `python:3.14-slim`) ## Repository layout @@ -63,7 +63,7 @@ A client sends a signed `POST /publish` request with a URL and a `post_id`. The ├── api/ │ ├── main.py # FastAPI application │ ├── requirements.txt # API Python dependencies -│ └── Dockerfile # python:3.12-slim image +│ └── Dockerfile # python:3.14-slim image ├── worker/ │ ├── worker.py # RQ worker entrypoint │ ├── jobs.py # Pipeline orchestration (deploy_page) @@ -72,7 +72,7 @@ A client sends a signed `POST /publish` request with a URL and a `post_id`. The │ ├── optimize.py # CSS/JS bundling + minification, image/font conversion │ ├── deploy.py # S3 upload + CloudFront invalidation │ ├── requirements.txt # Worker Python dependencies -│ └── Dockerfile # python:3.12-slim + wget image +│ └── Dockerfile # python:3.14-slim + wget image ├── tests/ │ ├── conftest.py # pytest path setup and default env vars │ ├── test_api.py # FastAPI endpoint tests @@ -83,11 +83,13 @@ A client sends a signed `POST /publish` request with a URL and a `post_id`. The │ └── requirements.txt # Test dependencies ├── nginx/ │ └── default.conf.template # Local preview nginx config +├── localstack/ +│ └── init-s3.sh # Dev: creates the S3 bucket + anonymous-read policy at container startup ├── .github/workflows/ │ ├── tests.yml # pytest + pylint on push / PR │ ├── codeql.yml # CodeQL security scan │ └── deploy.yml # Manual EC2 deploy workflow -├── docker-compose.yml # Dev stack with Redis + API + Worker + MinIO + nginx preview +├── docker-compose.yml # Dev stack with Redis + API + Worker + LocalStack + nginx preview ├── docker-compose.prod.yml # Production stack with Redis + API + Worker only ├── docker-compose.wordpress.yml # Example for adding the service to a WordPress project ├── .env.example # Environment variable template @@ -134,12 +136,12 @@ Copy `.env.example` to `.env` and adjust: | `HMAC_SECRET` | Shared secret for signing webhook requests. Generate in production with `openssl rand -hex 32`. | | `HMAC_MAX_SKEW` | Replay tolerance in seconds (default 300). | | `REDIS_URL` | Redis connection URL, e.g. `redis://redis:6379/0`. | -| `AWS_ACCESS_KEY_ID` | AWS key; also used as MinIO root user in dev. | -| `AWS_SECRET_ACCESS_KEY` | AWS secret; also used as MinIO root password in dev. | +| `AWS_ACCESS_KEY_ID` | AWS key. In dev any value works — LocalStack accepts any credentials. | +| `AWS_SECRET_ACCESS_KEY` | AWS secret. In dev any value works — LocalStack accepts any credentials. | | `AWS_REGION` | AWS region (e.g. `us-east-1`). | | `S3_BUCKET` | Target S3 bucket name. | | `S3_ENDPOINT_URL` | Custom S3 endpoint. Leave empty + set `S3_USE_PATH_STYLE=false` for real AWS. | -| `S3_USE_PATH_STYLE` | `true` for MinIO, `false` for AWS virtual-hosted style. | +| `S3_USE_PATH_STYLE` | `true` for LocalStack in dev, `false` for AWS virtual-hosted style. | | `CLOUDFRONT_DISTRIBUTION_ID` | Global fallback distribution for invalidation. Optional per-request override via payload. | | `CORS_ORIGINS` | Comma-separated list of allowed CORS origins. Defaults to `*` in dev. Restrict in production. | | `ORIGIN_HOST` | **Local preview only** — hostname used by the dev nginx rewrite. | @@ -172,12 +174,11 @@ Copy `.env.example` to `.env` and adjust: Dev services: - API: http://localhost:8123 - Local static preview: http://localhost:8080 -- MinIO console: http://localhost:9001 (login `minioadmin` / `minioadmin` unless changed) -- MinIO S3 API: http://localhost:9000 +- LocalStack S3 API: http://localhost:4566 (bucket auto-created at startup; inspect objects with `docker compose exec localstack awslocal s3 ls s3:// --recursive`) ### Production -Use `docker-compose.prod.yml` (no MinIO, API bound to localhost, TLS handled by Caddy/nginx/ALB): +Use `docker-compose.prod.yml` (no LocalStack, API bound to localhost, TLS handled by Caddy/nginx/ALB): ```bash docker compose -f docker-compose.prod.yml up -d @@ -235,7 +236,9 @@ The tests mock Redis/RQ and do **not** require a running Redis or Docker stack f - Filename normalization, URL rewriting, and HTML absolutization (`test_postprocess.py`) - S3 upload, CloudFront invalidation, font/image conversion, and subprocess behavior (`test_integration.py`) -The worker container uses **Python 3.12**, which is the target version for this project. Running tests inside Docker avoids host interpreter issues. +The worker container uses **Python 3.14**, which is the target version for this project. Running tests inside Docker avoids host interpreter issues. + +`httpx2` in `tests/requirements.txt` is Pydantic's maintained successor of `httpx` (used by starlette's TestClient), so leave it as-is — do not "fix" it back to `httpx`. ## Code style and conventions @@ -278,10 +281,10 @@ signature or attribution (e.g., no "Generated by ...", "Signed-off-by AI", - HMAC-SHA256 signature over the raw request body - Timestamp within `HMAC_MAX_SKEW` to prevent replays - URL scheme is `http` or `https` - - URL hostname is not an internal/loopback/link-local/reserved IP address + - URL hostname must resolve to a globally routable address — private/loopback/link-local/reserved and CGNAT (100.64.0.0/10) IP literals are rejected - `scrape.sh` rejects WordPress admin, REST, feeds, pagination, search, and attachment URLs via `--reject-regex`. - Google Fonts domains are excluded from scraping because the CSS is User-Agent-specific; those links remain external and load from Google at runtime. -- AWS credentials in dev are reused as MinIO credentials. Change them before exposing MinIO. +- LocalStack accepts any credentials in dev; the `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` env vars are passed to boto3 but ignored by LocalStack. - The production deploy workflow uses `environment: production` and manual trigger by default. - Never commit security scan reports (e.g. `bandit-report.txt`, `pip-audit-*.json`) or private audit documents (e.g. `SECURITY_AUDIT.md`). Run scans inside Docker and keep reports local/private. @@ -302,7 +305,7 @@ The workflow runs tests, rsyncs the repository to `/opt/make-it-static/` on the - **HMAC auth**: All `/publish` requests require `X-Signature` (hex HMAC-SHA256 of raw body) and `X-Timestamp` headers. Replay window: 300s (configurable via `HMAC_MAX_SKEW`). - **CORS**: Open (`*`) in dev. Restrict in production via `CORS_ORIGINS`. - **`.env` is gitignored**. Always copy from `.env.example` first. -- **Dev uses MinIO** at `http://minio:9000` with path-style URLs. Prod: leave `S3_ENDPOINT_URL` empty, set `S3_USE_PATH_STYLE=false`. +- **Dev uses LocalStack** at `http://localstack:4566` with path-style URLs; the bucket named by `S3_BUCKET` is created automatically at container startup (with an anonymous-read policy) by `localstack/init-s3.sh`, mounted at `/etc/localstack/init/ready.d/`. Prod: leave `S3_ENDPOINT_URL` empty, set `S3_USE_PATH_STYLE=false`. - **Deploy workflow** (`.github/workflows/deploy.yml`) is manual-only (`workflow_dispatch`). Tests must pass before deploy. ## CI workflows diff --git a/README.md b/README.md index d4b7e52..8ff4a62 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Client (any HTTP client, CMS plugin, CI/CD, etc.) - **API** (FastAPI): receives webhook, validates HMAC, enqueues job. Endpoints: `POST /publish`, `GET /jobs/{id}`, `DELETE /jobs/{id}`, `GET /health`. - **Worker** (RQ): consumes the queue and runs the full pipeline. - **Redis**: job queue. -- **MinIO** (dev only): local S3 replacement. +- **LocalStack** (dev only): local S3 replacement (S3 API on port 4566; bucket auto-created at startup). --- @@ -54,7 +54,7 @@ Client (any HTTP client, CMS plugin, CI/CD, etc.) cp .env.example .env ``` -`.env.example` is already pre-configured to run with MinIO. No AWS credentials are needed in dev. The only field you may want to adjust is `ORIGIN_HOST` — it defines which hostname is stripped from URLs in the HTML: +`.env.example` is already pre-configured to run with LocalStack. No AWS credentials are needed in dev. The only field you may want to adjust is `ORIGIN_HOST` — it defines which hostname is stripped from URLs in the HTML: ```bash # .env @@ -73,7 +73,7 @@ Wait for the images to build on the first run. When ready you will see: ``` worker-1 | RQ Worker started. Waiting for jobs in queue 'deploys'... api-1 | INFO: Application startup complete. -minio-init-1 | Bucket ready. +localstack-1 | Bucket ready. ``` Available services: @@ -82,8 +82,7 @@ Available services: |---------|---------| | API | http://localhost:8123 | | Site preview | http://localhost:8080 | -| MinIO console | http://localhost:9001 (login: `minioadmin` / `minioadmin`) | -| MinIO S3 API | http://localhost:9000 | +| LocalStack S3 API | http://localhost:4566 | ### 3. Check API health @@ -145,13 +144,10 @@ While the worker is processing, the status will be `started`. When finished: ### Step 3 — View the published files -Access the MinIO console at http://localhost:9001/browser/my-static-site and browse the bucket. Files appear replicating the URL path structure. - -Or via CLI: +The dev S3 (LocalStack) has no web console — inspect the bucket with `awslocal` inside the container. Files appear replicating the URL path structure: ```bash -# list files in the bucket -docker compose exec minio mc ls local/my-static-site --recursive +docker compose exec localstack awslocal s3 ls s3://my-static-site --recursive ``` ### Follow worker logs in real time @@ -176,7 +172,7 @@ You will see each pipeline step: ## Running in production (real S3 + CloudFront) -1. Use `docker-compose.prod.yml` (without MinIO): +1. Use `docker-compose.prod.yml` (without the local S3 stack): ```bash docker compose -f docker-compose.prod.yml up -d @@ -222,13 +218,13 @@ You can add them to an existing Docker Compose project (for example, alongside W # HMAC secret shared with the WordPress plugin MAKE_IT_STATIC_HMAC_SECRET=$(openssl rand -hex 32) - # S3 / MinIO credentials + # S3 credentials AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... AWS_REGION=us-east-1 S3_BUCKET=... S3_ENDPOINT_URL= # leave empty for real AWS - S3_USE_PATH_STYLE=false # true for MinIO, false for AWS + S3_USE_PATH_STYLE=false # true for LocalStack (dev), false for AWS # Optional CLOUDFRONT_DISTRIBUTION_ID=... @@ -257,8 +253,8 @@ You can add them to an existing Docker Compose project (for example, alongside W | `AWS_SECRET_ACCESS_KEY` | S3 secret key. | | `AWS_REGION` | AWS region (e.g. `us-east-1`). | | `S3_BUCKET` | Target S3 bucket. | -| `S3_ENDPOINT_URL` | Custom endpoint. Leave empty for AWS. Use `http://minio:9000` for MinIO. | -| `S3_USE_PATH_STYLE` | `true` for MinIO, `false` for AWS. | +| `S3_ENDPOINT_URL` | Custom endpoint. Leave empty for AWS. Use `http://localstack:4566` for a local LocalStack dev stack. | +| `S3_USE_PATH_STYLE` | `true` for LocalStack, `false` for AWS. | ### Optional environment variables @@ -570,8 +566,8 @@ pm.request.headers.add({ key: "Content-Type", value: "application/json" }); ``` make-it-static/ -├── docker-compose.yml # dev (with MinIO) -├── docker-compose.prod.yml # prod (without MinIO) +├── docker-compose.yml # dev (with LocalStack) +├── docker-compose.prod.yml # prod (without LocalStack) ├── docker-compose.wordpress.yml # example for WordPress integration ├── .env.example ├── IAM_POLICY.json # minimum IAM policy for the AWS key diff --git a/api/Dockerfile b/api/Dockerfile index 030a4f8..18dc144 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim +FROM python:3.14-slim LABEL org.opencontainers.image.source="https://github.com/daniloriedel/make-it-static" LABEL org.opencontainers.image.description="Make it Static — FastAPI webhook service" diff --git a/api/main.py b/api/main.py index 60f9021..77d2f1e 100644 --- a/api/main.py +++ b/api/main.py @@ -35,10 +35,12 @@ def _validate_url(url: str) -> None: if not parsed.hostname: raise HTTPException(status_code=400, detail="url must have a valid hostname") - # Reject literal internal IP addresses + # Reject any non-public IP literal. is_global covers private/loopback/ + # link-local/reserved space and also 100.64.0.0/10 (CGNAT), which newer + # ipaddress versions classify as neither private nor reserved. try: addr = ipaddress.ip_address(parsed.hostname) - if addr.is_private or addr.is_loopback or addr.is_link_local or addr.is_reserved: + if not addr.is_global: raise HTTPException(status_code=400, detail="url must not use internal IP addresses") except ValueError: pass # It's a domain name, not an IP literal diff --git a/api/requirements.txt b/api/requirements.txt index 8b1d958..7ca7b24 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -1,4 +1,4 @@ -fastapi==0.137.1 -uvicorn[standard]==0.34.2 -redis==5.0.8 -rq==1.16.2 +fastapi==0.165.0 +uvicorn[standard]==0.54.0 +redis==8.2.0 +rq==3.0 diff --git a/docker-compose.wordpress.yml b/docker-compose.wordpress.yml index a29c835..e04ead5 100644 --- a/docker-compose.wordpress.yml +++ b/docker-compose.wordpress.yml @@ -10,12 +10,12 @@ # # Required environment variables: # HMAC_SECRET — shared secret between plugin and API -# AWS_ACCESS_KEY_ID — S3/MinIO access key -# AWS_SECRET_ACCESS_KEY — S3/MinIO secret key +# AWS_ACCESS_KEY_ID — S3 access key +# AWS_SECRET_ACCESS_KEY — S3 secret key # AWS_REGION — e.g. us-east-1 # S3_BUCKET — target bucket name -# S3_ENDPOINT_URL — empty for real AWS; e.g. http://minio:9000 for MinIO -# S3_USE_PATH_STYLE — true for MinIO; false for AWS +# S3_ENDPOINT_URL — empty for real AWS; e.g. http://localstack:4566 for a local LocalStack dev stack +# S3_USE_PATH_STYLE — true for LocalStack; false for AWS # # Optional: # CLOUDFRONT_DISTRIBUTION_ID — default CloudFront distribution to invalidate diff --git a/docker-compose.yml b/docker-compose.yml index aadac3b..ab3de1f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,57 +23,40 @@ services: env_file: .env depends_on: - redis - - minio + - localstack networks: - default - make-it-static-network # ---- Local S3 for testing (remove in prod) ---- - minio: - image: minio/minio:latest + localstack: + image: localstack/localstack:4.6.0 restart: unless-stopped - command: server /data --console-address ":9001" environment: - MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID} - MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY} + SERVICES: s3 + EAGER_SERVICE_LOADING: "1" env_file: .env ports: - - "9000:9000" - - "9001:9001" + - "4566:4566" volumes: - - minio-data:/data + - localstack-data:/var/lib/localstack + - ./localstack/init-s3.sh:/etc/localstack/init/ready.d/init-s3.sh:ro # ---- Local static site preview (mirrors CloudFront) ---- preview: - image: nginx:alpine + image: nginx:1.30-alpine restart: unless-stopped depends_on: - - minio - - minio-init + - localstack ports: - "8080:80" volumes: - ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro env_file: .env - # automatically creates the bucket on startup - minio-init: - image: minio/mc:latest - depends_on: - - minio - env_file: .env - entrypoint: > - /bin/sh -c " - sleep 3 && - mc alias set local http://minio:9000 $${AWS_ACCESS_KEY_ID} $${AWS_SECRET_ACCESS_KEY} && - mc mb -p local/$${S3_BUCKET} || true && - mc anonymous set download local/$${S3_BUCKET} && - echo 'Bucket ready.' - " - volumes: redis-data: - minio-data: + localstack-data: networks: make-it-static-network: diff --git a/localstack/init-s3.sh b/localstack/init-s3.sh new file mode 100755 index 0000000..5fe16a7 --- /dev/null +++ b/localstack/init-s3.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Dev-only: create the S3 bucket in LocalStack and allow anonymous reads so the +# nginx preview can serve uploaded sites without signing requests. Mounted into +# LocalStack at /etc/localstack/init/ready.d/ — it runs once S3 is available. +awslocal s3 mb "s3://${S3_BUCKET}" || true +awslocal s3api put-bucket-policy --bucket "${S3_BUCKET}" --policy "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::${S3_BUCKET}/*\"}]}" +echo "Bucket ready." diff --git a/nginx/default.conf.template b/nginx/default.conf.template index 9c25fc8..64a84a9 100644 --- a/nginx/default.conf.template +++ b/nginx/default.conf.template @@ -14,7 +14,7 @@ server { rewrite ^([^.]+)$ /${S3_BUCKET}/${ORIGIN_HOST}$1/index.html break; rewrite ^(.*)$ /${S3_BUCKET}/${ORIGIN_HOST}$1 break; - proxy_pass http://minio:9000/; - proxy_set_header Host minio:9000; + proxy_pass http://localstack:4566/; + proxy_set_header Host localstack:4566; } } diff --git a/tests/requirements.txt b/tests/requirements.txt index b914324..3cac5ee 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ -pytest>=8.0 -pytest-cov>=5.0 -httpx2 +pytest>=9.0 +pytest-cov>=7.0 +httpx2>=2.0 diff --git a/tests/test_api.py b/tests/test_api.py index 6f80de1..75b7826 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -92,13 +92,21 @@ def test_publish_file_url_returns_400(): def test_publish_internal_ip_returns_400(): """URLs pointing to internal IP addresses are rejected (SSRF mitigation).""" - for ip in ("127.0.0.1", "10.0.0.1", "169.254.169.254", "192.168.1.1"): + for ip in ("127.0.0.1", "10.0.0.1", "169.254.169.254", "192.168.1.1", "100.64.0.1"): body, headers = _sign({"url": f"http://{ip}/", "post_id": 1, "ts": int(time.time())}) resp = client.post("/publish", content=body, headers=headers) assert resp.status_code == 400, f"expected 400 for {ip}, got {resp.status_code}" assert "internal IP" in resp.json()["detail"] +def test_publish_public_ip_allowed(): + """Globally routable IP literals pass the SSRF check (no over-blocking).""" + body, headers = _sign({"url": "http://93.184.216.34/", "post_id": 1, "ts": int(time.time())}) + resp = client.post("/publish", content=body, headers=headers) + assert resp.status_code == 200 + assert "job_id" in resp.json() + + def test_publish_extra_cdn_not_list_returns_400(): """extra_cdn as a plain string (not a list) returns 400.""" payload = { diff --git a/worker/Dockerfile b/worker/Dockerfile index 82a8e08..349a619 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim +FROM python:3.14-slim LABEL org.opencontainers.image.source="https://github.com/daniloriedel/make-it-static" LABEL org.opencontainers.image.description="Make it Static — RQ worker" @@ -6,15 +6,12 @@ LABEL org.opencontainers.image.description="Make it Static — RQ worker" RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ ca-certificates \ - gcc \ - python3-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt \ - && apt-get purge -y --auto-remove gcc python3-dev +RUN pip install --no-cache-dir -r requirements.txt COPY . . RUN chmod +x scrape.sh diff --git a/worker/requirements.txt b/worker/requirements.txt index 8d4e563..ebf2b35 100644 --- a/worker/requirements.txt +++ b/worker/requirements.txt @@ -1,9 +1,9 @@ -redis==5.0.8 -rq==1.16.2 -boto3==1.35.20 -beautifulsoup4==4.12.3 -rcssmin==1.1.2 -rjsmin==1.2.2 +redis==8.2.0 +rq==3.0 +boto3==1.44.9 +beautifulsoup4==4.15.0 +rcssmin==1.3.0 +rjsmin==1.3.0 minify-html==0.18.1 -fonttools[woff]>=4.47.0 -Pillow>=10.0.0 +fonttools[woff]==4.68.0 +Pillow==13.0.0