Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#!/usr/bin/env bashset -euo pipefail
if [[ "${1:-}" == "--help" ]]; then printf 'Usage: reams-publish-image FLY_APP [web|auth|happyview]\nBuild a Nix image and publish it to registry.fly.io.\nWeb needs the four public build variables; HappyView needs HAPPYVIEW_SOURCE.\n' exit 0fiif [[ $# -lt 1 || $# -gt 2 || ! "$1" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then printf 'Usage: reams-publish-image FLY_APP [web|auth|happyview]\n' >&2 exit 2fiprofile=${2:-web}case "$profile" in web) attribute=container; image_name=reams-atmosphere : "${REAMS_PUBLIC_ORIGIN:?Set the public app HTTPS origin}" : "${VITE_HAPPYVIEW_URL:?Set the public provider HTTPS endpoint}" : "${VITE_HAPPYVIEW_CLIENT_KEY:?Set the public provider client key}" : "${VITE_ATPROTO_OAUTH_SCOPE:?Set the base OAuth scope}" ;; auth) attribute=auth-container; image_name=reams-auth ;; happyview) attribute=happyview-container; image_name=reams-happyview; : "${HAPPYVIEW_SOURCE:?Set the tested provider source path}" ;; *) printf 'Unknown image profile: %s\n' "$profile" >&2; exit 2 ;;esac
app=$1root=$(git rev-parse --show-toplevel)if [[ ! -f "$root/nix/container.nix" || ! -f "$root/scripts/container-build.mjs" ]]; then printf 'Run this command from the Reams repository.\n' >&2 exit 2fi# Fail before building when local Docker or Fly credentials are unavailable.docker info >/dev/nullflyctl auth whoami >/dev/nullflyctl auth docker
archive=$(nix --extra-experimental-features 'nix-command flakes' build --impure "$root#$attribute" --no-link --print-out-paths)local_image=$(tar --extract --to-stdout --file "$archive" manifest.json | jq -er ' if length == 1 and (.[0].RepoTags | length) == 1 then .[0].RepoTags[0] else error("Expected one tagged Nix image") end')if [[ "$local_image" != "$image_name:"* || ! "${local_image#*:}" =~ ^[a-z0-9]{32}$ ]]; then printf 'Unexpected Nix image identity: %s\n' "$local_image" >&2 exit 1firepository="registry.fly.io/$app"remote_image="$repository:${local_image#*:}"docker load --input "$archive"docker tag "$local_image" "$remote_image"docker push "$remote_image"digest=$(docker image inspect --format '{{json .RepoDigests}}' "$remote_image" | jq -er --arg prefix "$repository@" ' [.[] | select(startswith($prefix))] | if length == 1 then .[0] else error("Registry digest missing after push") end')printf '\nPublished %s\n' "$digest"printf 'Deploy using this exact digest and your app configuration:\n'printf 'flyctl deploy --app %s --config deploy/fly-%s.toml --image %s --ha=false --strategy rolling\n' "$app" "$profile" "$digest"