Skip to content

Commit 83bbd1e

Browse files
authored
Merge pull request #25 from Materials-Data-Science-and-Informatics/enhancement/dockerize-app
Updated version of the app
2 parents 17e5a8a + 07b4f09 commit 83bbd1e

106 files changed

Lines changed: 138620 additions & 4630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# .dockerignore - Excludes files from Docker build context
2+
# Reduces build time, image size, and prevents leaking sensitive data
3+
4+
# Version control
5+
.git/
6+
.gitignore
7+
.github/
8+
9+
# Python cache and compiled files
10+
__pycache__/
11+
*.py[cod]
12+
*$py.class
13+
*.so
14+
.pytest_cache/
15+
16+
# Virtual environments
17+
.venv/
18+
venv/
19+
env/
20+
ENV/
21+
.poetry/
22+
23+
# Environment variables (SECURITY: never include secrets in images)
24+
.env
25+
.env.*
26+
27+
# Documentation
28+
# Keep README.md for Poetry package installation
29+
# *.md # Commented out to allow README.md
30+
docs/
31+
LICENSE
32+
33+
# Development and testing
34+
.pre-commit-config.yaml
35+
.ropeproject/
36+
tests/
37+
test_*.py
38+
39+
# IDE and editor files
40+
.vscode/
41+
.idea/
42+
*.swp
43+
*.swo
44+
*~
45+
.DS_Store
46+
47+
# Docker files (don't need these inside the image)
48+
Dockerfile
49+
Dockerfile.*
50+
docker-compose.yml
51+
docker-compose.*.yml
52+
.dockerignore
53+
54+
# Build artifacts
55+
dist/
56+
build/
57+
*.egg-info/
58+
*.egg
59+
.eggs/
60+
61+
# Logs
62+
*.log
63+
logs/
64+
65+
# OS files
66+
.DS_Store
67+
Thumbs.db
68+
Desktop.ini
69+
70+
# Temporary files
71+
*.tmp
72+
*.temp
73+
tmp/
74+
temp/
75+
76+
# Coverage reports
77+
htmlcov/
78+
.coverage
79+
.coverage.*
80+
coverage.xml
81+
*.cover
82+
.hypothesis/

.env.example

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Environment Variables Template for Survey Dashboard
2+
# Copy this file to .env and update with your actual values
3+
# Command: cp .env.example .env
4+
5+
# ============================================================================
6+
# Docker Compose Configuration
7+
# ============================================================================
8+
9+
# Project name - used as prefix for container names
10+
# Example: survey-dashboard_nginx_1, survey-dashboard_dashboard_1
11+
COMPOSE_PROJECT_NAME=survey-dashboard
12+
13+
# ============================================================================
14+
# Application Configuration
15+
# ============================================================================
16+
17+
# Port the Panel application runs on inside the container
18+
# Default: 5006 (Panel's default port)
19+
APP_PORT=
20+
21+
# ============================================================================
22+
# Nginx Configuration
23+
# ============================================================================
24+
25+
# Port nginx exposes on the host machine
26+
# Default: 80 (standard HTTP port), 443 (standard HTTPS port)
27+
# Change to 8080/8443 if 80/443 are already in use
28+
NGINX_PORT=
29+
30+
# Your domain name
31+
# IMPORTANT: For HTTPS to work, this MUST be a real domain that points to your server
32+
# In development: Use 'localhost' (HTTPS won't work, only HTTP)
33+
# In production: Use your actual domain (e.g., survey.example.com)
34+
# This domain is used by:
35+
# - nginx-proxy: Routes traffic from this domain to the dashboard
36+
# - acme-companion: Requests SSL certificate for this domain from Let's Encrypt
37+
HOST=
38+
39+
# Path on the domain where the dashboard is accessible
40+
# If set, the dashboard will ONLY be accessible at this specific path
41+
# Examples:
42+
# - VIRTUAL_PATH=/survey-dashboard → https://your-domain.com/survey-dashboard
43+
# - VIRTUAL_PATH=/dashboard → https://your-domain.com/dashboard
44+
# - Leave empty for root path → https://your-domain.com/
45+
# IMPORTANT: Must start with / (forward slash)
46+
# All other paths on this domain will return 404
47+
VIRTUAL_PATH=
48+
49+
# ============================================================================
50+
# SSL/HTTPS Configuration (Let's Encrypt)
51+
# ============================================================================
52+
53+
# Your email address for Let's Encrypt certificate registration
54+
# REQUIRED for production HTTPS deployment
55+
# Let's Encrypt uses this email to:
56+
# - Send certificate expiration warnings (if auto-renewal fails)
57+
# - Send security notices about your certificates
58+
# - Contact you about your Let's Encrypt account
59+
# Example: admin@example.com or your-email@gmail.com
60+
LETSENCRYPT_EMAIL=
61+
62+
# ============================================================================
63+
# Python Configuration
64+
# ============================================================================
65+
66+
# Keep Python output unbuffered for better logging
67+
PYTHONUNBUFFERED=1
68+
69+
# ============================================================================
70+
# NOTES
71+
# ============================================================================
72+
# - Never commit the .env file to version control
73+
# - .env is listed in .gitignore to prevent accidental commits
74+
# - Update .env.example when adding new environment variables
75+
# - In production, consider using Docker secrets or a secrets manager

