AWS / Automation

Hugo project - design and deployment

The new blog site design and initial delivery pipeline

Objectives

Sprint 1

  • Make a personal blog site.
  • Build a repeatable CI/CD pipeline.
  • Validate Hugo content before publishing.
  • Deploy each successful main commit automatically.

Sprint 2

  • Use AWS rather than GitHub Pages for the production origin.
  • Manage the S3, CloudFront, ACM, Route 53 and deployment-role resources with Terraform.
  • Keep long-lived AWS credentials out of GitHub Actions.

Backlog

  • Review commenting and feedback options.
  • Allow other projects to contribute articles and trigger a new blog deployment.
  • Add an AI-assisted editorial process with a clear human review boundary.

Production deployment

The intended production path is deliberately small:

GitHub push to main
  -> GitHub Actions
  -> build and validate with Hugo
  -> upload public/ to a private S3 bucket
  -> invalidate the CloudFront distribution
  -> serve blog.keithmarston.me.uk

GitHub Actions is the automation service, but it does not have to host the site. GitHub Pages would be simpler, while S3 and CloudFront provide direct control over the origin, caching, response headers and AWS infrastructure.

The deployment job should use GitHub’s OpenID Connect integration to assume a narrowly scoped AWS role. The role should be restricted to the K’loger repository and a protected production environment. Do not store an AWS access key in GitHub secrets.

A deployment should:

  1. Check formatting and required generated files.
  2. Run the production Hugo build with hugo --minify.
  3. Upload the verified public/ directory with aws s3 sync --delete.
  4. Invalidate CloudFront only after the upload succeeds.

CloudFront accesses a private S3 bucket through Origin Access Control. Public S3 website hosting is not needed.

OpenTofu boundary

OpenTofu manages the durable delivery infrastructure using Terraform-compatible .tf configuration:

  • the private S3 origin bucket;
  • CloudFront and its Origin Access Control configuration;
  • the CloudFront redirect function;
  • the ACM certificate in us-east-1;
  • Route 53 aliases for the public hostnames;
  • the GitHub Actions OIDC trust and publishing policy.

The ACM certificate must be in us-east-1 because it is attached to CloudFront. DNS validation records and the public website records remain in the keithmarston.me.uk hosted zone.

Infrastructure changes and content deployment are separate concerns. An OpenTofu plan can validate a proposed infrastructure change without granting the content workflow permission to change infrastructure.

Domain names and the www redirect

Route 53 provides DNS, not HTTP redirects. An alias or CNAME from one hostname to another does not by itself change the URL shown in the browser.

To redirect www.keithmarston.me.uk permanently to the blog, the two hostnames can point at the same CloudFront distribution:

blog.keithmarston.me.uk  -> CloudFront -> S3 origin
www.keithmarston.me.uk   -> CloudFront -> 301/308 redirect to blog host

The ACM certificate must contain both names. A CloudFront Function can inspect the host header and preserve the requested path and query string while returning blog.keithmarston.me.uk as the canonical hostname.

An ordinary DNS-only CNAME is therefore not enough. A redirect also has to account for HTTPS, which is why the redirect hostname should be covered by the certificate and handled at the CloudFront edge.

Hosting alternatives

GitHub Pages

GitHub Pages offers the shortest route from a Hugo repository to a public site. It is suitable for a prototype or if the AWS stack is not a learning objective.

Limitations include less control over edge headers, caching and redirects, and the constraint that a Pages site is centred on a single custom domain. A second hostname still needs additional handling for a genuine URL redirect.

Cloudflare Pages or Netlify

These services can build Hugo from GitHub and provide custom domains, certificates, preview deployments and redirects with less infrastructure code. The trade-off is that they move the final site outside the intended AWS architecture.

For K’loger, GitHub Pages is a useful fallback, but the selected production design remains GitHub Actions, S3 and CloudFront.

Article-focused editorial automation

