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