Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9ab6d3b
Normalize line endings to LF
mano8 Apr 8, 2025
13b5d16
feat: add .gitattributes to enforce LF line endings for shell scripts
mano8 Apr 9, 2025
6851286
feat: rename pre-start script for service initialization with retry l…
mano8 Apr 9, 2025
65d690b
feat: improve error handling in pre_start script with exit codes
mano8 Apr 9, 2025
9167e44
feat: add paths.py utility for dotenv file discovery
mano8 Apr 9, 2025
722a009
fix: reorder docstring and import statement in database.py
mano8 Apr 9, 2025
0a692df
feat: add ValidationConstants class with regex patterns for configura…
mano8 Apr 10, 2025
1d4ad67
feat: enhance configuration settings with CORS validation and secure …
mano8 Apr 10, 2025
496a171
fix: ensure newline at end of file in config.py
mano8 Apr 10, 2025
3e3475a
feat: add wait_for_db.sh script for MySQL database readiness check
mano8 Apr 10, 2025
5923bd2
feat: add docker_start.sh script for initializing database and starti…
mano8 Apr 10, 2025
0ca32ec
feat: add .dockerignore to exclude Dockerfile and alembic versions fr…
mano8 Apr 10, 2025
16220e4
feat: add requirements-docker-dev.txt for Docker development dependen…
mano8 Apr 10, 2025
320ea34
feat: add Dockerfile for setting up FastAPI environment with MySQL su…
mano8 Apr 10, 2025
d196e5f
fix: improve logging message in wait_for_db.sh to include database ho…
mano8 Apr 10, 2025
1043a47
refactor: update CORS handling in settings and improve BACKEND_CORS_O…
mano8 Apr 10, 2025
3fcdadd
refactor: streamline CORS middleware configuration by using settings …
mano8 Apr 10, 2025
27fe10b
refactor: remove pip upgrade command and fix script naming in Dockerfile
mano8 Apr 10, 2025
3fbc9d3
refactor: update Vite server configuration for Docker compatibility
mano8 Apr 10, 2025
edb7c76
feat: add .dockerignore to exclude node_modules and Dockerfile from b…
mano8 Apr 10, 2025
30bbad9
feat: add Dockerfile for Vite development environment setup
mano8 Apr 10, 2025
08853a4
feat: add Docker Compose configuration and environment setup for deve…
mano8 Apr 10, 2025
395eef2
feat: add example environment configuration for local development
mano8 Apr 10, 2025
df7ccf9
feat: update .gitignore to include records and alembic version files
mano8 Apr 10, 2025
aeb812c
refactor: improve CORS origin parsing and validation error messages
mano8 Apr 10, 2025
45669c3
fix: retrieve superuser password securely using get_secret_value()
mano8 Apr 10, 2025
15ad93b
fix: retrieve JWT token payload securely using get_secret_value()
mano8 Apr 10, 2025
0fc191d
fix: retrieve secret key securely using get_secret_value() in JWT tok…
mano8 Apr 10, 2025
ad25274
docs: update .example_env with usage instructions for environment var…
mano8 Apr 10, 2025
930740c
feat: add .example_env_docker for backend environment variable setup
mano8 Apr 10, 2025
9e28181
feat: add .example_env for development environment configuration
mano8 Apr 10, 2025
9326067
feat: add pymysql dependency to requirements for database support
mano8 Apr 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ celerybeat.pid
*.sage.py

# Environments
.env
.env*
.venv
env/
venv/
Expand Down Expand Up @@ -162,8 +162,10 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

