Skip to content

Commit fa67835

Browse files
committed
fresh dockerized set up of the app
1 parent f326bbc commit fa67835

7 files changed

Lines changed: 791 additions & 8 deletions

File tree

.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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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=5006
20+
21+
# ============================================================================
22+
# Nginx Configuration
23+
# ============================================================================
24+
25+
# Port nginx exposes on the host machine
26+
# Default: 80 (standard HTTP port)
27+
# Change to 8080 or another port if 80 is already in use
28+
NGINX_PORT=80
29+
30+
# Your domain name
31+
# In development: Use 'localhost' or your IP address
32+
# In production: Use your actual domain (e.g., survey.example.com)
33+
# This is used in nginx server_name directive
34+
HOST=localhost
35+
36+
# ============================================================================
37+
# Optional: SSL/HTTPS Configuration (for future use)
38+
# ============================================================================
39+
40+
# Uncomment and configure these if you want to enable HTTPS
41+
# ENABLE_SSL=false
42+
# SSL_CERT_PATH=/path/to/cert.pem
43+
# SSL_KEY_PATH=/path/to/key.pem
44+
45+
# ============================================================================
46+
# Python Configuration
47+
# ============================================================================
48+
49+
# Keep Python output unbuffered for better logging
50+
PYTHONUNBUFFERED=1
51+
52+
# ============================================================================
53+
# NOTES
54+
# ============================================================================
55+
# - Never commit the .env file to version control
56+
# - .env is listed in .gitignore to prevent accidental commits
57+
# - Update .env.example when adding new environment variables
58+
# - In production, consider using Docker secrets or a secrets manager

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 using the updated script
43+
CMD ["survey-dashboard", "--production", "--host", "0.0.0.0", "--port", "5006"]

docker-compose.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Docker Compose configuration for Survey Dashboard
2+
# Orchestrates nginx reverse proxy and Panel application containers
3+
4+
version: '3.8'
5+
6+
services:
7+
# Panel application container
8+
dashboard:
9+
build: .
10+
# Builds from Dockerfile in current directory
11+
# Uses multi-stage build to create optimized production image
12+
13+
expose:
14+
- "5006"
15+
# Exposes port 5006 to other containers (not to host machine)
16+
# Only accessible within Docker network - nginx can reach it
17+
18+
restart: unless-stopped
19+
# Automatically restart if container crashes
20+
# Persists across system reboots unless manually stopped
21+
22+
environment:
23+
- PYTHONUNBUFFERED=1
24+
# Ensures Python output is sent directly to logs (not buffered)
25+
# Makes 'docker-compose logs' show real-time output
26+
27+
# Uncomment to mount local code for development
28+
# volumes:
29+
# - ./survey_dashboard:/app/survey_dashboard
30+
31+
# Nginx reverse proxy container
32+
nginx:
33+
image: nginx:latest
34+
# Uses official nginx image from Docker Hub
35+
# No custom build needed - just mount our config
36+
37+
ports:
38+
- "80:80"
39+
# Maps host port 80 to container port 80
40+
# This is the ONLY port exposed to the internet
41+
# Users access dashboard via http://yourdomain.com (port 80)
42+
43+
volumes:
44+
- ./nginx/conf.d:/etc/nginx/conf.d:ro
45+
# Mounts our nginx config into the container
46+
# :ro = read-only (nginx cannot modify our files)
47+
# Changes to config files are reflected immediately
48+
49+
depends_on:
50+
- dashboard
51+
# Ensures dashboard container starts before nginx
52+
# Nginx needs dashboard to be available for proxying
53+
54+
restart: unless-stopped
55+
# Same restart policy as dashboard
56+
57+
networks:
58+
default:
59+
# Docker Compose automatically creates a default network
60+
# Both containers join this network and can communicate
61+
# Service names (dashboard, nginx) work as DNS hostnames

0 commit comments

Comments
 (0)