The delivery design uses GitHub pull requests as the QA and review boundary. AI can prepare a candidate, but it cannot independently approve or publish production content.

The intended chain is:

human content
→ pull request
→ AI editorial pipeline
→ AI editorial commit
→ build exact committed revision
→ deploy QA
→ human review and approval
→ merge to main
→ deploy production

main therefore represents the intended production state.

Pull request workflow

When a pull request is opened or updated:

  1. Identify only the article folders changed by the pull request.
  2. Decide whether their editorial input has changed since a successful review.
  3. Skip articles that match the previous reviewed output.
  4. Wake the Mac mini if necessary.
  5. Run the changed articles through the Ollama editorial pipeline.
  6. Validate and commit the final editorial changes back to the PR branch.
  7. Build Hugo from the exact committed revision.
  8. Deploy that revision to qa.keithmarston.me.uk.

Later human or AI commits to the pull request redeploy the QA candidate. The workflow must detect the AI’s own editorial output so that its commit does not cause another review and an infinite loop.

A merge to main does not run the editors again. It validates the already-reviewed revision, builds Hugo, publishes production and invalidates the production CloudFront cache.

Editorial architecture

Use one Ollama model sequentially with several editorial personas instead of running independent models concurrently.

  1. Technical reviewer.
  2. Fact checker.
  3. Style reviewer.
  4. Readability reviewer.
  5. Final editor.

The first stages should produce structured findings. The final editor is the only stage permitted to make the coherent final rewrite using those findings. After stage 5, the orchestration layer validates the result, updates editorial metadata, creates one commit and pushes it to the pull-request branch.

For example:

editorial: complete AI review of zabbix-at-home

Article review boundary

An individual article directory is the unit of editorial work:

content/posts/zabbix-at-home/
├── index.md
├── diagram.png
└── screenshot.png

Detailed editorial evidence and state can be stored separately:

.editorial/posts/zabbix-at-home/
├── state.json
├── technical.json
├── facts.json
├── style.json
├── readability.json
└── final.json

The model receives only the relevant article directory plus explicitly required site and editorial context. It does not need the entire content/ tree.

Editorial change detection

The editorial input includes index.md, relevant local assets and the pipeline policy version. State records the relationship between the input and resulting output:

{
  "source_hash": "sha256:abc...",
  "output_hash": "sha256:def...",
  "reviewed_commit": "8c42abc",
  "pipeline_version": 3,
  "status": "passed"
}
  • source_hash identifies the input given to the editorial process.
  • output_hash identifies the approved output produced by the editorial process.
  • reviewed_commit records the repository revision that completed review.
  • pipeline_version can invalidate prior reviews when prompts or policy change.

If the current article matches its previous output_hash, the workflow skips it. Hashing the editor’s output as if it were fresh human input would otherwise create an endless loop:

human changes article
→ AI changes article
→ hash changes
→ AI thinks the article changed
→ AI edits again
→ repeat

A pull request changing:

content/posts/zabbix-at-home/index.md
content/posts/mac-mini-runner/index.md

runs the editorial pipeline for those two article directories only.

Article front matter

Useful high-level state can remain visible in YAML front matter:

editorial:
  status: qa-ready
  pipeline_version: 3

  technical:
    status: passed

  fact_check:
    status: passed
    evidence: ".editorial/posts/zabbix-at-home/facts.json"

  style:
    status: passed

  readability:
    status: passed

  final:
    status: approved

Large amounts of AI reasoning should not be added to front matter. Detailed findings and source evidence belong under .editorial/.

Technical fact checking

The Ollama model must not treat its internal knowledge as evidence for technical claims. A fact-checking stage needs controlled, read-only research tools, for example:

  • search_web(query);
  • fetch_url(url);
  • search_official_docs(product, query).

Preferred source order is:

  1. Official product and vendor documentation.
  2. Project repositories and official release information.
  3. Standards, RFC and CVE authorities.
  4. Established technical publications.
  5. General web results.

