Téléverser les fichiers vers "Web"

This commit is contained in:
Emeline Nerot 2025-03-19 09:03:00 +00:00
parent 35de0f98ca
commit 08358252fa
4 changed files with 40 additions and 0 deletions

10
Web/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3.9
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

BIN
Web/Dockerfile~ Normal file

Binary file not shown.

28
Web/app.py Normal file
View File

@ -0,0 +1,28 @@
from flask import Flask
import os
import psycopg2
app = Flask(__name__)
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://user:password@db:5432/mydatabase")
@app.route('/')
def home():
return "This is my application!"
@app.route('/db-test')
def db_test():
try:
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
cur.execute("SELECT 'Database connection successful!'")
message = cur.fetchone()[0]
cur.close()
conn.close()
return message
except Exception as e:
return f"Database connection failed: {e}"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

2
Web/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flask
psycopg2