Created docker environment for API

This commit is contained in:
Marcin-Ramotowski 2023-12-27 10:50:38 +00:00
parent 6846536df8
commit eb8201d4a1
8 changed files with 36 additions and 19 deletions

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM python:3.11.7-slim-bookworm
WORKDIR /app
COPY src .
RUN pip install -r requirements.txt
CMD python3 app.py

19
app.py
View File

@ -1,19 +0,0 @@
from flask import Flask
from models import db
from user_views import user_bp
from task_views import task_bp
from dotenv import load_dotenv
import os
load_dotenv()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.register_blueprint(user_bp)
app.register_blueprint(task_bp)
db.init_app(app)
with app.app_context():
db.create_all()

13
docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: '3.7'
services:
web:
container_name: todo-api
hostname: todo-api
build: .
env_file:
- src/.env
ports:
- "5000:5000"
volumes:
- ./src/test.db:/app/test.db

18
src/app.py Normal file
View File

@ -0,0 +1,18 @@
from flask import Flask
from models import db
from user_views import user_bp
from task_views import task_bp
from dotenv import load_dotenv
import os
if __name__ == "__main__":
load_dotenv()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.register_blueprint(user_bp)
app.register_blueprint(task_bp)
db.init_app(app)
with app.app_context():
db.create_all()
app.run(debug=True, host='0.0.0.0')