| 1 | import { |
| 2 | defineRailway, |
| 3 | github, |
| 4 | postgres, |
| 5 | preserve, |
| 6 | project, |
| 7 | service, |
| 8 | bucket, |
| 9 | } from "railway/iac"; |
| 10 | |
| 11 | const REPO = " |
| 12 | |
| 13 | // Custom domains: `*.up.railway.app` is a public suffix, so it cannot hold the session cookie both services share. Edit them to yours. |
| 14 | // |
| 15 | // Railway does not register custom domains from configuration: add both in the dashboard, then `railway config pull`. These constants only build the URLs the two services need to know about each other. |
| 16 | const ROOT_DOMAIN = " |
| 17 | const WEB_DOMAIN = ` |
| 18 | const API_DOMAIN = ` |
| 19 | |
| 20 | const API_URL = ` |
| 21 | const WEB_URL = ` |
| 22 | |
| 23 | export default defineRailway(() |
| 24 | const db = |
| 25 | const storage = |
| 26 | const api = |
| 27 | source: github(REPO |
| 28 | build: { |
| 29 | builder: "DOCKERFILE", |
| 30 | dockerfilePath: "apps/api/Dockerfile", |
| 31 | }, |
| 32 | // Applies packages/db/drizzle/*.sql; a failure keeps the old version up. |
| 33 | preDeploy: "node packages/db/dist/migrate.js", |
| 34 | healthcheck: "/api", |
| 35 | healthcheckTimeout: 60, |
| 36 | deploy: { |
| 37 | restartPolicyType: "ON_FAILURE", |
| 38 | restartPolicyMaxRetries: 5, |
| 39 | }, |
| 40 | env: { |
| 41 | DATABASE_URL: db.env |
| 42 | BETTER_AUTH_URL: API_URL, |
| 43 | AUTH_TRUSTED_ORIGINS: WEB_URL, |
| 44 | AUTH_COOKIE_DOMAIN: `.${ROOT_DOMAIN |
| 45 | BETTER_AUTH_SECRET: preserve(), |
| 46 | // we set `preserve` here cus storage.env does not exist. We need to set it manually on dashboard |
| 47 | S3_BUCKET: preserve(), |
| 48 | S3_ENDPOINT: preserve(), |
| 49 | S3_ACCESS_KEY_ID: preserve(), |
| 50 | S3_SECRET_ACCESS_KEY: preserve(), |
| 51 | }, |
| 52 | }); |
| 53 | |
| 54 | const web = |
| 55 | source: github(REPO |
| 56 | build: { |
| 57 | builder: "DOCKERFILE", |
| 58 | dockerfilePath: "apps/web/Dockerfile", |
| 59 | }, |
| 60 | deploy: { |
| 61 | restartPolicyType: "ON_FAILURE", |
| 62 | restartPolicyMaxRetries: 5, |
| 63 | }, |
| 64 | env: { |
| 65 | // Inlined into the browser bundle at build time: the Dockerfile picks it up through `ARG NEXT_PUBLIC_API_URL`, so a change needs a rebuild. |
| 66 | NEXT_PUBLIC_API_URL: API_URL, |
| 67 | }, |
| 68 | }); |
| 69 | |
| 70 | return project("ghost |
| 71 | }); |