Skip to content

Commit 5ab8d49

Browse files
author
Lasim
committed
chore(backend): update environment configuration and README for Docker
1 parent adf8120 commit 5ab8d49

File tree

4 files changed

+207
-278
lines changed

4 files changed

+207
-278
lines changed

services/backend/.env.example

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
# Database Configuration
2-
# Choose one: sqlite, turso
3-
DB_TYPE=sqlite
1+
# Server Configuration
2+
NODE_ENV=development
3+
PORT=3000
4+
HOST=localhost
45

5-
# SQLite Configuration (when DB_TYPE=sqlite)
6-
SQLITE_DB_PATH=persistent_data/database/deploystack.db
6+
# Frontend Integration
7+
# URL of your frontend application for CORS and redirects
8+
DEPLOYSTACK_FRONTEND_URL=http://localhost:5173
79

8-
# Turso Configuration (when DB_TYPE=turso)
9-
# Get these values from: https://docs.turso.tech/sdk/ts/quickstart
10-
# TURSO_DATABASE_URL=libsql://your-database-url
11-
# TURSO_AUTH_TOKEN=your-auth-token
10+
# Security
11+
# Required: 32+ character secret for encrypting cookies and global settings
12+
# Generate with: openssl rand -hex 32
13+
DEPLOYSTACK_ENCRYPTION_SECRET=your-32-character-secret-key-here-change-this
1214

1315
# Logging Configuration
1416
# Available levels: trace, debug, info, warn, error, fatal
15-
# Default: info (production), debug (development)
16-
LOG_LEVEL=info
17+
# Default: debug (development), info (production)
18+
# LOG_LEVEL=debug
1719

18-
# Other existing environment variables...
19-
NODE_ENV=development
20-
HOST=localhost
21-
PORT=3000
22-
COOKIE_SECRET=a-very-secret-and-strong-secret-for-cookies
20+
# Plugin System (Optional)
21+
# Custom path for loading plugins
22+
# PLUGINS_PATH=/path/to/custom/plugins
23+
24+
# Database Configuration (Optional)
25+
# Note: Database configuration is primarily handled through the setup wizard at /setup
26+
# The database type and connection details are stored in persistent_data/db.selection.json
27+
# However, you can override with environment variables if needed:
28+
29+
# Turso Database Configuration (Optional)
30+
# If you want to use Turso instead of SQLite, you can set these variables
31+
# Get these values from: https://turso.tech/
32+
# TURSO_DATABASE_URL=libsql://your-database-url.turso.io
33+
# TURSO_AUTH_TOKEN=your-turso-auth-token

services/backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ COPY services/backend/dist ./dist
1616
RUN mkdir -p /shared/public/img/
1717
COPY services/shared/public/img/favicon.ico /shared/public/img/
1818

19-
# Create data directory for SQLite database
20-
RUN mkdir -p /app/data
19+
# Create persistent_data directory structure
20+
RUN mkdir -p /app/persistent_data
2121

2222
# Create a default .env file
2323
RUN echo "NODE_ENV=production" > .env && \

services/backend/README.md

Lines changed: 93 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ A modular and extensible backend API for the DeployStack CI/CD platform, built w
1515
- **Logging**: Comprehensive request logging with request IDs and timing
1616
- **Developer-friendly**: Pretty logging in development, production-ready in production
1717

18-
## 🚀 Run
18+
## 🚀 Quick Start with Docker
1919

2020
```bash
21+
# Run with Docker (using docker-compose recommended)
22+
docker-compose up -d
23+
24+
# Or run standalone with volume for data persistence
2125
docker run -it -p 3000:3000 \
22-
-e FOO=bar22 \
23-
-v $(pwd)/data:/app/data \
26+
-e NODE_ENV=production \
27+
-e DEPLOYSTACK_ENCRYPTION_SECRET=your-32-character-secret-key-here \
28+
-v deploystack_data:/app/persistent_data \
2429
deploystack/backend:latest
30+
31+
# Access the setup wizard at http://localhost:3000
32+
# (or http://localhost:8080 if using the full docker-compose stack)
2533
```
2634

2735
## 📋 Prerequisites
@@ -31,20 +39,44 @@ docker run -it -p 3000:3000 \
3139

