diff --git a/.github/workflows/deploy-lit-payments.yml b/.github/workflows/deploy-lit-payments.yml new file mode 100644 index 00000000..6ba8880a --- /dev/null +++ b/.github/workflows/deploy-lit-payments.yml @@ -0,0 +1,98 @@ +# Deploy lit-payments to Railway +# +# Mirrors the lit-static release flow (see deploy-static.yml / +# deploy-prod-3-static.yml), but the deploy target is Railway instead of +# Cloudflare Pages: +# +# * push to `main` -> Railway "staging" environment +# * push of a `v*` tag -> Railway "production" environment +# +# Deployment uses the Railway CLI (`railway up`) authenticated with an +# environment-scoped Railway *project token* passed as RAILWAY_TOKEN. A project +# token encodes both the Railway project and its environment, so there is no +# `railway link` step — we only pass the service name. +# +# lit-payments needs the repo ROOT as its build context: its Dockerfile COPYs +# the sibling `lit-billing-core` crate. So `railway up` runs from the repo root, +# and the Railway service must be pre-configured (in the Railway dashboard) with: +# * Root directory / build context: repo root (/) +# * Config file path: lit-payments/railway.json +# (See lit-payments/README.md → "Deploy to Railway".) +# +# Required repository secrets: +# RAILWAY_TOKEN_PAYMENTS_STAGING Railway project token — lit-payments +# project, "staging" environment. +# RAILWAY_TOKEN_PAYMENTS_PRODUCTION Railway project token — lit-payments +# project, "production" environment. +# +# Optional repository variables (defaults shown): +# RAILWAY_PAYMENTS_SERVICE Railway service name (default: lit-payments) + +name: Deploy lit-payments (Railway) + +on: + push: + branches: [main] + tags: ['v*'] + workflow_dispatch: + inputs: + environment: + description: 'Railway environment to deploy' + required: true + default: staging + type: choice + options: + - staging + - production + +concurrency: + group: deploy-lit-payments-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +jobs: + deploy-staging: + if: > + (github.event_name == 'push' && github.ref == 'refs/heads/main') || + (github.event_name == 'workflow_dispatch' && inputs.environment == 'staging') + runs-on: self-hosted + environment: staging + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Railway CLI + run: npm install -g @railway/cli@5.57.2 + + - name: Deploy to Railway (staging) + # Build context = repo root so the Dockerfile can reach lit-billing-core. + env: + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN_PAYMENTS_STAGING }} + run: railway up --ci --service "${{ vars.RAILWAY_PAYMENTS_SERVICE || 'lit-payments' }}" + + deploy-production: + if: > + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || + (github.event_name == 'workflow_dispatch' && inputs.environment == 'production') + runs-on: self-hosted + environment: production + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Railway CLI + run: npm install -g @railway/cli@5.57.2 + + - name: Deploy to Railway (production) + # Build context = repo root so the Dockerfile can reach lit-billing-core. + env: + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN_PAYMENTS_PRODUCTION }} + run: railway up --ci --service "${{ vars.RAILWAY_PAYMENTS_SERVICE || 'lit-payments' }}" diff --git a/.github/workflows/deploy-lit-triggers.yml b/.github/workflows/deploy-lit-triggers.yml new file mode 100644 index 00000000..5dc9cd90 --- /dev/null +++ b/.github/workflows/deploy-lit-triggers.yml @@ -0,0 +1,102 @@ +# Deploy lit-triggers to Railway +# +# Mirrors the lit-static release flow (see deploy-static.yml / +# deploy-prod-3-static.yml), but the deploy target is Railway instead of +# Cloudflare Pages: +# +# * push to `main` -> Railway "staging" environment +# * push of a `v*` tag -> Railway "production" environment +# +# Deployment uses the Railway CLI (`railway up`) authenticated with an +# environment-scoped Railway *project token* passed as RAILWAY_TOKEN. A project +# token encodes both the Railway project and its environment, so there is no +# `railway link` step — we only pass the service name. +# +# lit-triggers is self-contained: its Dockerfile `COPY . .`s from the +# `lit-triggers/` directory, so `railway up` runs from that directory (Railway +# service root = lit-triggers, config = lit-triggers/railway.json). +# (See lit-triggers/README.md → "Railway deployment".) +# +# Required repository secrets: +# RAILWAY_TOKEN_TRIGGERS_STAGING Railway project token — lit-triggers +# project, "staging" environment. +# RAILWAY_TOKEN_TRIGGERS_PRODUCTION Railway project token — lit-triggers +# project, "production" environment. +# +# Optional repository variables (defaults shown): +# RAILWAY_TRIGGERS_SERVICE Railway service name (default: lit-triggers) + +name: Deploy lit-triggers (Railway) + +on: + push: + branches: [main] + tags: ['v*'] + workflow_dispatch: + inputs: + environment: + description: 'Railway environment to deploy' + required: true + default: staging + type: choice + options: + - staging + - production + +concurrency: + group: deploy-lit-triggers-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +jobs: + deploy-staging: + if: > + (github.event_name == 'push' && github.ref == 'refs/heads/main') || + (github.event_name == 'workflow_dispatch' && inputs.environment == 'staging') + runs-on: self-hosted + environment: staging + defaults: + run: + working-directory: lit-triggers + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Railway CLI + run: npm install -g @railway/cli@5.57.2 + + - name: Deploy to Railway (staging) + # Build context = lit-triggers/ to match the Dockerfile's `COPY . .`. + env: + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN_TRIGGERS_STAGING }} + run: railway up --ci --service "${{ vars.RAILWAY_TRIGGERS_SERVICE || 'lit-triggers' }}" + + deploy-production: + if: > + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || + (github.event_name == 'workflow_dispatch' && inputs.environment == 'production') + runs-on: self-hosted + environment: production + defaults: + run: + working-directory: lit-triggers + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Railway CLI + run: npm install -g @railway/cli@5.57.2 + + - name: Deploy to Railway (production) + # Build context = lit-triggers/ to match the Dockerfile's `COPY . .`. + env: + RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN_TRIGGERS_PRODUCTION }} + run: railway up --ci --service "${{ vars.RAILWAY_TRIGGERS_SERVICE || 'lit-triggers' }}" diff --git a/lit-payments/README.md b/lit-payments/README.md index 61599c5e..e1ba2cd5 100644 --- a/lit-payments/README.md +++ b/lit-payments/README.md @@ -347,6 +347,25 @@ railway link # choose or create the lit-payments project railway up # from repo root; service config path should be lit-payments/railway.json ``` +### CI/CD (GitHub Actions) + +`.github/workflows/deploy-lit-payments.yml` deploys automatically via the +Railway CLI, mirroring the `lit-static` release flow: + +- push to `main` → Railway **staging** environment +- push of a `v*` tag → Railway **production** environment + +It runs `railway up` from the repo root (so the Dockerfile can reach +`lit-billing-core`) and selects the service with `--service`. Auth uses +environment-scoped Railway **project tokens**, so no `railway link` is needed. + +Required repo secrets: + +- `RAILWAY_TOKEN_PAYMENTS_STAGING` — project token, `staging` environment +- `RAILWAY_TOKEN_PAYMENTS_PRODUCTION` — project token, `production` environment + +Optional repo variable: `RAILWAY_PAYMENTS_SERVICE` (defaults to `lit-payments`). + ### 2. Add Postgres Use Railway's Postgres plugin for the cheapest/simple path: diff --git a/lit-triggers/README.md b/lit-triggers/README.md index a0ca67fd..13c0522c 100644 --- a/lit-triggers/README.md +++ b/lit-triggers/README.md @@ -65,6 +65,22 @@ Create a Railway project with: 3. The web service root directory set to `lit-triggers`. 4. App sleeping disabled. `lit-triggers/railway.json` sets `sleepApplication: false`; keep it disabled in the Railway UI too because scheduled and chain-event triggers rely on a continuously running worker. +### CI/CD (GitHub Actions) + +`.github/workflows/deploy-lit-triggers.yml` deploys automatically via the Railway CLI, mirroring the `lit-static` release flow: + +- push to `main` → Railway **staging** environment +- push of a `v*` tag → Railway **production** environment + +It runs `railway up` from the `lit-triggers/` directory (matching the service root) and selects the service with `--service`. Auth uses environment-scoped Railway **project tokens**, so no `railway link` is needed. + +Required repo secrets: + +- `RAILWAY_TOKEN_TRIGGERS_STAGING` — project token, `staging` environment +- `RAILWAY_TOKEN_TRIGGERS_PRODUCTION` — project token, `production` environment + +Optional repo variable: `RAILWAY_TRIGGERS_SERVICE` (defaults to `lit-triggers`). + Set the web service variables before deploying: ```bash