diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c650c4c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.gitignore +.git +__pycache__ diff --git a/config/Dockerfile b/Dockerfile similarity index 88% rename from config/Dockerfile rename to Dockerfile index d570dfa..b912a40 100644 --- a/config/Dockerfile +++ b/Dockerfile @@ -22,4 +22,4 @@ ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 # Run the application -CMD ["gunicorn", "-w", "4", "-b", ":8000", "app:create_app()"] \ No newline at end of file +CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "wsgi:app"] \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3224d17..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Yohei Nakajima - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..a861500 --- /dev/null +++ b/compose.yml @@ -0,0 +1,15 @@ +# version: '3' + +services: + app: + build: + context: . + dockerfile: Dockerfile + image: homedocs:latest + ports: + - "8000:8000" + volumes: + - ./instance:/app/instance # Persist SQLite database + environment: + - FLASK_ENV=${FLASK_ENV:-production} + restart: unless-stopped diff --git a/config/docker-compose.yml b/config/docker-compose.yml deleted file mode 100644 index c6c3024..0000000 --- a/config/docker-compose.yml +++ /dev/null @@ -1,53 +0,0 @@ -version: '3' - -services: - app: - build: - context: .. - dockerfile: config/Dockerfile - command: gunicorn -w 4 -b :8000 "app:create_app()" --access-logfile - --error-logfile - - volumes: - - ../app:/app/app - environment: - - FLASK_APP=app - - FLASK_ENV=production - - DATABASE_URL=postgresql://user:password@db:5432/app_db - - REDIS_URL=redis://redis:6379/0 - - SECRET_KEY=${SECRET_KEY:-default_secret_key_change_in_production} - depends_on: - - db - - redis - restart: unless-stopped - - nginx: - image: nginx:1.25 - ports: - - "80:80" - - "443:443" - volumes: - - ./nginx/nginx.conf:/etc/nginx/nginx.conf - - ./nginx/conf.d:/etc/nginx/conf.d - - ./nginx/ssl:/etc/nginx/ssl - depends_on: - - app - restart: unless-stopped - - db: - image: postgres:15 - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: password - POSTGRES_DB: app_db - volumes: - - pg_data:/var/lib/postgresql/data - restart: unless-stopped - - redis: - image: redis:7 - volumes: - - redis_data:/data - restart: unless-stopped - -volumes: - pg_data: - redis_data: diff --git a/wsgi.py b/wsgi.py index e95d7ab..e4ee86e 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,13 +1,17 @@ import os +import secrets from app import create_app -# Set the environment variable for database URL if needed -# os.environ['DATABASE_URL'] = 'your_production_database_url' +# Get Flask environment +flask_env = os.environ.get("FLASK_ENV", "production") -# Create a production application -app = create_app("production") +# Create the application +app = create_app(flask_env) + +# Also provide 'application' for WSGI servers that look for this name +application = app if __name__ == "__main__": - # This is only used for development - # In production, a WSGI server would import this file - app.run(host="0.0.0.0", port=5000) + # Only for development + debug = flask_env != "production" + app.run(host="0.0.0.0", port=8000, debug=debug)