Publish locally when building on the host itself

This commit is contained in:
Sami Samhuri 2026-06-21 19:26:41 -07:00
parent e35cd5acf7
commit 368c630034
4 changed files with 23 additions and 4 deletions

View file

@ -16,7 +16,13 @@ require "pressa/publish"
require "pressa/git"
DRAFTS_DIR = "public/drafts".freeze
PUBLISH_HOST = "mudge".freeze
# Defaults to the "mudge" tailnet host. Set SAMHURI_PUBLISH_HOST=local (or empty)
# to rsync into the publish dirs directly, e.g. when building on mudge itself.
PUBLISH_HOST =
case (host = ENV.fetch("SAMHURI_PUBLISH_HOST", "mudge"))
when "", "local" then nil
else host.freeze
end
PRODUCTION_PUBLISH_DIR = "/var/www/samhuri.net/public".freeze
BETA_PUBLISH_DIR = "/var/www/beta.samhuri.net/public".freeze
GEMINI_PUBLISH_DIR = "/var/gemini/samhuri.net".freeze

View file

@ -57,7 +57,9 @@ git -c commit.gpgsign=false commit -m "Add link post: $slug" >&2
git push "$REMOTE" "HEAD:$BRANCH" >&2
echo "==> Building and publishing" >&2
bundle exec bake publish >&2
# We're already on the publish host, so rsync into the live dirs locally
# instead of trying to SSH back to ourselves.
SAMHURI_PUBLISH_HOST=local bundle exec bake publish >&2
echo "==> Published $post_path" >&2
# Stdout carries just the path so the caller (Shortcut) can show/use it.

View file

@ -4,12 +4,14 @@ module Pressa
module Publish
module_function
# A nil host publishes locally (no SSH), used when building on the host itself.
def rsync_command(local_paths:, host:, publish_dir:, dry_run:, delete:)
command = ["rsync", "-aKv", "-e", "ssh -4"]
command = ["rsync", "-aKv"]
command.push("-e", "ssh -4") if host
command << "--dry-run" if dry_run
command << "--delete" if delete
command.concat(local_paths)
command << "#{host}:#{publish_dir}"
command << (host ? "#{host}:#{publish_dir}" : publish_dir)
command
end
end

View file

@ -30,6 +30,15 @@ class Pressa::PublishTest < Minitest::Test
refute_includes(command, "--delete")
end
def test_rsync_command_publishes_locally_when_host_is_nil
command = Pressa::Publish.rsync_command(
local_paths: ["www/"], host: nil, publish_dir: "/var/www/samhuri.net/public",
dry_run: false, delete: true
)
assert_equal("/var/www/samhuri.net/public", command.last)
refute_includes(command, "-e")
end
def test_rsync_command_supports_multiple_local_paths
command = Pressa::Publish.rsync_command(
local_paths: ["www/", "extra/"], host: "powder", publish_dir: "/srv/site",