flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/scripts/deploy.sh

61 lines1,648 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Deploy scripts live in the repository1#!/usr/bin/env bash
2# Deploys g1t: every part, or the ones named, in the order they depend on
3# each other. Each part's D1 migrations are applied before its code goes
4# out, so new code never meets an old database.
5#
6# scripts/deploy.sh # everything
7# scripts/deploy.sh billing web # just these, still in order
8#
9# Uses your `wrangler login`. The repository's .env may hold a token for
10# other tools; it is ignored here unless you set CLOUDFLARE_DEPLOY_TOKEN.
11set -euo pipefail
12
13ROOT="$(cd "$(dirname "$0")/.." && pwd)"
14export CLOUDFLARE_API_TOKEN="${CLOUDFLARE_DEPLOY_TOKEN:-}"
15
16# Dependency order: what others bind to goes first.
17ORDER=(
18 services/events
19 services/identity
20 services/repos
21 services/work
Projects: what a workspace builds and runs, first on every page22 services/projects
Deploy scripts live in the repository23 services/billing
24 services/integrations
25 services/webhooks
26 services/actions
27 services/models
28 services/deployments
29 services/runner
30 apps/api
31 services/pages
32 apps/web
Billing accounts, terms and enterprises; g1t is no longer free33 apps/sudo
Deploy scripts live in the repository34 apps/docs
35)
36
37wanted() {
38 [ $# -eq 0 ] && return 0
39 local dir="$1"; shift
40 for name in "${PICK[@]}"; do
41 [ "$dir" = "$name" ] || [ "$(basename "$dir")" = "$name" ] && return 0
42 done
43 return 1
44}
45
46PICK=("$@")
47for dir in "${ORDER[@]}"; do
48 [ ${#PICK[@]} -eq 0 ] || wanted "$dir" || continue
49 echo "== $dir"
50 cd "$ROOT/$dir"
51 db=$(grep -o '"database_name": *"[^"]*"' wrangler.jsonc 2>/dev/null | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true)
52 if [ -n "$db" ] && [ -d migrations ]; then
53 npx wrangler d1 migrations apply "$db" --remote
54 fi
55 if grep -q '"deploy": "[^"]*build' package.json 2>/dev/null; then
56 npm run deploy
57 else
58 npx wrangler deploy
59 fi
60done
61echo "== Deployed."