3240
## 🛠️ Installation
3341

42+
### Development Setup
43+
3444
```bash
3545
# Clone the repository
36-
git clone https://github.com/deploystack/deploystack.git
46+
git clone https://github.com/deploystackio/deploystack.git
3747
cd deploystack
3848

3949
# Navigate to backend directory
4050
cd services/backend
4151

4252
# Install dependencies
4353
npm install
54+
55+
# Create .env file (see Environment Variables section)
56+
cp .env.example .env # Or create manually
57+
58+
# Start development server
59+
npm run dev
60+
61+
# Access at http://localhost:3000
62+
```
63+
64+
### Production Setup with Docker
65+
66+
```bash
67+
# Using Docker Compose (recommended)
68+
git clone https://github.com/deploystackio/deploystack.git
69+
cd deploystack
70+
docker-compose up -d
71+
72+
# Access frontend at http://localhost:8080
73+
# Backend API at http://localhost:3000
4474
```
4575

4676
## 🚀 Usage
4777

78+
### Development Commands
79+
4880
```bash
4981
# Run in development mode (with live reloading)
5082
npm run dev
@@ -57,94 +89,73 @@ npm run start
5789

5890
# Lint and fix TypeScript files
5991
npm run lint
60-
```
6192

62-
## 🧱 Project Structure
93+
# Database migrations
94+
npm run db:generate # Generate new migrations
95+
npm run db:up # Apply migrations
6396

64-
```bash
65-
services/backend/
66-
├── src/
67-
│ ├── api/ # API route handlers
68-
│ ├── db/ # Database configuration and schema
69-
│ │ ├── config.ts # Database connection setup
70-
│ │ ├── index.ts # Database exports
71-
│ │ ├── migrations.ts # Migration management
72-
│ │ └── schema.ts # Database schema definitions
73-
│ ├── email/ # Email system (NEW)
74-
│ │ ├── templates/ # Pug email templates
75-
│ │ │ ├── layouts/ # Base layout components
76-
│ │ │ │ ├── base.pug # Main email layout
77-
│ │ │ │ ├── header.pug # Email header
78-
│ │ │ │ └── footer.pug # Email footer
79-
│ │ │ ├── welcome.pug # Welcome email template
80-
│ │ │ ├── password-reset.pug # Password reset template
81-
│ │ │ └── notification.pug # General notification template
82-
│ │ ├── emailService.ts # Main email service
83-
│ │ ├── templateRenderer.ts # Pug template renderer
84-
│ │ ├── types.ts # Email type definitions
85-
│ │ ├── example.ts # Usage examples
86-
│ │ └── index.ts # Email module exports
87-
│ ├── fastify/ # Fastify configuration
88-
│ │ ├── config/ # Fastify setup
89-
│ │ ├── hooks/ # Request/response hooks
90-
│ │ └── plugins/ # Fastify plugins
91-
│ ├── global-settings/ # Global configuration system
92-
│ │ ├── github-oauth.ts # GitHub OAuth settings
93-
│ │ ├── smtp.ts # SMTP email settings
94-
│ │ ├── types.ts # Global settings types
95-
│ │ └── index.ts # Settings initialization
96-
│ ├── hooks/ # Authentication hooks
97-
│ ├── lib/ # External library integrations
98-
│ │ └── lucia.ts # Lucia authentication setup
99-
│ ├── middleware/ # Request middleware
100-
│ ├── plugin-system/ # Plugin architecture
101-
│ ├── plugins/ # Available plugins
102-
│ ├── routes/ # API route definitions
103-
│ │ ├── auth/ # Authentication routes
104-
│ │ ├── db/ # Database management routes
105-
│ │ ├── globalSettings/ # Settings management routes
106-
│ │ ├── roles/ # Role management routes
107-
│ │ └── users/ # User management routes
108-
│ ├── services/ # Business logic services
109-
│ │ ├── globalSettingsService.ts # Settings service
110-
│ │ ├── roleService.ts # Role management
111-
│ │ ├── teamService.ts # Team management
112-
│ │ └── userService.ts # User management
113-
│ ├── types/ # TypeScript type definitions
114-
│ ├── utils/ # Utility functions
115-
│ │ ├── banner.ts # Startup banner
116-
│ │ └── encryption.ts # Encryption utilities
117-
│ ├── server.ts # Server configuration
118-
│ └── index.ts # Application entry point
119-
├── drizzle/ # Database migrations
120-
├── persistent_data/ # Persistent application data
121-
├── tests/ # Test files
122-
├── .env # Environment variables (not in version control)
123-
├── DB.md # Database documentation
124-
├── GLOBAL_SETTINGS.md # Global settings documentation
125-
├── Mail.md # Email system documentation (NEW)
126-
├── PLUGINS.md # Plugin system documentation
127-
├── ROLES.md # Role management documentation
128-
├── SECURITY.md # Security documentation
129-
├── package.json # Package dependencies and scripts
130-
└── tsconfig.json # TypeScript configuration
97+
# API documentation
98+
npm run api:spec # Generate OpenAPI spec
13199
```
132100

