diff --git a/.dockerignore b/.dockerignore index c650c4c..1518c81 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,86 @@ -.gitignore -.git -__pycache__ +tests/__pycache__/conftest.cpython-313-pytest-8.3.5.pyc +scripts/__pycache__/check_routes.cpython-313-pytest-8.3.5.pyc + +# Python bytecode +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +dist/ +build/ +*.egg-info/ + +# Virtual environments +venv/ +env/ +ENV/ +.env/ +.venv/ + +# Flask stuff +instance/ +.webassets-cache +flask_session/ + +# SQLite database files +*.sqlite +*.sqlite3 +*.db + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Jupyter Notebook +.ipynb_checkpoints + +# VS Code +.vscode/ +*.code-workspace + +# PyCharm +.idea/ +*.iml +*.iws +*.ipr + +# Environment variables +.env +.env.local +.env.development +.env.test +.env.production + +# Logs +logs/ +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# System files +.DS_Store +Thumbs.db +ehthumbs.db +Desktop.ini + +# User-specific files +*.swp +*.swo +*~ + +# Local development settings +local_settings.py + +# Media and static files (if collected locally) +/media/ +/static/collected/ diff --git a/.src/build.sh b/.src/build.sh new file mode 100755 index 0000000..47d32d9 --- /dev/null +++ b/.src/build.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +IMAGE_NAME=homedocs +TAG=latest + +# ─< Check if the given command exists silently >───────────────────────────────────────── +command_exists() { + command -v "$@" >/dev/null 2>&1 +} + +# ─< ANSI color codes >─────────────────────────────────────────────────────────────────── +RED='\033[0;31m' +CYAN='\033[0;36m' +YELLOW='\033[0;33m' +LIGHT_GREEN='\033[0;92m' +BOLD='\033[1m' +NC='\033[0m' # No Color + +echo_error() { + printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2 +} + +echo_info() { + printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1" +} + +echo_warning() { + printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1" +} + +echo_note() { + printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1" +} + +checks() { + if ! command_exists docker; then + echo_error "Docker command does not exist! Please install docker to continue building!" + return 1 + fi + + if [[ ! -e ./Dockerfile ]]; then + echo_error "There is no Dockerfile in the current directory.." + echo_error "Be sure to execute the script in the project path like: ./src/build.sh" + return 1 + fi +} + +build() { + docker build -t "${IMAGE_NAME}:${TAG}" . +} + +if checks; then + build +fi diff --git a/Dockerfile b/Dockerfile index b912a40..4117b9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,17 +9,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Install Python dependencies +# Copy requirements first for better caching COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt -RUN pip install gunicorn psycopg2-binary redis -# Copy application code +# Upgrade pip and install dependencies +RUN pip install --upgrade pip && \ + pip install -r requirements.txt + +# Copy the rest of the application COPY . . -# Set environment variables -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 +# Create a non-root user to run the app +RUN useradd -m appuser && \ + chown -R appuser:appuser /app -# Run the application -CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "wsgi:app"] \ No newline at end of file +USER appuser + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Run gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "wsgi:app"] diff --git a/compose.yml b/compose.yml index a861500..8441da6 100644 --- a/compose.yml +++ b/compose.yml @@ -5,7 +5,7 @@ services: build: context: . dockerfile: Dockerfile - image: homedocs:latest + # image: homedocs:latest ports: - "8000:8000" volumes: diff --git a/requirements.txt b/requirements.txt index e8eecb6..57354c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # Flask and core extensions Flask==2.3.3 flask-sqlalchemy==3.1.1 +flask-migrate==4.0.5 flask-login==0.6.3 flask-limiter==3.5.0 flask-bcrypt==1.0.1