Skip to content

Commit 7e532bc

Browse files
fix: Railway deployment build error - remove node_modules cache
- Add nixpacks.toml cache fix for EBUSY error - Create railway.toml with proper build commands - Add .npmrc to prevent cache issues - Use minimal server for Railway deployment
1 parent 6392277 commit 7e532bc

11 files changed

Lines changed: 2551 additions & 1 deletion

File tree

.npmrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Prevent cache issues in Railway deployment
2+
cache=/tmp/.npm
3+
prefer-offline=false
4+
audit=false
5+
fund=false

docs/STORAGE_SETUP.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Storage Tier Configuration Guide
2+
3+
## Overview
4+
StackMemory uses a 3-tier storage system for optimal performance and cost:
5+
- **Hot Tier (Redis)**: Last 24 hours - Already configured ✅
6+
- **Warm Tier (Railway Buckets)**: 1-30 days - Setup required
7+
- **Cold Tier (GCS)**: 30+ days - Setup required
8+
9+
## 1. Railway Buckets Setup (Warm Tier)
10+
11+
### Option A: Using Railway CLI
12+
13+
```bash
14+
# Install Railway CLI if not already installed
15+
brew install railway
16+
17+
# Login to Railway
18+
railway login
19+
20+
# Create a new bucket
21+
railway storage create stackmemory-warm
22+
23+
# Get bucket credentials
24+
railway storage credentials stackmemory-warm
25+
```
26+
27+
### Option B: Using Railway Dashboard
28+
29+
1. Go to [Railway Dashboard](https://railway.app)
30+
2. Navigate to your project
31+
3. Click "New" → "Bucket"
32+
4. Name it `stackmemory-warm`
33+
5. Copy the credentials:
34+
- Endpoint URL
35+
- Access Key ID
36+
- Secret Access Key
37+
38+
### Add to .env file:
39+
40+
```bash
41+
# Railway Bucket Configuration
42+
RAILWAY_BUCKET_ENDPOINT=https://buckets.railway.app
43+
RAILWAY_BUCKET_NAME=stackmemory-warm
44+
RAILWAY_BUCKET_ACCESS_KEY=your_access_key_here
45+
RAILWAY_BUCKET_SECRET_KEY=your_secret_key_here
46+
```
47+
48+
## 2. Google Cloud Storage Setup (Cold Tier)
49+
50+
### Step 1: Create GCS Bucket
51+
52+
```bash
53+
# Install gcloud CLI if not already installed
54+
brew install google-cloud-sdk
55+
56+
# Authenticate
57+
gcloud auth login
58+
59+
# Set your project
60+
gcloud config set project YOUR_PROJECT_ID
61+
62+
# Create a Coldline bucket for cost optimization
63+
gsutil mb -c coldline -l us-central1 gs://stackmemory-cold
64+
65+
# Verify bucket creation
66+
gsutil ls
67+
```
68+
69+
### Step 2: Create Service Account
70+
71+
```bash
72+
# Create service account
73+
gcloud iam service-accounts create stackmemory-storage \
74+
--display-name="StackMemory Storage Service"
75+
76+
# Get service account email
77+
SERVICE_ACCOUNT=stackmemory-storage@YOUR_PROJECT_ID.iam.gserviceaccount.com
78+
79+
# Grant bucket permissions
80+
gsutil iam ch serviceAccount:$SERVICE_ACCOUNT:objectAdmin gs://stackmemory-cold
81+
82+
# Create and download key file
83+
gcloud iam service-accounts keys create \
84+
~/.stackmemory/gcs-key.json \
85+
--iam-account=$SERVICE_ACCOUNT
86+
87+
echo "Key saved to ~/.stackmemory/gcs-key.json"
88+
```
89+
90+
### Step 3: Add to .env file:
91+
92+
```bash
93+
# GCS Configuration
94+
GCS_BUCKET=stackmemory-cold
95+
GCP_PROJECT_ID=your-project-id
96+
GCP_KEY_FILE=/Users/jwu/.stackmemory/gcs-key.json
97+
```
98+
99+
## 3. Alternative: Use AWS S3 Instead
100+
101+
If you prefer AWS S3 over Railway Buckets:
102+
103+
```bash
104+
# Create S3 bucket with lifecycle rules
105+
aws s3 mb s3://stackmemory-storage --region us-east-1
106+
107+
# Create lifecycle policy for automatic archival
108+
cat > lifecycle.json << 'EOF'
109+
{
110+
"Rules": [
111+
{
112+
"Id": "ArchiveOldTraces",
113+
"Status": "Enabled",
114+
"Transitions": [
115+
{
116+
"Days": 30,
117+
"StorageClass": "GLACIER_IR"
118+
},
119+
{
120+
"Days": 90,
121+
"StorageClass": "DEEP_ARCHIVE"
122+
}
123+
]
124+
}
125+
]
126+
}
127+
EOF
128+
129+
aws s3api put-bucket-lifecycle-configuration \
130+
--bucket stackmemory-storage \
131+
--lifecycle-configuration file://lifecycle.json
132+
```
133+
134+
Add to .env:
135+
```bash
136+
# S3 Configuration (alternative to Railway)
137+
S3_BUCKET=stackmemory-storage
138+
AWS_REGION=us-east-1
139+
AWS_ACCESS_KEY_ID=your_access_key
140+
AWS_SECRET_ACCESS_KEY=your_secret_key
141+
```
142+
143+
## 4. Testing Your Configuration
144+
145+
After setting up, test with:
146+
147+
```bash
148+
# Test storage status
149+
stackmemory storage status
150+
151+
# Test migration (dry run first)
152+
stackmemory storage migrate --dry-run
153+
154+
# Perform actual migration
155+
stackmemory storage migrate
156+
157+
# Verify trace retrieval
158+
stackmemory storage retrieve <trace-id>
159+
```
160+
161+
## 5. Cost Estimates
162+
163+
| Tier | Storage Type | Cost/GB/Month | Access Cost |
164+
|------|-------------|---------------|-------------|
165+
| Hot | Redis (Railway) | $0.00 (included) | Free |
166+
| Warm | Railway Buckets | ~$0.023 | $0.01/1000 requests |
167+
| Warm | AWS S3 Standard | $0.023 | $0.0004/1000 requests |
168+
| Cold | GCS Coldline | $0.004 | $0.01/GB retrieval |
169+
| Cold | AWS Glacier IR | $0.004 | $0.03/GB retrieval |
170+
171+
## 6. Troubleshooting
172+
173+
### Railway Buckets Connection Issues
174+
```bash
175+
# Test connection
176+
curl -I https://buckets.railway.app
177+
178+
# Verify credentials
179+
railway whoami
180+
railway project
181+
```
182+
183+
### GCS Permission Issues
184+
```bash
185+
# Check service account permissions
186+
gcloud projects get-iam-policy YOUR_PROJECT_ID \
187+
--flatten="bindings[].members" \
188+
--filter="bindings.members:stackmemory-storage"
189+
190+
# Test bucket access
191+
gsutil ls gs://stackmemory-cold
192+
```
193+
194+
### Redis Connection Issues
195+
```bash
196+
# Test Redis connection
197+
redis-cli -u $REDIS_URL ping
198+
```
199+
200+
## Next Steps
201+
202+
1. Choose your preferred warm tier (Railway Buckets or AWS S3)
203+
2. Set up GCS for cold storage
204+
3. Add credentials to .env file
205+
4. Test with `stackmemory storage status`
206+
5. Monitor costs with `stackmemory storage stats`

nixpacks.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
nixPkgs = ["nodejs_20", "npm-10_x"]
66

77
[phases.install]
8-
cmds = ["npm ci --omit=dev --ignore-scripts"]
8+
cmds = [
9+
"rm -rf node_modules/.cache",
10+
"npm ci --omit=dev --ignore-scripts"
11+
]
12+
cacheDirectories = ["/root/.npm"]
913

1014
[phases.build]
15+
dependsOn = ["install"]
1116
cmds = ["npm run build"]
1217

1318
[start]

railway.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[build]
2+
builder = "nixpacks"
3+
buildCommand = "rm -rf node_modules/.cache && npm ci --omit=dev --ignore-scripts && npm run build"
4+
5+
[deploy]
6+
startCommand = "node dist/servers/railway/minimal.js"
7+
healthcheckPath = "/api/health"
8+
restartPolicyType = "on-failure"
9+
restartPolicyMaxRetries = 3

0 commit comments

Comments
 (0)