From 368c6300347ab5dce4bc1a1ac68c1643aaaa1a70 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 21 Jun 2026 19:26:41 -0700 Subject: [PATCH] Publish locally when building on the host itself --- bake.rb | 8 +++++++- bin/post-link | 4 +++- lib/pressa/publish.rb | 6 ++++-- test/publish_test.rb | 9 +++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bake.rb b/bake.rb index 2ef4e76..82a8bbf 100644 --- a/bake.rb +++ b/bake.rb @@ -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 diff --git a/bin/post-link b/bin/post-link index bcf1557..dccd465 100755 --- a/bin/post-link +++ b/bin/post-link @@ -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. diff --git a/lib/pressa/publish.rb b/lib/pressa/publish.rb index 7d1e712..bbf6522 100644 --- a/lib/pressa/publish.rb +++ b/lib/pressa/publish.rb @@ -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 diff --git a/test/publish_test.rb b/test/publish_test.rb index ff00118..120d197 100644 --- a/test/publish_test.rb +++ b/test/publish_test.rb @@ -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",