36 lines
1.4 KiB
Bash
Executable File
36 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Publish the site to one environment: ./deploy.sh dev|prod
|
|
#
|
|
# Uploads the build context with Railway's CLI; Railway builds the Dockerfile
|
|
# (found on its own) and swaps the new deployment in once it is running.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
env=${1:?usage: $0 dev|prod}
|
|
case $env in
|
|
prod) environment=production ;;
|
|
dev) environment=dev ;;
|
|
*) echo "usage: $0 dev|prod" >&2; exit 2 ;;
|
|
esac
|
|
|
|
outputs=$(docker compose run --rm -T terraform -chdir=infra/railway output -json)
|
|
out() { python3 -c 'import json,sys; print(json.load(sys.stdin)[sys.argv[1]]["value"])' "$1" <<<"$outputs"; }
|
|
|
|
project=$(out project_id)
|
|
service=$(out service)
|
|
|
|
# Only what the Dockerfile copies. Uploading the repo would mean either
|
|
# leaving out bible/ (gitignored, and the CLI honors .gitignore) or sending
|
|
# .env and source/ along with it.
|
|
stage=.build
|
|
rm -rf "$stage"
|
|
mkdir "$stage"
|
|
cp -r Dockerfile .dockerignore server.py worker.py assets bible "$stage/"
|
|
|
|
docker compose run --rm -T railway up "$stage" --path-as-root --no-gitignore --ci \
|
|
--project "$project" --environment "$environment" --service "$service" \
|
|
--message "deploy.sh $(git rev-parse --short HEAD)$(git diff --quiet HEAD || echo +dirty)"
|
|
|
|
rm -rf "$stage"
|
|
echo "deployed $env: https://$(python3 -c 'import json,sys; print(json.load(sys.stdin)["domains"]["value"][sys.argv[1]]["domain"])' "$environment" <<<"$outputs")"
|