From a43a682d9b6ce2ec6d78699c2aa7f21d28f3d486 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Mar 2026 17:34:52 +0000 Subject: [PATCH] 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 --- .gitmodules | 4 +++ Dockerfile | 16 ++++++++++++ ghostfolio-agent/.gitkeep | 0 railway.toml | 11 ++++++++- scripts/railway-build.sh | 52 +++++++++++++++++++++++++++++++++++++++ scripts/railway-deploy.sh | 31 +++++++++++++++++++++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 100644 ghostfolio-agent/.gitkeep create mode 100755 scripts/railway-build.sh create mode 100755 scripts/railway-deploy.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..8ddf0c40c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "ghostfolio-agent"] + path = ghostfolio-agent + url = https://github.com/RajatA98/ghostfolio-agent.git + branch = ghostfolio-main diff --git a/Dockerfile b/Dockerfile index e73cd73e6..f3167edfe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,20 @@ COPY ./nx.json nx.json COPY ./replace.build.mjs replace.build.mjs 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 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/* 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 ./scripts/railway-deploy.sh /ghostfolio/ WORKDIR /ghostfolio/apps/api EXPOSE ${PORT:-3333} USER node diff --git a/ghostfolio-agent/.gitkeep b/ghostfolio-agent/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/railway.toml b/railway.toml index c38e6296c..b8cd708d8 100644 --- a/railway.toml +++ b/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] builder = "DOCKERFILE" dockerfilePath = "Dockerfile" diff --git a/scripts/railway-build.sh b/scripts/railway-build.sh new file mode 100755 index 000000000..484526c53 --- /dev/null +++ b/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 ===" diff --git a/scripts/railway-deploy.sh b/scripts/railway-deploy.sh new file mode 100755 index 000000000..ece80d6da --- /dev/null +++ b/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