web/lukegbcom: shore up deployment script a bit

This commit is contained in:
Luke Granger-Brown 2024-11-24 12:55:01 +00:00
parent 6d006b8b8d
commit cf619ce7f6

View file

@ -1,8 +1,12 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -p nodePackages.firebase-tools -p vault -i bash #!nix-shell -p nodePackages.firebase-tools -p vault -i bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DEPOT="$(realpath "${SCRIPT_DIR}/../..")"
vault_path=unix:///run/tokend/sock vault_path=unix:///run/tokend/sock
deploycmd="deploy" deploycmd="deploy"
channelname=""
postdeploy () { postdeploy () {
return return
} }
@ -10,15 +14,29 @@ postdeploy () {
if [[ "$(groups)" =~ (.* |^)"users"($| .*) ]] || ! test -f /etc/NIXOS; then if [[ "$(groups)" =~ (.* |^)"users"($| .*) ]] || ! test -f /etc/NIXOS; then
vault_path=https://vault.int.lukegb.com vault_path=https://vault.int.lukegb.com
channelname="$(id -un)" channelname="$(id -un)"
fi
if [[ $# -gt 0 ]]; then
channelname="$1"
fi
if [[ "$channelname" != "" ]]; then
deploycmd="hosting:channel:deploy $channelname" deploycmd="hosting:channel:deploy $channelname"
postdeploy () { postdeploy () {
firebase hosting:channel:open $channelname --token="$token" firebase hosting:channel:open $channelname --token="$token"
} }
fi fi
cd $(nix-build ../.. -A web.lukegbcom) echo "Building from $DEPOT" >&2
cd $(nix-build "$DEPOT" -A web.lukegbcom)
echo "Using vault at $vault_path to get token" >&2
token="$(vault read --field=token --address="$vault_path" gcp/roleset/lukegbcom-deployer/token)" token="$(vault read --field=token --address="$vault_path" gcp/roleset/lukegbcom-deployer/token)"
if [[ "$channelname" == "" ]]; then
echo "Deploying to prod" >&2
else
echo "Deploying to preview channel '$channelname'" >&2
fi
firebase $deploycmd --token="$token" firebase $deploycmd --token="$token"
# Do it twice because sometimes it doesn't actually do anything the first time # Do it twice because sometimes it doesn't actually do anything the first time
firebase $deploycmd --token="$token" firebase $deploycmd --token="$token"