Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Compose: containerize backend & build frontend

Juan Denis8921b6ff0a4c
diff --git a/backend/.dockerignore b/backend/.dockerignore
new file mode 100644
index 00000000..ce3671ff
--- /dev/null
+++ b/backend/.dockerignore
@@ -0,0 +1,9 @@
+venv/
+__pycache__/
+*.pyc
+*.pyo
+.git
+.env
+*.egg-info/
+.pytest_cache/
+instance/
diff --git a/backend/app/__init__.py b/backend/app/__init__.py
index 172ef204..59f03ff6 100644
--- a/backend/app/__init__.py
+++ b/backend/app/__init__.py
@@ -202,17 +202,22 @@ def create_app(config_name=None):
# Serve frontend for root path
@app.route('/')
def serve_index():
- return send_from_directory(app.static_folder, 'index.html')
+ index = os.path.join(app.static_folder, 'index.html') if app.static_folder else None
+ if index and os.path.isfile(index):
+ return send_from_directory(app.static_folder, 'index.html')
+ return {'message': 'ServerKit API is running', 'docs': '/api/v1/'}, 200
# Catch-all route for SPA - must be after all other routes
@app.errorhandler(404)
def not_found(e):
- # If it's an API request, return JSON 404
from flask import request
if request.path.startswith('/api/'):
return {'error': 'Not found'}, 404
- # Otherwise serve the SPA index.html for client-side routing
- return send_from_directory(app.static_folder, 'index.html')
+ # Serve SPA index.html if it exists, otherwise JSON 404
+ index = os.path.join(app.static_folder, 'index.html') if app.static_folder else None
+ if index and os.path.isfile(index):
+ return send_from_directory(app.static_folder, 'index.html')
+ return {'error': 'Not found'}, 404
return app
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
deleted file mode 100644
index 8e809dde..00000000
--- a/docker-compose.dev.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-# ==============================================
-# ServerKit Development Docker Compose
-# ==============================================
-# FOR LOCAL TESTING ONLY - System management features
-# (PHP install, firewall, etc.) won't work in Docker.
-#
-# Usage:
-# docker compose -f docker-compose.dev.yml up --build
-#
-# Access:
-# Frontend: http://localhost:3000
-# Backend: http://localhost:5000
-# ==============================================
-
-services:
- backend:
- build:
- context: ./backend
- dockerfile: Dockerfile
- container_name: serverkit-backend-dev
- environment:
- - FLASK_ENV=development
- - SECRET_KEY=dev-secret-key-not-for-production
- - JWT_SECRET_KEY=dev-jwt-key-not-for-production
- - DATABASE_URL=sqlite:////app/instance/serverkit.db
- - CORS_ORIGINS=http://localhost,http://localhost:3000,http://localhost:5173
- ports:
- - "5000:5000"
- volumes:
- - dev-data:/app/instance
- - dev-config:/etc/serverkit
- networks:
- - serverkit-dev
- healthcheck:
- test: ["CMD", "curl", "-f", "http://localhost:5000/api/v1/system/health"]
- interval: 10s
- timeout: 5s
- retries: 3
-
- frontend-dev:
- image: node:20-alpine
- container_name: serverkit-frontend-dev
- working_dir: /app
- command: sh -c "npm install && npm run dev -- --host 0.0.0.0 --port 3000"
- environment:
- - VITE_API_URL=http://localhost:5000
- ports:
- - "3000:3000"
- volumes:
- - ./frontend:/app
- - frontend-modules:/app/node_modules
- depends_on:
- backend:
- condition: service_healthy
- networks:
- - serverkit-dev
-
-networks:
- serverkit-dev:
- driver: bridge
- name: serverkit-dev
-
-volumes:
- dev-data:
- name: serverkit-dev-data
- dev-config:
- name: serverkit-dev-config
- frontend-modules:
- name: serverkit-frontend-modules
diff --git a/docker-compose.yml b/docker-compose.yml
index d84d526d..d8e6ab6a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,35 +1,59 @@
# ============================================
# ServerKit Docker Compose
# ============================================
-# The backend runs directly on the host (not in Docker)
-# for full system access. Only the frontend runs in Docker.
-#
-# Architecture:
-# - Host nginx (port 80/443) routes domains to apps
-# - ServerKit frontend (port 8080) serves the UI
-# - ServerKit backend (port 5000) provides the API
+# Runs both backend and frontend in Docker.
+# Note: System management features (PHP install,
+# firewall, etc.) won't work in Docker.
#
# Usage:
-# 1. Copy .env.example to .env and configure
-# 2. Start backend: sudo systemctl start serverkit
-# 3. Start frontend: docker compose up -d
-# 4. Configure host nginx to route your domain
+# docker compose up --build -d
+#
+# Access:
+# Frontend: http://localhost:3847
+# Backend: http://localhost:5849
# ============================================
services:
+ backend:
+ build:
+ context: ./backend
+ dockerfile: Dockerfile
+ container_name: serverkit-backend
+ environment:
+ - FLASK_ENV=development
+ - SECRET_KEY=dev-secret-key-not-for-production
+ - JWT_SECRET_KEY=dev-jwt-key-not-for-production
+ - DATABASE_URL=sqlite:////app/instance/serverkit.db
+ - CORS_ORIGINS=http://localhost,http://localhost:3847,http://localhost:5173
+ ports:
+ - "5849:5000"
+ volumes:
+ - serverkit-data:/app/instance
+ - serverkit-config:/etc/serverkit
+ networks:
+ - serverkit-network
+ restart: unless-stopped
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost:5000/api/v1/system/health"]
+ interval: 10s
+ timeout: 5s
+ retries: 3
+ logging:
+ driver: "json-file"
+ options:
+ max-size: "10m"
+ max-file: "3"
+
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: serverkit-frontend
ports:
- # Use 8080 internally - host nginx handles 80/443 and routes by domain
- - "127.0.0.1:8080:80"
- extra_hosts:
- # Allows container to reach the host machine where backend runs
- - "host.docker.internal:host-gateway"
- volumes:
- - ./nginx/ssl:/etc/nginx/ssl:ro
+ - "3847:80"
+ depends_on:
+ backend:
+ condition: service_healthy
networks:
- serverkit-network
restart: unless-stopped
@@ -48,3 +72,9 @@ networks:
serverkit-network:
driver: bridge
name: serverkit-network
+
+volumes:
+ serverkit-data:
+ name: serverkit-data
+ serverkit-config:
+ name: serverkit-config
diff --git a/frontend/.dockerignore b/frontend/.dockerignore
index 9b0ece52..49a2c8ed 100644
--- a/frontend/.dockerignore
+++ b/frontend/.dockerignore
@@ -1,6 +1,4 @@
node_modules
-src
-public
.git
.gitignore
*.md
@@ -9,7 +7,3 @@ public
.idea
.DS_Store
Thumbs.db
-package*.json
-vite.config.js
-eslint.config.js
-index.html
diff --git a/frontend/Dockerfile b/frontend/Dockerfile
index c4d01f90..bb06fe2f 100644
--- a/frontend/Dockerfile
+++ b/frontend/Dockerfile
@@ -1,13 +1,25 @@
# Frontend Dockerfile for ServerKit
-# Pre-built assets are copied in — the Vite build runs on the host
-# to avoid memory issues on low-RAM VPS servers.
+# Multi-stage build: Node builds the assets, nginx serves them.
+
+# Stage 1: Build
+FROM node:20-alpine AS builder
+
+WORKDIR /app
+
+COPY package*.json ./
+RUN npm ci
+
+COPY . .
+RUN npm run build
+
+# Stage 2: Serve
FROM nginx:alpine
# Copy custom nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf
-# Copy pre-built frontend assets
-COPY dist /usr/share/nginx/html
+# Copy built frontend assets from builder
+COPY --from=builder /app/dist /usr/share/nginx/html
# Create non-root user for nginx
RUN chown -R nginx:nginx /usr/share/nginx/html && \
diff --git a/frontend/nginx.conf b/frontend/nginx.conf
index 253ef1d7..5f65cb51 100644
--- a/frontend/nginx.conf
+++ b/frontend/nginx.conf
@@ -25,7 +25,7 @@ server {
# Proxy API requests to backend (running on host, not in Docker)
location /api {
- proxy_pass http://host.docker.internal:5000;
+ proxy_pass http://backend:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -40,7 +40,7 @@ server {
# WebSocket support for socket.io (running on host, not in Docker)
location /socket.io {
- proxy_pass http://host.docker.internal:5000;
+ proxy_pass http://backend:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
diff --git a/scripts/dev/dev.bat b/scripts/dev/dev.bat
index adbf119c..186e50c3 100644
--- a/scripts/dev/dev.bat
+++ b/scripts/dev/dev.bat
@@ -17,27 +17,27 @@ goto help
:up
echo Starting ServerKit (Docker)...
-docker compose -f docker-compose.dev.yml up --build -d
+docker compose up --build -d
echo.
-echo Frontend: http://localhost:3000
-echo Backend: http://localhost:5000
+echo Frontend: http://localhost:3847
+echo Backend: http://localhost:5849
echo.
goto end
:down
-docker compose -f docker-compose.dev.yml down
+docker compose down
goto end
:logs
-docker compose -f docker-compose.dev.yml logs -f
+docker compose logs -f
goto end
:shell
-docker exec -it serverkit-backend-dev /bin/bash
+docker exec -it serverkit-backend /bin/bash
goto end
:reset
-docker compose -f docker-compose.dev.yml down -v
+docker compose down -v
echo Run 'dev.bat up' to start fresh.
goto end
@@ -51,8 +51,6 @@ echo logs View logs
echo shell Shell into backend
echo reset Reset all data
echo.
-echo Note: Use WSL for full system feature testing.
-echo.
goto end
:end