.env.local.example

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Environment Variables for LOCAL TESTING
2+
# Copy this file to .env.local for local Docker testing
3+
# Command: cp .env.local.example .env.local
4+
5+
# IMPORTANT: This is for LOCAL TESTING ONLY
6+
# For production deployment, use .env.example instead
7+
8+
# ============================================================================
9+
# Docker Compose Configuration
10+
# ============================================================================
11+
12+
# Project name - use different name to avoid conflicts with production
13+
COMPOSE_PROJECT_NAME=survey-dashboard-local
14+
15+
# ============================================================================
16+
# Application Configuration
17+
# ============================================================================
18+
19+
# Port the Panel application runs on inside the container
20+
APP_PORT=5006
21+
22+
# ============================================================================
23+
# Nginx Configuration
24+
# ============================================================================
25+
26+
# Port nginx exposes on the host machine
27+
# Default: 80 for HTTP
28+
# If port 80 is in use, change to 8080 or another available port
29+
NGINX_PORT=80
30+
31+
# Domain name - use localhost for local testing
32+
# IMPORTANT: HTTPS will NOT work with localhost (Let's Encrypt requires real domains)
33+
# You can only test HTTP locally
34+
HOST=localhost
35+
36+
# Path on the domain where the dashboard is accessible
37+
# Test the same path you'll use in production
38+
# Example: VIRTUAL_PATH=/2021community
39+
# Leave empty to serve from root: http://localhost/
40+
VIRTUAL_PATH=/2021community
41+
42+
# ============================================================================
43+
# SSL/HTTPS Configuration (Let's Encrypt)
44+
# ============================================================================
45+
46+
# Dummy email for local testing
47+
# This is not used when HOST=localhost (Let's Encrypt won't run)
48+
# In production, use a real email address
49+
LETSENCRYPT_EMAIL=test@localhost
50+
51+
# ============================================================================
52+
# Python Configuration
53+
# ============================================================================
54+
55+
# Keep Python output unbuffered for better logging
56+
PYTHONUNBUFFERED=1
57+
58+
# ============================================================================
59+
# LOCAL TESTING NOTES
60+
# ============================================================================
61+
62+
# What works locally:
63+
# ✅ Docker build and container startup
64+
# ✅ HTTP access at http://localhost/2021community
65+
# ✅ Path routing and restrictions
66+
# ✅ WebSocket connections
67+
# ✅ Dashboard interactivity
68+
# ✅ Container restarts and rebuilds
69+
70+
# What does NOT work locally:
71+
# ❌ HTTPS/SSL certificates (requires real domain)
72+
# ❌ Let's Encrypt certificate acquisition (localhost is not valid)
73+
# ❌ External access from internet (only local machine)
74+
75+
# How to test:
76+
# 1. Copy this file: cp .env.local.example .env.local
77+
# 2. Start containers: docker-compose --env-file .env.local up -d --build
78+
# 3. Test in browser: http://localhost/2021community
79+
# 4. Follow LOCAL_TESTING.md for detailed testing scenarios
80+
81+
# Cleanup after testing:
82+
# docker-compose --env-file .env.local down
83+
# docker-compose --env-file .env.local down -v # Remove volumes too

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# custom
2-
*.csv
2+
responses_cleaned_mapped_to_publish.csv
3+
#survey_dashboard/hmc_layout/static/en_files/fonts/
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/
@@ -106,13 +107,17 @@ celerybeat.pid
106107

107108
# Environments
108109
.env
110+
.env.local
109111
.venv
110112
env/
111113
venv/
112114
ENV/
113115
env.bak/
114116
venv.bak/
115117

118+
# Deployment files (may contain sensitive server info)
119+
DEPLOYMENT.md
120+
116121
# Spyder project settings
117122
.spyderproject
118123
.spyproject
@@ -130,3 +135,7 @@ dmypy.json
130135

131136
# Pyre type checker
132137
.pyre/
138+
139+
140+
# Claude
141+
.claude/

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Multi-stage build for survey dashboard
2+
# Stage 1: Builder - installs dependencies
3+
FROM python:3.12-slim as builder
4+
5+
# Install poetry
6+
RUN pip install --no-cache-dir poetry==1.8.2
7+
8+
WORKDIR /app
9+
10+
# Copy dependency files first (for Docker layer caching)
11+
COPY pyproject.toml poetry.lock README.md ./
12+
13+
# Configure poetry to not create virtual environment (we're in a container)
14+
RUN poetry config virtualenvs.create false
15+
16+
# Install dependencies (excluding dev dependencies)
17+
# --no-root: Don't install the project itself, only dependencies
18+
RUN poetry install --only main --no-root --no-interaction --no-ansi
19+
20+
# Stage 2: Final runtime image
21+
FROM python:3.12-slim
22+
23+
WORKDIR /app
24+
25+
# Copy installed packages from builder stage
26+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
27+
COPY --from=builder /usr/local/bin /usr/local/bin
28+
29+
# Copy application code
30+
COPY survey_dashboard/ ./survey_dashboard/
31+
COPY pyproject.toml ./
32+
33+
# Create a non-root user for security
34+
RUN useradd -m -u 1000 appuser && \
35+
chown -R appuser:appuser /app
36+
37+
USER appuser
38+
39+
# Expose the application port
40+
EXPOSE 5006
41+
42+
# Run the application in production mode
43+
# Use python -m to run the module directly since we installed with --no-root
44+
CMD ["python", "-m", "survey_dashboard.scripts", "--production", "--host", "0.0.0.0", "--port", "5006"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Materials Data Science and Informatics
3+
Copyright (c) 2025 Materials Data Science and Informatics
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)