101+
### Initial Setup
102+
103+
1. **First Run**: Navigate to `/setup` in your browser
104+
2. **Choose Database**: Select SQLite (default) or Turso
105+
3. **Create Admin**: Set up your administrator account
106+
4. **Configure Settings**: Access Global Settings to configure email, features, etc.
107+
133108
## 💾 Persistent Data
134109

135-
The `services/backend/persistent_data/` directory is designated for storing all data that needs to persist across application restarts or deployments.
110+
All persistent data is stored in the `persistent_data/` directory, which maintains the same structure across development and production environments.
111+
112+
### Directory Structure
113+
114+
```
115+
persistent_data/
116+
├── database/
117+
│ └── deploystack.db # SQLite database (if using SQLite)
118+
└── db.selection.json # Database type configuration
119+
```
120+
121+
### Environment-Specific Locations
122+
123+
**Development (Local):**
124+
- Location: `services/backend/persistent_data/`
125+
- Created automatically when running `npm run dev`
126+
- Direct file system access
136127

137-
**Purpose:**
128+
**Production (Docker):**
129+
- Location: `/app/persistent_data/` (inside container)
130+
- Mounted as Docker volume: `deploystack_backend_persistent`
131+
- Persists data between container restarts
138132

139-
- To provide a single, consistent location for all persistent backend data.
140-
- When developing backend features that require data persistence (e.g., database files, configuration files that should not be in version control but are generated/modified at runtime), use this directory exclusively.
133+
### Backup Strategies
141134

142-
**Examples of data stored here:**
135+
**Docker Volume Backup:**
136+
```bash
137+
# Create backup
138+
docker run --rm -v deploystack_backend_persistent:/data \
139+
-v $(pwd):/backup alpine \
140+
tar czf /backup/deploystack-backup-$(date +%Y%m%d).tar.gz /data
141+
142+
# Restore backup
143+
docker run --rm -v deploystack_backend_persistent:/data \
144+
-v $(pwd):/backup alpine \
145+
tar xzf /backup/deploystack-backup-20250108.tar.gz -C /
146+
```
143147

144-
- SQLite database file (e.g., `persistent_data/database/deploystack.db`)
145-
- Database selection configuration (e.g., `persistent_data/db.selection.json`)
148+
**Local Development Backup:**
149+
```bash
150+
# Create backup
151+
tar czf deploystack-backup-$(date +%Y%m%d).tar.gz \
152+
services/backend/persistent_data/
153+
154+
# Restore backup
155+
tar xzf deploystack-backup-20250108.tar.gz
156+
```
146157

147-
This ensures that persistent data is managed in a predictable way and is not scattered across the project.
158+
**Important:** Always backup the entire `persistent_data/` directory/volume, not just the database file, as it contains critical configuration.
148159

149160
## 📧 Email System
150161

@@ -192,6 +203,7 @@ NODE_ENV=development
192203
PORT=3000
193204
HOST=localhost
194205
LOG_LEVEL=info
206+
DEPLOYSTACK_FRONTEND_URL=http://localhost:5173 # Frontend URL for CORS and redirects
195207
DEPLOYSTACK_ENCRYPTION_SECRET=your-32-character-secret-key-here # Required for global settings encryption
196208
```
197209

0 commit comments

Comments
 (0)