Add database connection handling with dummy usage
This commit is contained in:
parent
fa5268f608
commit
20f219793d
|
@ -1,7 +1,7 @@
|
|||
FROM postgres:11
|
||||
ENV POSTGRES_USER flittr
|
||||
ENV POSTGRES_PASSWORD flittr
|
||||
ENV POSTGRES_DB flittr
|
||||
ENV POSTGRES_USER codepage
|
||||
ENV POSTGRES_PASSWORD codepage
|
||||
ENV POSTGRES_DB codepage
|
||||
ENV PGDATA /var/lib/postgresql/data/pgdata
|
||||
VOLUME /var/lib/postgresql/data/pgdata
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
FROM python:3
|
||||
RUN pip install -U Flask
|
||||
RUN pip install psycopg2
|
||||
WORKDIR /
|
||||
ADD ./src/ /src/
|
||||
CMD ["python", "/src/webserver.py"]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
DB_NAME = "codepage"
|
||||
DB_USER = "codepage"
|
||||
DB_PASS = "codepage"
|
||||
DB_HOST = "database"
|
||||
DB_PORT = 5432
|
|
@ -0,0 +1,15 @@
|
|||
"""
|
||||
Database handling code for the CodePage
|
||||
"""
|
||||
import psycopg2
|
||||
import config
|
||||
|
||||
def getdb():
|
||||
return psycopg2.connect(
|
||||
dbname=config.DB_NAME,
|
||||
user=config.DB_USER,
|
||||
password=config.DB_PASS,
|
||||
host=config.DB_HOST,
|
||||
port=config.DB_PORT
|
||||
)
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
from flask import Flask
|
||||
from database import getdb
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return "Hello, world"
|
||||
with getdb() as db:
|
||||
return "Hello, world"
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
|
|
Loading…
Reference in New Issue