Hosting a Static Site in the Silliest Way Possible (Part 2) (opens in new tab)

geoff.tuxpup.com·11w·Open original (opens in new tab)

Now that I can build my static site and serve it up using Caddy inside a docker container, it’s time to publish it to a server on the internet. If I didn’t want to host other things with it, at this point, I’d just stop and throw it on a static host somewhere, either like github pages, gitlab pages or sourcehut pages. Or a shared hosting space at nearlyfreespeech.net. But I want to publish some larger file downloads also, and those are a poor fit for the software forges. They’d be a fine fit for nearlyfreespeech.net, but I’m under-using my VPS with plenty of space and transfer capacity, and moving the downloads there wouldn’t let me reduce its size or decommission it, so using it is a better option. Here’s how I’m using kamal to do that.

Container Registries

Kamal uses container images to publish web applications. In order to make that work easily, it needs some sort of repository. Dockerhub only lets you have one private repo on their free plan, and the next tier up is $11/mo. Github is more generous with their free tier. Kamal also offers the ability to have a local repo and use an ssh tunnel to your server to publish that. I haven’t tried that, but if I were starting fresh now, that’s how I’d start out. Since I’ve already set up an AWS ECR account, which at last check is costing me less than $0.10/mo, I’m using ECR with Kamal. The excellent SaaS Pegasus documentation for using ECR with Kamal has more details about how to set it up. But with Kamal’s local registry support, that should be optional for deployments now.

Configuring Kamal

If you haven’t installed kamal on your development machine yet, follow the instructions on kamal-deploy.org first. Then run kamal init from the root of your project to generate a skeletal configuration file.

Editing config/deploy.yml

First, name your service and image. e.g.:

service: www-example-dev

image: example/www


Immediately below that, because I’m using ansible as a single source of truth for my VPS configurations, I add a bit of embedded ruby to the configuration file to pull that in:

<%
require 'dotenv/load'
puts "site=#{ENV['SITE_NAME']}"

def get_site_info(site_name = nil)
require 'yaml'
site_name ||= ENV['SITE_NAME']
hosts = YAML.load_file('../5tools_inventories/hosts-web.yml')
hosts['webservers']['vars']['sites'].find { |s| s['name'] == site_name }
end
%>

Loading more...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help