Browse Source

Setup Railway deployment with ghostfolio-agent submodule support

Configure the deployment so Ghostfolio deploys from the main branch and
the ghostfolio-agent submodule uses the ghostfolio-main branch:

- Add .gitmodules defining ghostfolio-agent on ghostfolio-main branch
- Add scripts/railway-build.sh for local/CI builds with submodule init
- Add scripts/railway-deploy.sh as container runtime entry-point
- Update Dockerfile to clone ghostfolio-agent during the build stage
  when the submodule is not pre-initialized in the build context
- Update railway.toml with branch strategy documentation

https://claude.ai/code/session_01Gk8caDep1ufgTpkYgEPnXe
pull/6450/head
Claude 1 month ago
parent
commit
a43a682d9b
Failed to extract signature
  1. 4
      .gitmodules
  2. 16
      Dockerfile
  3. 0
      ghostfolio-agent/.gitkeep
  4. 11
      railway.toml
  5. 52
      scripts/railway-build.sh
  6. 31
      scripts/railway-deploy.sh

4
.gitmodules

@ -0,0 +1,4 @@
[submodule "ghostfolio-agent"]
path = ghostfolio-agent
url = https://github.com/RajatA98/ghostfolio-agent.git
branch = ghostfolio-main

16
Dockerfile

@ -30,6 +30,20 @@ COPY ./nx.json nx.json
COPY ./replace.build.mjs replace.build.mjs COPY ./replace.build.mjs replace.build.mjs
COPY ./tsconfig.base.json tsconfig.base.json COPY ./tsconfig.base.json tsconfig.base.json
# Initialize ghostfolio-agent submodule (ghostfolio-main branch)
COPY ./.gitmodules .gitmodules
COPY ./ghostfolio-agent ghostfolio-agent/
# If the submodule directory is empty (not initialized in build context),
# clone it directly from the repository
RUN if [ ! -f ghostfolio-agent/.git ] && [ ! -d ghostfolio-agent/.git ]; then \
echo "Submodule not initialized in build context, cloning ghostfolio-agent..."; \
rm -rf ghostfolio-agent; \
git clone --branch ghostfolio-main --depth 1 \
https://github.com/RajatA98/ghostfolio-agent.git ghostfolio-agent; \
else \
echo "ghostfolio-agent submodule found in build context"; \
fi
ENV NX_DAEMON=false ENV NX_DAEMON=false
RUN npm run build:production RUN npm run build:production
@ -59,7 +73,9 @@ RUN apt-get update && apt-get install -y --no-install-suggests \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --chown=node:node --from=builder /ghostfolio/dist/apps /ghostfolio/apps/ COPY --chown=node:node --from=builder /ghostfolio/dist/apps /ghostfolio/apps/
COPY --chown=node:node --from=builder /ghostfolio/ghostfolio-agent /ghostfolio/ghostfolio-agent/
COPY --chown=node:node ./docker/entrypoint.sh /ghostfolio/ COPY --chown=node:node ./docker/entrypoint.sh /ghostfolio/
COPY --chown=node:node ./scripts/railway-deploy.sh /ghostfolio/
WORKDIR /ghostfolio/apps/api WORKDIR /ghostfolio/apps/api
EXPOSE ${PORT:-3333} EXPOSE ${PORT:-3333}
USER node USER node

0
ghostfolio-agent/.gitkeep

11
railway.toml

@ -1,4 +1,13 @@
# Railway: deploy from GitHub; add Postgres + Redis in dashboard, then set env vars. # Railway deployment configuration for Ghostfolio
#
# Branch strategy:
# - Ghostfolio (this repo): deploy from "main" branch
# - ghostfolio-agent submodule: uses "ghostfolio-main" branch
#
# Required environment variables (set in Railway dashboard):
# DATABASE_URL, REDIS_HOST, REDIS_PORT, REDIS_PASSWORD,
# JWT_SECRET_KEY, ACCESS_TOKEN_SALT, ROOT_URL
[build] [build]
builder = "DOCKERFILE" builder = "DOCKERFILE"
dockerfilePath = "Dockerfile" dockerfilePath = "Dockerfile"

52
scripts/railway-build.sh

@ -0,0 +1,52 @@
#!/bin/sh
# railway-build.sh
# Railway build script for Ghostfolio
# Ensures the main branch is used for Ghostfolio and the ghostfolio-main
# branch is used for the ghostfolio-agent submodule.
set -e
GHOSTFOLIO_BRANCH="main"
AGENT_SUBMODULE="ghostfolio-agent"
AGENT_BRANCH="ghostfolio-main"
echo "=== Ghostfolio Railway Build ==="
# ---------------------------------------------------------------------------
# 1. Validate / report the current Ghostfolio branch
# ---------------------------------------------------------------------------
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
echo "Ghostfolio branch: $CURRENT_BRANCH (expected: $GHOSTFOLIO_BRANCH)"
if [ "$CURRENT_BRANCH" != "$GHOSTFOLIO_BRANCH" ]; then
echo "WARNING: Current branch is '$CURRENT_BRANCH', expected '$GHOSTFOLIO_BRANCH'."
echo "Railway should be configured to deploy from the '$GHOSTFOLIO_BRANCH' branch."
fi
# ---------------------------------------------------------------------------
# 2. Initialize and update the ghostfolio-agent submodule
# ---------------------------------------------------------------------------
echo "Initializing submodule: $AGENT_SUBMODULE ..."
git submodule init "$AGENT_SUBMODULE"
git submodule update --remote --checkout "$AGENT_SUBMODULE"
# Ensure the submodule is on the correct branch
cd "$AGENT_SUBMODULE"
echo "Checking out $AGENT_BRANCH for $AGENT_SUBMODULE ..."
git fetch origin "$AGENT_BRANCH"
git checkout "$AGENT_BRANCH"
git pull origin "$AGENT_BRANCH"
cd ..
echo "$AGENT_SUBMODULE is on branch: $(cd "$AGENT_SUBMODULE" && git rev-parse --abbrev-ref HEAD)"
# ---------------------------------------------------------------------------
# 3. Install dependencies and build
# ---------------------------------------------------------------------------
echo "Installing dependencies ..."
npm ci
echo "Building Ghostfolio for production ..."
npm run build:production
echo "=== Build complete ==="

31
scripts/railway-deploy.sh

@ -0,0 +1,31 @@
#!/bin/sh
# railway-deploy.sh
# Railway deployment entry-point for Ghostfolio.
# This script is executed inside the running container. It runs database
# migrations, seeds the database, and starts the application server.
#
# Branch configuration (build-time):
# - Ghostfolio: main
# - ghostfolio-agent: ghostfolio-main
set -e
echo "=== Ghostfolio Railway Deployment ==="
# ---------------------------------------------------------------------------
# 1. Database migrations
# ---------------------------------------------------------------------------
echo "Running database migrations ..."
npx prisma migrate deploy
# ---------------------------------------------------------------------------
# 2. Seed the database
# ---------------------------------------------------------------------------
echo "Seeding the database ..."
npx prisma db seed
# ---------------------------------------------------------------------------
# 3. Start the server
# ---------------------------------------------------------------------------
echo "Starting the Ghostfolio server ..."
exec node main
Loading…
Cancel
Save