From 264144ebcaa3c1c44e9913a3cb4790d94c71a13e Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Tue, 1 Jul 2025 11:22:56 +0200 Subject: [PATCH] Prepare for fly.io --- .dockerignore | 36 ++++++++++++++++++++++++++++++++++++ Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ app.py | 3 ++- fly.toml | 27 +++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..249982c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,36 @@ +.git +.gitignore +README.md +.env +.env.local +.env.development.local +.env.test.local +.env.production.local +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.DS_Store +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env +pip-log.txt +pip-delete-this-directory.txt +.tox +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.venv +.mypy_cache +.pytest_cache +.hypothesis +fly.toml +timetrack.db +*.db-journal +tests/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..69677e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM python:3.9-slim + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + FLASK_APP=app.py + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file first for better caching +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application +COPY . . + +# Create the SQLite database directory with proper permissions +RUN mkdir -p /app/instance && chmod 777 /app/instance + +# Expose the port the app runs on +EXPOSE 5000 + +# Run database migrations on startup +RUN python -c "from app import app, db; app.app_context().push(); db.create_all()" + +# Command to run the application +CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] \ No newline at end of file diff --git a/app.py b/app.py index f55fc40..9aa6a82 100644 --- a/app.py +++ b/app.py @@ -1840,4 +1840,5 @@ def download_team_hours_export(): return redirect(url_for('team_hours')) if __name__ == '__main__': - app.run(debug=True, port=5050) \ No newline at end of file + port = int(os.environ.get('PORT', 5000)) + app.run(debug=False, host='0.0.0.0', port=port) \ No newline at end of file diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..2e73adb --- /dev/null +++ b/fly.toml @@ -0,0 +1,27 @@ +app = "timetrack" +primary_region = "iad" + +[build] + +[env] + FLASK_APP = "app.py" + FLASK_ENV = "production" + +[http_service] + internal_port = 5000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + +[[mounts]] + source = "timetrack_data" + destination = "/app/instance" + +[processes] + app = "flask run --host=0.0.0.0" + +[[vm]] + cpu_kind = "shared" + cpus = 1 + memory_mb = 256 \ No newline at end of file