When building this blog, I wanted full control over the deployment pipeline while offloading the heavy lifting of analytics to a serverless backend. Here is a raw breakdown of how I handle both.
1. Custom CI/CD: FastAPI, Temporal & Portainer
I don’t use GitHub Actions or Jenkins. I built my own custom CI/CD engine in Python using Temporal to orchestrate the builds.
My pipeline is split into a server and a worker:
- The Webhook Server (FastAPI): Receives push events from GitHub. It verifies the HMAC signature and triggers a Temporal workflow (
BuildAndDeployWorkflow). By using Temporal’sWorkflowIDConflictPolicy.TERMINATE_EXISTING, it automatically cancels older builds on the same branch if I push a new commit rapidly. - The Worker (Activities): Executes the actual pipeline steps asynchronously.
- It performs a shallow Git clone of the repo.
- It shells out to the Docker CLI to build the Astro blog image.
- It pushes the image to my local registry (
localhost:5000). - It hits a webhook on my local Portainer instance (
192.168.4.233:9443) which automatically pulls the new image and re-deploys the stack.
By building it with Temporal, I get built-in retries, timeouts, and a complete UI for observing every step of my deployment pipeline. Here is exactly what that orchestrator looks like in Python:
from datetime import timedelta
from temporalio import workflow
@workflow.defn
class BuildAndDeployWorkflow:
@workflow.run
async def run(self, repo_url: str, dockerfile_path: str, image_tag: str, registry_url: str, portainer_id: str) -> str:
dest_path = f"/tmp/{workflow.info().workflow_id}"
# Step 1: Clone the repository
await workflow.execute_activity(
"clone_repository",
args=[repo_url, dest_path],
schedule_to_close_timeout=timedelta(minutes=5),
)
# Step 2: Build the Docker image
await workflow.execute_activity(
"build_docker_image",
args=[dest_path, dockerfile_path, image_tag, "."],
schedule_to_close_timeout=timedelta(minutes=10),
)
# Step 3: Push the Docker image to the registry
await workflow.execute_activity(
"push_docker_image",
args=[image_tag, registry_url],
schedule_to_close_timeout=timedelta(minutes=5),
)
# Step 4: Notify Portainer about the new deployment
await workflow.execute_activity(
"notify_portainer",
portainer_id,
schedule_to_close_timeout=timedelta(minutes=2),
)
return "Build and deployment completed successfully."
2. Analytics: Replacing Google Analytics with ClickHouse (via Tinybird)
I don’t use Google Analytics. It’s bloated, privacy-invasive, and you don’t actually own the raw data.
Instead, I built a tiny, custom tracking script directly into my Astro <BaseHead /> that streams events to Tinybird, a serverless platform built on top of ClickHouse (an insanely fast columnar database).
Here is exactly how it works internally:
1. The Dumb Frontend (Unified Ingestion)
The frontend does almost zero work. Whether the browser is reporting a page view, a user’s location via ipapi.co, or a Web Vital (like LCP or TTFB), it fires a single POST request to one endpoint: analytics_events.
The data is sent as a hybrid schema: strict top-level columns (timestamp, session ID, action) and a flexible, stringified JSON payload column that holds the specific event metrics.
2. The Smart Backend (ClickHouse Materialized Views)
This is where ClickHouse shines. Instead of parsing that JSON on the fly every time I load my dashboard, the backend uses Tinybird Materialized Views.
When a raw JSON event hits the analytics_events table, a Materialized View instantly triggers. It uses ClickHouse’s lightning-fast JSONExtract functions to pull the metrics out of the JSON string and writes them into a strictly typed, columnar MergeTree table (e.g., pulling out the Web Vitals into exact float columns).
3. Incremental Aggregation
For dashboards, you don’t want to scan millions of rows to count daily visitors. ClickHouse uses AggregatingMergeTree engines to continuously pre-aggregate the data in the background. By the time I open my analytics dashboard, the math is already done.
By decoupling the raw JSON ingestion from the ClickHouse parsing, my Astro frontend stays incredibly lightweight, and I get sub-second dashboard queries over my own raw data.