My photography portfolio
  • Go 60.9%
  • templ 16.6%
  • CSS 12%
  • JavaScript 10.1%
  • Makefile 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-05 21:03:37 +13:00
cmd/portfolio Pure-Go image pipeline, mobile layout fixes, image protection 2026-10-28 07:45:13 +13:00
deploy Build portfolio site: Go server, admin, image pipeline 2026-10-27 22:20:21 +13:00
internal Favicon, social links, search data, enquiry place field 2026-11-05 21:00:24 +13:00
web Favicon, social links, search data, enquiry place field 2026-11-05 21:00:24 +13:00
.gitignore Build portfolio site: Go server, admin, image pipeline 2026-10-27 22:20:21 +13:00
CLAUDE.md Pure-Go image pipeline, mobile layout fixes, image protection 2026-10-28 07:45:13 +13:00
go.mod Pure-Go image pipeline, mobile layout fixes, image protection 2026-10-28 07:45:13 +13:00
go.sum Pure-Go image pipeline, mobile layout fixes, image protection 2026-10-28 07:45:13 +13:00
LICENSE Initial commit 2026-10-27 19:43:21 +13:00
Makefile Pure-Go image pipeline, mobile layout fixes, image protection 2026-10-28 07:45:13 +13:00
README.md Favicon, social links, search data, enquiry place field 2026-11-05 21:00:24 +13:00

portfolio

My photography portfolio: wildlife, events and sport. A Go server renders the pages, htmx handles page changes and the photo viewer, and uploaded JPEGs are turned into fast AVIF, WebP and JPEG web sizes. It's all pure Go, so the server is a single file with no other software to install.

Run it locally

You need Go 1.26 or newer. Nothing else: the image encoders are built in.

go run ./cmd/portfolio set-password   # once; data goes in ./data
make dev                              # http://127.0.0.1:8080, admin at /admin

make dev rebuilds and restarts on every change to Go, templ, CSS or JS files.

Command What it does
make build Builds bin/portfolio, a single static file that runs on any x86-64 Linux
make build GOARCH=arm64 The same, for an ARM machine such as a Raspberry Pi
make test Runs all tests
go test -tags nodynamic ./internal/store -run TestLeadAndOrder -v Runs one test
make generate Regenerates Go code from the .templ templates
portfolio reprocess [id…] Makes new web sizes for every photo, or just the given ones

Host it from home (Rocky Linux)

Build on your laptop, then copy one file to the server. The server doesn't need Go.

  1. Build and copy:
    make build
    scp bin/portfolio deploy/portfolio.service deploy/portfolio.env.example deploy/Caddyfile you@server:
    
  2. On the server, install the binary and create its user:
    sudo install -m 755 portfolio /usr/local/bin/portfolio
    sudo useradd --system --home /var/lib/portfolio --shell /usr/sbin/nologin portfolio
    
  3. Settings: sudo install -m 600 portfolio.env.example /etc/portfolio.env, then edit it to set your domain and, optionally, email.
  4. Start the service:
    sudo cp portfolio.service /etc/systemd/system/
    sudo systemctl daemon-reload && sudo systemctl enable --now portfolio
    sudo -u portfolio PORTFOLIO_DATA=/var/lib/portfolio portfolio set-password
    
  5. HTTPS with Caddy:
    sudo dnf install 'dnf-command(copr)' && sudo dnf copr enable @caddy/caddy && sudo dnf install caddy
    
    Put your domain in Caddyfile, then sudo cp Caddyfile /etc/caddy/Caddyfile && sudo systemctl enable --now caddy.
  6. Open the firewall:
    sudo firewall-cmd --permanent --add-service=http --add-service=https
    sudo firewall-cmd --permanent --add-port=443/udp
    sudo firewall-cmd --reload
    
  7. Router: forward TCP 80 and 443, and UDP 443, to the server, and point your domain at your home address. If the address changes, use a dynamic DNS service. This only works if your ISP gives you your own public address (no CGNAT).

Then log in at https://yourdomain/admin.

Updating: run make build, copy the new bin/portfolio over, then sudo install -m 755 portfolio /usr/local/bin/portfolio && sudo systemctl restart portfolio.

If the service won't start, check journalctl -u portfolio -e. SELinux is on by default on Rocky; sudo ausearch -m avc -ts recent shows whether it blocked something.

Resources: each photo uses about 1 GB of memory while it's being processed (2 at a time by default; change with PORTFOLIO_WORKERS). A 20-megapixel photo takes about 7 seconds on a 12-core machine. Visitors aren't affected by either.

Backups

Everything lives in /var/lib/portfolio:

  • portfolio.db holds text, order and settings. Copy it safely while the site runs with sqlite3 /var/lib/portfolio/portfolio.db ".backup '/backups/portfolio.db'".
  • originals/ holds your uploaded JPEGs. Back this folder up.
  • derived/ holds the web sizes. It doesn't need a backup: portfolio reprocess rebuilds it from the originals.