dev/
/dev/*
.vscode/settings.json

*/node_modules/*
records
records

/backend/alembic/versions/*.py
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
/alembic/versions/*
33 changes: 13 additions & 20 deletions .example_env → backend/.example_env
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# project envs
# This file is used to set up the environment variables for the backend
# This file should be copied to .env and edited with the correct values

# Domain
# This would be set to the production domain with an env var on deployment
# used by Traefik to transmit traffic and aqcuire TLS certificates
DOMAIN="localhost"
# To test the local Traefik config
# DOMAIN=localhost.tiangolo.com

# Used by the backend to generate links in emails to the frontend
FRONTEND_HOST="http://localhost:5173"
# In staging and production, set this env var to the frontend host, e.g.
# FRONTEND_HOST=https://dashboard.example.com

# Environment: local, staging, production
ENVIRONMENT="local"

API_V1_STR="/api/v1"
PROJECT_NAME="EmonTools"
STACK_NAME="full-stack-emontools-project"

Expand All @@ -22,24 +20,19 @@ DATA_BASE_PATH="/opt/emon_tools/data"
STATIC_BASE_PATH="/opt/emon_tools/static"

# Backend
# Used by the backend to generate links in emails to the frontend
FRONTEND_HOST="http://localhost:5173"
# In staging and production, set this env var to the frontend host, e.g.
# FRONTEND_HOST=https://dashboard.example.com
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173"
SECRET_KEY=
FIRST_SUPERUSER=admin@example.com

SECRET_KEY=changethis
FIRST_SUPERUSER=changethis
FIRST_SUPERUSER_PASSWORD=changethis

# Mysql
MYSQL_SERVER="127.0.0.1"
MYSQL_HOST="127.0.0.1"
MYSQL_PORT=3306
MYSQL_DB="app"
MYSQL_DB="emontools"
MYSQL_USER="emontools"
MYSQL_PASSWORD=changethis

# EmonCms envs
# local emoncms instance
EMONCMS_URL="http://127.0.0.1:8080"
# emoncms apikey
API_KEY=changethis
# local phpfina paths
EMON_FINA_PATH="/var/lib/phpfina"
# phpfina archives directory
ARCHIVE_FINA_PATH="./datas"
38 changes: 38 additions & 0 deletions backend/.example_env_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is used to set up the environment variables for the backend
# This file should be copied to .env.docker and edited with the correct values

# Domain
# This would be set to the production domain with an env var on deployment
# used by Traefik to transmit traffic and aqcuire TLS certificates
DOMAIN="localhost"
# To test the local Traefik config
# DOMAIN=localhost.tiangolo.com

# Environment: local, staging, production
ENVIRONMENT="local"

API_V1_STR="/api/v1"
PROJECT_NAME="EmonTools"
STACK_NAME="full-stack-emontools-project"

# Data Path
DATA_BASE_PATH="/opt/emon_tools/data"
STATIC_BASE_PATH="/opt/emon_tools/static"

# Backend
# Used by the backend to generate links in emails to the frontend
FRONTEND_HOST="http://localhost:5173"
# In staging and production, set this env var to the frontend host, e.g.
# FRONTEND_HOST=https://dashboard.example.com
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173"

SECRET_KEY=changethis
FIRST_SUPERUSER=changethis
FIRST_SUPERUSER_PASSWORD=changethis

# Mysql
MYSQL_HOST="127.0.0.1"
MYSQL_PORT=3306
MYSQL_DB="emontools"
MYSQL_USER="emontools"
MYSQL_PASSWORD=changethis
65 changes: 65 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Use Python 3.11 slim base image
FROM python:3.11-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
# Add the local user's bin directory to PATH
PATH="/home/appuser/.local/bin:$PATH"

# Create a non-root user and group
RUN groupadd --gid 1000 appuser && \
useradd --uid 1000 --gid appuser --create-home appuser

# Set working directory
WORKDIR /opt/emon_tools

# Install build dependencies if needed (e.g., for any compiled packages)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
dos2unix \
default-mysql-client \
python3-dev \
default-libmysqlclient-dev \
build-essential \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements and install them as the non-root user
COPY --chown=appuser:appuser requirements-docker-dev.txt .

# Create the datas and static directories for storing data
RUN mkdir -p /opt/emon_tools/datas /opt/emon_tools/static /opt/emon_tools/backend \
&& chown -R appuser:appuser /opt/emon_tools/datas /opt/emon_tools/static /opt/emon_tools/backend

# Switch to the non-root user
USER appuser

# Install Python dependencies
# Use --no-cache-dir to avoid caching the packages in the image
# Use --user to install packages in the user's home directory
RUN pip install --no-cache-dir --user --upgrade pip && \
pip install --no-cache-dir --user -r requirements-docker-dev.txt

# Copy the backend source code
COPY --chown=appuser:appuser . ./backend

# Replace env file with the one for Docker
COPY --chown=appuser:appuser .env.docker ./backend/.env

RUN dos2unix /opt/emon_tools/backend/scripts/docker_start.sh
RUN dos2unix /opt/emon_tools/backend/scripts/pre_start.sh
RUN dos2unix /opt/emon_tools/backend/scripts/wait_for_db.sh

# Ensure scripts have execution permission
RUN chmod +x /opt/emon_tools/backend/scripts/docker_start.sh \
&& chmod +x /opt/emon_tools/backend/scripts/pre_start.sh \
&& chmod +x /opt/emon_tools/backend/scripts/wait_for_db.sh

# Set the PYTHONPATH to ensure the backend module is found
ENV PYTHONPATH=/opt/emon_tools

# Expose FastAPI port (use 8000)
EXPOSE 8000

# Use the entrypoint script as CMD, which will run migrations and then launch uvicorn
CMD ["./backend/scripts/docker_start.sh"]
2 changes: 1 addition & 1 deletion backend/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[alembic]
# path to migration scripts
# Use forward slashes (/) also on windows to provide an os agnostic path
script_location = ./emon_tools/fastapi/alembic
script_location = ./backend/alembic

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down
Loading