Deploying to Source Hut

I had to figure some thigns out while trying to get my particular setup of Hugo deployed to SourceHut, because I made some interesting choices:

  • the source repo is private
  • using a custom domain (this one)
  • using a theme as a git submodule

If those very specific constraints apply to you too, use the following tweaks to the Quick Start Guide:

  1. Set up the domain CNAME to point to pages.st.ht.; in my case this was a CNAME for www. This was needed for the deploy to complete successfully.
    www IN CNAME pages.sr.ht.
  2. The Build manifest reference got me to the page that describes setting up a private key.
  3. If you have already added a key to your profile, you should use ssh-keygen -C <new-key-name> along with any other options. new-key-name is what the key will get named in the secrets management page. This private key is necessary to access your repo from the build instances. The summary of that is adding the following two top-level keys to .build.yml:
    secrets:
    - <ssh key secret uuid from secrets dashboard>
    sources:
    - git@git.sr.ht:~yourname/your-private-repo
  4. Add hugo to the value part of the packages key in .build.yml
    packages:
    - hut
    - hugo
  5. Update the package key to have this as the value (note that -b passed to hugo changes the URLs to be relative to your domain and -C public to tar only compresses files in that folder):
    package: |
      cd $site
      git submodule update
      hugo -b https://$site
      tar -C public -cvz . > ../site.tar.gz  
  6. If you’ve done all that, your .build.yaml should be looking something like:
    image: alpine/edge
    oauth: pages.sr.ht/PAGES:RW
    packages:
    - hut
    - hugo
    environment:
      site: <your-website-url>
      repo: <your-website-repo>
    secrets:
    - <uuid-of-your-sh-key-from-step-3>
    sources:
    - git@git.sr.ht:~<username>/$repo
    tasks:
    - package: |
        cd $repo
        git submodule update
        hugo -b https://$site
        tar -C public -cvz . > ../site.tar.gz    
    - upload: |
      hut pages publish -d $site site.tar.gz  

I figured this out mostly in a couple of hours, after not having spent any time doing ops-y stuff for ages, so yay!