Skip to content

Commit a50ef47

Browse files
authored
Merge pull request #93 from Worklenz/development
Development
2 parents 1224965 + db4240d commit a50ef47

15 files changed

Lines changed: 330 additions & 208 deletions

File tree

.env

Lines changed: 0 additions & 34 deletions
This file was deleted.

.env.example

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.md

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,34 +358,88 @@ const s3Client = new S3Client({
358358

359359
### Environment Configuration
360360

361-
The `.env` file includes the necessary configuration for using MinIO:
361+
The project uses the following environment file structure:
362362

363+
- **Frontend**:
364+
- `worklenz-frontend/.env.development` - Development environment variables
365+
- `worklenz-frontend/.env.production` - Production build variables
366+
367+
- **Backend**:
368+
- `worklenz-backend/.env` - Backend environment variables
369+
370+
### Setting Up Environment Files
371+
372+
The Docker environment script will create or overwrite all environment files:
373+
374+
```bash
375+
# For HTTP/WS
376+
./update-docker-env.sh your-hostname
377+
378+
# For HTTPS/WSS
379+
./update-docker-env.sh your-hostname true
363380
```
364-
STORAGE_PROVIDER=s3
365-
AWS_REGION=us-east-1
366-
AWS_BUCKET=worklenz-bucket
367-
S3_ACCESS_KEY_ID=minioadmin
368-
S3_SECRET_ACCESS_KEY=minioadmin
369-
S3_URL=http://minio:9000
370-
```
371381

372-
When the backend service starts, it will use these environment variables to connect to MinIO for file storage.
382+
This script generates properly configured environment files for both development and production environments.
383+
384+
## Docker Deployment
373385

374-
## Development
386+
### Local Development with Docker
387+
388+
1. Set up the environment files:
389+
```bash
390+
# For HTTP/WS
391+
./update-docker-env.sh
392+
393+
# For HTTPS/WSS
394+
./update-docker-env.sh localhost true
395+
```
396+
397+
2. Run the application using Docker Compose:
398+
```bash
399+
docker-compose up -d
400+
```
375401

376-
For development, you can use the provided Docker setup which includes all necessary dependencies. The code will be running inside containers, but you can still edit files locally and see changes reflected in real-time.
402+
3. Access the application:
403+
- Frontend: http://localhost:5000
404+
- Backend API: http://localhost:3000 (or https://localhost:3000 with SSL)
405+
406+
### Remote Server Deployment
407+
408+
When deploying to a remote server:
409+
410+
1. Set up the environment files with your server's hostname:
411+
```bash
412+
# For HTTP/WS
413+
./update-docker-env.sh your-server-hostname
414+
415+
# For HTTPS/WSS
416+
./update-docker-env.sh your-server-hostname true
417+
```
418+
419+
This ensures that the frontend correctly connects to the backend API.
420+
421+
2. Pull and run the latest Docker images:
422+
```bash
423+
docker-compose pull
424+
docker-compose up -d
425+
```
426+
427+
3. Access the application through your server's hostname:
428+
- Frontend: http://your-server-hostname:5000
429+
- Backend API: http://your-server-hostname:3000
430+
431+
### Environment Configuration
377432

378-
## Production Deployment
433+
The Docker setup uses environment variables to configure the services:
379434

380-
For production deployment:
435+
- Frontend:
436+
- `VITE_API_URL`: URL of the backend API (default: http://backend:3000 for container networking)
437+
- `VITE_SOCKET_URL`: WebSocket URL for real-time communication (default: ws://backend:3000)
381438

382-
1. Update the `.env` file with production settings
383-
2. Build custom Docker images or use the provided ones
384-
3. Deploy using Docker Compose or a container orchestration platform like Kubernetes
439+
- Backend:
440+
- Database connection parameters
441+
- Storage configuration
442+
- Other backend settings
385443

386-
For MinIO in production, consider:
387-
- Setting up proper credentials (change default minioadmin/minioadmin)
388-
- Configuring persistent storage
389-
- Setting up proper networking and access controls
390-
- Using multiple MinIO instances for high availability
444+
For custom configuration, edit the `.env` file or the `update-docker-env.sh` script.
391445

docker-compose.yml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
services:
22
frontend:
3-
image: docker.io/chamikajaycey/worklenz-frontend:latest
3+
build:
4+
context: ./worklenz-frontend
5+
dockerfile: Dockerfile
46
container_name: worklenz_frontend
57
ports:
68
- "5000:5000"
79
depends_on:
810
backend:
911
condition: service_started
12+
env_file:
13+
- ./worklenz-frontend/.env.production
1014
networks:
1115
- worklenz
1216

@@ -20,36 +24,8 @@ services:
2024
condition: service_healthy
2125
minio:
2226
condition: service_started
23-
environment:
24-
- AWS_REGION=${AWS_REGION:-us-east-1}
25-
- BACKEND_PUBLIC_DIR
26-
- BACKEND_VIEWS_DIR
27-
- COMMIT_BUILD_IMMEDIATELY
28-
- COOKIE_SECRET
29-
- DB_HOST=${DB_HOST:-db}
30-
- DB_MAX_CLIENTS
31-
- DB_NAME=${DB_NAME:-worklenz_db}
32-
- DB_PASSWORD=${DB_PASSWORD:-password}
33-
- DB_PORT=${DB_PORT:-5432}
34-
- DB_USER=${DB_USER:-postgres}
35-
- GOOGLE_CALLBACK_URL
36-
- GOOGLE_CLIENT_ID
37-
- GOOGLE_CLIENT_SECRET
38-
- HOSTNAME
39-
- LOGIN_FAILURE_REDIRECT
40-
- NODE_ENV=${NODE_ENV:-development}
41-
- PORT=${PORT:-3000}
42-
- SESSION_NAME
43-
- SESSION_SECRET
44-
- SLACK_WEBHOOK
45-
- SOCKET_IO_CORS
46-
- SOURCE_EMAIL
47-
- USE_PG_NATIVE
48-
- STORAGE_PROVIDER=${STORAGE_PROVIDER:-s3}
49-
- AWS_BUCKET=${BUCKET:-worklenz-bucket}
50-
- AWS_ACCESS_KEY_ID=${S3_ACCESS_KEY_ID:-minioadmin}
51-
- AWS_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY:-minioadmin}
52-
- S3_URL=${S3_URL:-http://minio:9000}
27+
env_file:
28+
- ./worklenz-backend/.env
5329
networks:
5430
- worklenz
5531

@@ -113,7 +89,23 @@ services:
11389
- worklenz
11490
volumes:
11591
- worklenz_postgres_data:/var/lib/postgresql/data
116-
- ./worklenz-backend/database/:/docker-entrypoint-initdb.d
92+
- type: bind
93+
source: ./worklenz-backend/database
94+
target: /docker-entrypoint-initdb.d
95+
consistency: cached
96+
command: >
97+
bash -c '
98+
if command -v apt-get >/dev/null 2>&1; then
99+
apt-get update && apt-get install -y dos2unix
100+
elif command -v apk >/dev/null 2>&1; then
101+
apk add --no-cache dos2unix
102+
fi &&
103+
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '\''
104+
dos2unix "{}" 2>/dev/null || true
105+
chmod +x "{}"
106+
'\'' \; &&
107+
exec docker-entrypoint.sh postgres
108+
'
117109
118110
volumes:
119111
worklenz_postgres_data:

update-docker-env.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
3+
# Script to set environment variables for Docker deployment
4+
# Usage: ./update-docker-env.sh [hostname] [use_ssl]
5+
6+
# Default hostname if not provided
7+
DEFAULT_HOSTNAME="localhost"
8+
HOSTNAME=${1:-$DEFAULT_HOSTNAME}
9+
10+
# Check if SSL should be used
11+
USE_SSL=${2:-false}
12+
13+
# Set protocol prefixes based on SSL flag
14+
if [ "$USE_SSL" = "true" ]; then
15+
HTTP_PREFIX="https://"
16+
WS_PREFIX="wss://"
17+
else
18+
HTTP_PREFIX="http://"
19+
WS_PREFIX="ws://"
20+
fi
21+
22+
# Frontend URLs
23+
FRONTEND_URL="${HTTP_PREFIX}${HOSTNAME}:5000"
24+
MINIO_DASHBOARD_URL="${HTTP_PREFIX}${HOSTNAME}:9001"
25+
26+
# Create or overwrite frontend .env.development file
27+
mkdir -p worklenz-frontend
28+
cat > worklenz-frontend/.env.development << EOL
29+
# API Connection
30+
VITE_API_URL=http://localhost:3000
31+
VITE_SOCKET_URL=ws://localhost:3000
32+
33+
# Application Environment
34+
VITE_APP_TITLE=Worklenz
35+
VITE_APP_ENV=development
36+
37+
# Mixpanel
38+
VITE_MIXPANEL_TOKEN=
39+
40+
# Recaptcha
41+
VITE_ENABLE_RECAPTCHA=false
42+
VITE_RECAPTCHA_SITE_KEY=
43+
44+
# Session ID
45+
VITE_WORKLENZ_SESSION_ID=worklenz-session-id
46+
EOL
47+
48+
# Create frontend .env.production file
49+
cat > worklenz-frontend/.env.production << EOL
50+
# API Connection
51+
VITE_API_URL=${HTTP_PREFIX}${HOSTNAME}:3000
52+
VITE_SOCKET_URL=${WS_PREFIX}${HOSTNAME}:3000
53+
54+
# Application Environment
55+
VITE_APP_TITLE=Worklenz
56+
VITE_APP_ENV=production
57+
58+
# Mixpanel
59+
VITE_MIXPANEL_TOKEN=
60+
61+
# Recaptcha
62+
VITE_ENABLE_RECAPTCHA=false
63+
VITE_RECAPTCHA_SITE_KEY=
64+
65+
# Session ID
66+
VITE_WORKLENZ_SESSION_ID=worklenz-session-id
67+
EOL
68+
69+
# Create backend environment file
70+
mkdir -p worklenz-backend
71+
cat > worklenz-backend/.env << EOL
72+
# Server
73+
NODE_ENV=production
74+
PORT=3000
75+
SESSION_NAME=worklenz.sid
76+
SESSION_SECRET=change_me_in_production
77+
COOKIE_SECRET=change_me_in_production
78+
79+
# CORS
80+
SOCKET_IO_CORS=${FRONTEND_URL}
81+
SERVER_CORS=${FRONTEND_URL}
82+
83+
# Database
84+
DB_HOST=db
85+
DB_PORT=5432
86+
DB_USER=postgres
87+
DB_PASSWORD=password
88+
DB_NAME=worklenz_db
89+
DB_MAX_CLIENTS=50
90+
USE_PG_NATIVE=true
91+
92+
# Storage Configuration
93+
STORAGE_PROVIDER=s3
94+
AWS_REGION=us-east-1
95+
AWS_BUCKET=worklenz-bucket
96+
AWS_ACCESS_KEY_ID=minioadmin
97+
AWS_SECRET_ACCESS_KEY=minioadmin
98+
S3_URL=http://minio:9000
99+
100+
# Backend Directories
101+
BACKEND_PUBLIC_DIR=./public
102+
BACKEND_VIEWS_DIR=./views
103+
104+
# Host
105+
HOSTNAME=${HOSTNAME}
106+
FRONTEND_URL=${FRONTEND_URL}
107+
108+
# Email
109+
SOURCE_EMAIL=no-reply@example.com
110+
111+
# Notifications
112+
SLACK_WEBHOOK=
113+
114+
# Other Settings
115+
COMMIT_BUILD_IMMEDIATELY=true
116+
117+
# JWT Secret
118+
JWT_SECRET=change_me_in_production
119+
EOL
120+
121+
echo "Environment configuration updated for ${HOSTNAME} with" $([ "$USE_SSL" = "true" ] && echo "HTTPS/WSS" || echo "HTTP/WS")
122+
echo "Created/updated environment files:"
123+
echo "- worklenz-frontend/.env.development (development)"
124+
echo "- worklenz-frontend/.env.production (production build)"
125+
echo "- worklenz-backend/.env"
126+
echo
127+
echo "To run with Docker Compose, use: docker-compose up -d"
128+
echo
129+
echo "Frontend URL: ${FRONTEND_URL}"
130+
echo "API URL: ${HTTP_PREFIX}${HOSTNAME}:3000"
131+
echo "Socket URL: ${WS_PREFIX}${HOSTNAME}:3000"
132+
echo "MinIO Dashboard URL: ${MINIO_DASHBOARD_URL}"
133+
echo "CORS is configured to allow requests from: ${FRONTEND_URL}"

0 commit comments

Comments
 (0)