Successfully implemented a comprehensive application deployment system that allows users to deploy applications from Git repositories through the dashboard UI. The system supports 7 different application types and handles the complete deployment lifecycle.
Added new columns to __sys_applications table:
app_type: Type of application (npm, react, nextjs, php, python, static, docker)port: Port number the application runs on (default: 3000)container_id: Docker container ID for trackingExisting tables used:
__sys_applications: Stores application metadata__sys_deployments: Tracks deployment history and logsservices/api/src/services/deployment.ts)Key Features:
- deployFromGit(): Full deployment workflow
- cloneRepository(): Git clone with branch support
- buildDockerImage(): Dynamic Dockerfile generation
- startContainer(): Container orchestration
- stopApplication(): Graceful shutdown
- getDeploymentLogs(): Build and deployment logs
- getContainerLogs(): Runtime container logs
services/api/src/services/nginx.ts)/<slug>/services/api/src/routes/applications.ts)New Endpoints:
POST /api/applications/:id/deploy - Deploy applicationPOST /api/applications/:id/stop - Stop applicationGET /api/applications/:id/deployments - List deploymentsGET /api/applications/:id/deployments/:deploymentId/logs - Deployment logsGET /api/applications/:id/logs - Container logsEnhanced Endpoints:
POST /api/applications - Create with app_type, port, domains, etc.DELETE /api/applications/:id - Stop container before deletiondocker-compose.yml)api-service:
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Docker-in-Docker
privileged: true # Required for container management
apps-proxy.conf for dynamic app routing| Type | Base Image | Default Build | Default Start | Port |
|---|---|---|---|---|
| npm | node:18-alpine | npm install | npm start | 3000 |
| react | node:18-alpine | npm install && npm run build | npm run preview | 3000 |
| nextjs | node:18-alpine | npm install && npm run build | npm start | 3000 |
| php | php:8.2-apache | (none) | apache | 80 |
| python | python:3.11-slim | pip install -r requirements.txt | python app.py | 3000 |
| static | nginx:alpine | (none) | nginx | 80 |
| docker | (custom) | docker build | docker run | custom |
┌─────────────────────────────────────────────────────────────────┐
│ 1. User fills deployment form in dashboard │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 2. Create application record in database │
│ - name, slug, app_type, repository_url, etc. │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 3. Create deployment record (status: pending) │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 4. Clone git repository to /apps/{app-id} │
│ - git clone -b {branch} {url} /apps/{app-id} │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 5. Generate Dockerfile based on app type │
│ - Auto-detect package manager, runtime, etc. │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 6. Build Docker image │
│ - docker build -t saas-app-{id}:latest │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 7. Stop existing container (if any) │
│ - docker stop saas-app-{id} │
│ - docker rm saas-app-{id} │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 8. Start new container │
│ - docker run --name saas-app-{id} │
│ --network saas-network │
│ --restart unless-stopped │
│ -p {port}:3000 │
│ saas-app-{id}:latest │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 9. Update nginx configuration │
│ - Generate proxy rules for /{slug}/ path │
│ - Add custom domain server blocks │
│ - Write to /etc/nginx/conf.d/apps-proxy.conf │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 10. Reload nginx │
│ - nginx -t (test configuration) │
│ - nginx -s reload │
└──────────────────────┬──────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────┐
│ 11. Update deployment status to 'deployed' │
│ - Update application status to 'active' │
│ - Save container_id in database │
└─────────────────────────────────────────────────────────────────┘
services/api/src/services/deployment.ts - Deployment orchestrationservices/api/src/services/nginx.ts - Nginx configuration managementdashboard/src/components/DeployApplicationModal.tsx - Deployment UInginx/conf.d/apps-proxy.conf - Dynamic app routing configdocs/DEPLOYMENT-SYSTEM.md - Comprehensive documentationservices/api/src/routes/applications.ts - Added deployment endpointsdashboard/src/pages/Applications.tsx - Added deploy/stop UIdashboard/src/services/api.ts - Added deployment API methodsdocker-compose.yml - Added Docker socket and privileged modenginx/conf.d/default.conf - Integrated apps-proxy.confservices/api/package.json - Added dockerode dependencyALTER TABLE __sys_applications ADD COLUMN app_type VARCHAR(50) DEFAULT 'static';
ALTER TABLE __sys_applications ADD COLUMN port INTEGER DEFAULT 3000;
ALTER TABLE __sys_applications ADD COLUMN container_id VARCHAR(255);
# Create application via API
curl -X POST http://localhost:8888/api/applications \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "My Static Site",
"slug": "my-site",
"appType": "static",
"repositoryUrl": "https://github.com/user/static-site.git",
"branch": "main",
"port": 80
}'
# Deploy
curl -X POST http://localhost:8888/api/applications/{id}/deploy \
-H "Authorization: Bearer $TOKEN"
# Access
open http://localhost:8888/my-site/
Via Dashboard:
npm install && npm run buildnpm run preview# Get deployment logs
curl http://localhost:8888/api/applications/{id}/deployments \
-H "Authorization: Bearer $TOKEN"
# Get container logs
curl http://localhost:8888/api/applications/{id}/logs \
-H "Authorization: Bearer $TOKEN"
docker compose build api-service dashboarddocker compose up -d⚠️ Important Security Notes:
All deployments are logged in the __sys_deployments table with:
For issues or questions:
docker logs saas-app-{id}docker exec saas-gateway nginx -tThe deployment system is now fully functional and ready for use. Users can deploy applications from Git repositories through an intuitive dashboard interface with support for multiple application types, custom configurations, and automatic proxy setup.