- Go 60.9%
- templ 16.6%
- CSS 12%
- JavaScript 10.1%
- Makefile 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| cmd/portfolio | ||
| deploy | ||
| internal | ||
| web | ||
| .gitignore | ||
| CLAUDE.md | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
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.
- Build and copy:
make build scp bin/portfolio deploy/portfolio.service deploy/portfolio.env.example deploy/Caddyfile you@server: - 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 - Settings:
sudo install -m 600 portfolio.env.example /etc/portfolio.env, then edit it to set your domain and, optionally, email. - 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 - HTTPS with Caddy:
Put your domain insudo dnf install 'dnf-command(copr)' && sudo dnf copr enable @caddy/caddy && sudo dnf install caddyCaddyfile, thensudo cp Caddyfile /etc/caddy/Caddyfile && sudo systemctl enable --now caddy. - 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 - 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.dbholds text, order and settings. Copy it safely while the site runs withsqlite3 /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 reprocessrebuilds it from the originals.