Created docker environment for API
This commit is contained in:
parent
6846536df8
commit
eb8201d4a1
5
Dockerfile
Normal file
5
Dockerfile
Normal 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
19
app.py
@ -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
13
docker-compose.yml
Normal 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
18
src/app.py
Normal 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')
|
Loading…
x
Reference in New Issue
Block a user