Skip to content

Commit d44b6be

Browse files
alanopsclaude
andcommitted
Prepare backend for Railway deployment
- Create separate backend directory with all necessary files - Add Railway-specific Dockerfile with Docker CLI support - Configure railway.json for deployment settings - Add comprehensive deployment documentation - Update package.json with Railway build commands - Frontend already configured to use NEXT_PUBLIC_WS_URL Ready for Railway deployment - just need to: 1. Create Railway project from backend/ directory 2. Set FRONTEND_URL environment variable 3. Deploy frontend to Netlify with NEXT_PUBLIC_WS_URL 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 05d8f99 commit d44b6be

23 files changed

Lines changed: 1362 additions & 0 deletions

DEPLOY-RAILWAY.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Deploying to Railway + Netlify
2+
3+
This guide shows how to deploy the DevOps Learn platform using Railway for the backend and Netlify for the frontend.
4+
5+
## Architecture
6+
7+
- **Frontend**: Static Next.js site deployed to Netlify
8+
- **Backend**: Node.js WebSocket server deployed to Railway with Docker support
9+
10+
## Step 1: Deploy Backend to Railway
11+
12+
1. **Create Railway Account**: Go to [railway.app](https://railway.app) and sign up
13+
2. **Create New Project**: Click "New Project" → "Deploy from GitHub repo"
14+
3. **Connect Repository**: Select your backend repository
15+
4. **Configure Environment Variables**:
16+
```
17+
FRONTEND_URL=https://your-netlify-site.netlify.app
18+
NODE_ENV=production
19+
```
20+
5. **Deploy**: Railway will automatically detect the Dockerfile and deploy
21+
22+
## Step 2: Deploy Frontend to Netlify
23+
24+
1. **Build Settings**:
25+
- Build command: `npm run build`
26+
- Publish directory: `out`
27+
28+
2. **Environment Variables**:
29+
```
30+
NEXT_PUBLIC_WS_URL=wss://your-railway-app.railway.app
31+
```
32+
33+
3. **Deploy**: Connect your GitHub repo and deploy
34+
35+
## Step 3: Update CORS
36+
37+
After deployment, update the Railway backend environment variable:
38+
```
39+
FRONTEND_URL=https://your-actual-netlify-domain.netlify.app
40+
```
41+
42+
## Local Development
43+
44+
1. **Backend**:
45+
```bash
46+
cd backend
47+
npm install
48+
npm run dev
49+
```
50+
51+
2. **Frontend**:
52+
```bash
53+
npm install
54+
NEXT_PUBLIC_WS_URL=ws://localhost:3001 npm run dev
55+
```
56+
57+
## Cost Breakdown
58+
59+
- **Railway**: $5/month free credit (should cover small projects)
60+
- **Netlify**: Free tier (100GB bandwidth, unlimited sites)
61+
- **Total**: $0/month for starter projects
62+
63+
## Benefits
64+
65+
- ✅ No time limits (unlike Heroku)
66+
- ✅ Auto-scaling
67+
- ✅ Docker support for scenarios
68+
- ✅ WebSocket support
69+
- ✅ Free tier generous enough for learning projects

backend/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Multi-stage build for Railway deployment
2+
FROM node:18-alpine AS base
3+
4+
# Install Docker CLI for scenario management
5+
RUN apk add --no-cache docker-cli
6+
7+
WORKDIR /app
8+
9+
# Copy package files
10+
COPY package*.json ./
11+
12+
# Install dependencies
13+
RUN npm ci --only=production
14+
15+
# Copy source code
16+
COPY . .
17+
18+
# Build TypeScript
19+
RUN npm run build
20+
21+
# Expose the port Railway expects
22+
EXPOSE $PORT
23+
24+
# Set environment variables
25+
ENV NODE_ENV=production
26+
27+
# Start the server
28+
CMD ["npm", "start"]

backend/Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.PHONY: help install dev build start stop clean test lint scenario-build
2+
3+
help:
4+
@echo "DevOps Learning Platform - Available commands:"
5+
@echo " make install - Install dependencies"
6+
@echo " make dev - Start development environment"
7+
@echo " make build - Build production images"
8+
@echo " make start - Start production environment"
9+
@echo " make stop - Stop all services"
10+
@echo " make clean - Clean up containers and volumes"
11+
@echo " make test - Run tests"
12+
@echo " make lint - Run linting"
13+
@echo " make scenario-build - Build all scenario images"
14+
15+
install:
16+
npm install
17+
cd src/server && npm install
18+
19+
dev:
20+
docker-compose up -d
21+
@echo "Frontend: http://localhost:3000"
22+
@echo "Backend: http://localhost:3001"
23+
24+
build:
25+
docker-compose build
26+
$(MAKE) scenario-build
27+
28+
start:
29+
docker-compose up -d --build
30+
31+
stop:
32+
docker-compose down
33+
34+
clean:
35+
docker-compose down -v
36+
docker rmi $$(docker images -q 'devopslearn/*') 2>/dev/null || true
37+
38+
test:
39+
npm test
40+
cd src/server && npm test
41+
42+
lint:
43+
npm run lint
44+
npm run typecheck
45+
46+
scenario-build:
47+
@echo "Building scenario base image..."
48+
docker build -t devopslearn/scenario-base:latest -f docker/Dockerfile.scenario-base .
49+
@echo "Building Keycloak CrashLoop scenario..."
50+
docker build -t devopslearn/scenario-keycloak-crashloop:latest -f scenarios/kubernetes/keycloak-crashloop/Dockerfile scenarios/kubernetes/keycloak-crashloop/
51+
@echo "Scenario images built successfully!"
52+
53+
logs:
54+
docker-compose logs -f
55+
56+
ps:
57+
docker-compose ps

backend/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# DevOps Learn - Backend
2+
3+
WebSocket server for the DevOps Learning Platform that manages interactive scenario containers.
4+
5+
## Features
6+
7+
- WebSocket server for real-time terminal communication
8+
- Docker container management for scenarios
9+
- Kubernetes scenario support with kind clusters
10+
- Automatic Docker network creation
11+
- Image validation and error handling
12+
13+
## Railway Deployment
14+
15+
This backend is designed to be deployed on Railway with Docker support.
16+
17+
### Environment Variables
18+
19+
- `PORT` - Server port (automatically set by Railway)
20+
- `FRONTEND_URL` - Frontend URL for CORS (set to your Netlify URL)
21+
22+
### Deployment Steps
23+
24+
1. Connect this repository to Railway
25+
2. Set environment variables
26+
3. Deploy automatically
27+
28+
## Local Development
29+
30+
```bash
31+
npm install
32+
npm run dev
33+
```
34+
35+
## Building Scenario Images
36+
37+
```bash
38+
make scenario-build
39+
```

backend/docker/Dockerfile.backend

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:18-alpine
2+
3+
# Install Docker CLI
4+
RUN apk add --no-cache docker-cli
5+
6+
WORKDIR /app
7+
8+
# Copy package files
9+
COPY src/server/package*.json ./
10+
11+
# Install dependencies
12+
RUN npm ci
13+
14+
# Copy server files
15+
COPY src/server ./
16+
17+
# Create TypeScript config for server
18+
RUN echo '{"compilerOptions":{"target":"es2020","module":"commonjs","outDir":"./dist","strict":true,"esModuleInterop":true,"skipLibCheck":true,"forceConsistentCasingInFileNames":true}}' > tsconfig.json
19+
20+
# Expose port
21+
EXPOSE 3001
22+
23+
# Start server
24+
CMD ["npm", "run", "dev"]

backend/docker/Dockerfile.frontend

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
# Copy package files
6+
COPY package*.json ./
7+
COPY tsconfig.json ./
8+
COPY next.config.js ./
9+
COPY tailwind.config.js ./
10+
COPY postcss.config.js ./
11+
12+
# Install dependencies
13+
RUN npm ci
14+
15+
# Copy source files
16+
COPY src ./src
17+
COPY public ./public
18+
19+
# Expose port
20+
EXPOSE 3000
21+
22+
# Start development server
23+
CMD ["npm", "run", "dev"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && apt-get install -y curl gnupg
4+
RUN curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
5+
RUN echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
6+
7+
# Install base tools
8+
RUN apt-get update && apt-get install -y curl wget git vim nano htop net-tools dnsutils traceroute telnet jq python3 python3-pip nodejs npm docker.io kubectl lsb-release unzip && rm -rf /var/lib/apt/lists/*
9+
10+
# Install Terraform
11+
RUN wget -O- https://apt.releases.hashicorp.com/gpg | apt-key add - \
12+
&& echo "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/hashicorp.list \
13+
&& apt-get update && apt-get install -y terraform
14+
15+
# Install AWS CLI
16+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
17+
&& unzip awscliv2.zip \
18+
&& ./aws/install \
19+
&& rm -rf awscliv2.zip aws
20+
21+
# Install Helm
22+
RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
23+
24+
# Create scenario user
25+
RUN useradd -m -s /bin/bash devops
26+
USER devops
27+
WORKDIR /home/devops
28+
29+
# Set up shell prompt
30+
RUN echo 'PS1="\\[\\033[01;32m\\]devops@dojo\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ "' >> ~/.bashrc
31+
32+
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)