Claims should be classified as VERIFIED, CONTRADICTED, OUTDATED, UNVERIFIED or NOT_FACTUAL. A failure to find contradictory information is not verification. Supporting URLs and evidence are retained in .editorial/posts/<article>/facts.json.

Internet access for this stage remains read-only. The Ollama agent must not receive arbitrary shell access, AWS credentials, SSH access, curl | bash, or Git push capabilities. The trusted orchestration process validates the result and performs commit and push operations.

Mac mini Ollama runner

The Mac mini acts as an on-demand self-hosted GitHub Actions worker:

GitHub job queued
→ wake Mac mini
→ runner becomes available
→ Ollama editorial pipeline runs
→ editorial commit pushed
→ QA built and deployed
→ Mac becomes idle
→ Mac sleeps

Wired Ethernet, sleep rather than shutdown and Wake-on-LAN are preferred. A smart plug is only a guarded recovery mechanism, not the normal power-control path.

A recovery cycle should require all applicable guards: the Mac has been unreachable for a defined period, SSH is unavailable, the runner is offline, no editorial job is known to be active, and a retry limit has not been exceeded. Only then should power be removed, restored after roughly 20–30 seconds, and macOS restart-after-power-failure behaviour be tested separately.

Separate QA and production permissions

The content deployments use separate AWS identities:

qa.keithmarston.me.uk
→ home-IP allowlist at CloudFront
→ private QA S3 bucket

blog.keithmarston.me.uk
→ public Production CloudFront
→ private Production S3 bucket

The QA role can update only the QA bucket and invalidate the QA distribution. The production role can update only the production bucket and invalidate the production distribution. It is available only to the protected production environment and workflow running from main.

Home-only QA visibility

QA is deliberately not public. A CloudFront Function checks the viewer IP before allowing the request to reach S3. The allowed public IPv4 addresses are managed as OpenTofu input in qa_allowed_ipv4_addresses.

viewer IP is allowlisted?
        │
    yes ┴ no
     │     │
   CONTINUE 403
     │
     ▼
rewrite Hugo pretty URL
     │
     ▼
serve QA from S3 through CloudFront

Disallowed viewers receive 403 Forbidden with a no-store cache-control header. The response is generated at CloudFront, so an unauthorised visitor cannot inspect S3 content. The production hostname is public and is not attached to this restriction.

The initial allowlist contains the home IPv4 address discovered when QA was provisioned. If the home public address changes, the OpenTofu variable is updated and only the QA CloudFront Function is replanned and applied. The QA bucket, certificate, DNS records and distribution remain unchanged.

Implemented GitHub Actions flow

A non-draft pull request opens the review boundary. The QA workflow checks out the exact pull-request head revision, builds it with the QA base URL and deploys it to the QA origin:

PR opened or updated
→ checkout exact PR head SHA
→ hugo --minify with QA base URL
→ verify generated site files
→ assume QA role with GitHub OIDC
→ sync public/ to QA S3 with --delete
→ invalidate QA CloudFront
→ review qa.keithmarston.me.uk from the home network

Further commits to the same pull request run the workflow again. Concurrency is grouped by pull-request number, and an older QA deployment is cancelled when a newer revision supersedes it.

Production has no corresponding pull-request deployment. Its trigger is a push to main, which normally occurs when an approved pull request is merged:

human approval
→ merge to main
→ checkout merged main revision
→ build and validate Hugo
→ assume production OIDC role
→ sync production S3
→ invalidate production CloudFront

A manual production dispatch exists for controlled recovery, but it does not replace review and the merge boundary for normal publication. GitHub OIDC supplies short-lived credentials for both environments; no long-lived AWS access key is stored in the workflows.

OpenTofu owns the infrastructure. GitHub Actions owns Hugo builds, validation and content deployment. OpenTofu should not upload normal generated site content.

The final production trust boundary remains human-controlled: AI may prepare a future QA candidate, but approval and the merge to main explicitly promote it to production.