This commit is contained in:
pika 2025-03-31 17:27:03 +02:00
parent 3036042416
commit da0a156ada
5 changed files with 159 additions and 13 deletions

View file

@ -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/

54
.src/build.sh Executable file
View file

@ -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

View file

@ -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"]
USER appuser
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Run gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "wsgi:app"]

View file

@ -5,7 +5,7 @@ services:
build:
context: .
dockerfile: Dockerfile
image: homedocs:latest
# image: homedocs:latest
ports:
- "8000:8000"
volumes:

View file

@ -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