Compare commits

..

No commits in common. "b375760aab55fd56bc7ce86567b407ec7ea5249b" and "42860188c6411551069de7b0a676271678dc9a06" have entirely different histories.

7 changed files with 6 additions and 57 deletions

View File

@ -1,3 +0,0 @@
## Setup
Create the database schema `docker-compose exec webserver python src/makedb.py`

View File

@ -1,7 +1,7 @@
FROM postgres:11 FROM postgres:11
ENV POSTGRES_USER codepage ENV POSTGRES_USER flittr
ENV POSTGRES_PASSWORD codepage ENV POSTGRES_PASSWORD flittr
ENV POSTGRES_DB codepage ENV POSTGRES_DB flittr
ENV PGDATA /var/lib/postgresql/data/pgdata ENV PGDATA /var/lib/postgresql/data/pgdata
VOLUME /var/lib/postgresql/data/pgdata VOLUME /var/lib/postgresql/data/pgdata

View File

@ -1,6 +1,4 @@
FROM python:3 FROM python:3
RUN pip install -U Flask RUN pip install -U Flask
RUN pip install psycopg2 ADD hello.py ./
WORKDIR / CMD ["python", "hello.py"]
ADD ./src/ /src/
CMD ["python", "/src/webserver.py"]

View File

@ -1,12 +1,10 @@
from flask import Flask from flask import Flask
from database import getdb
app = Flask(__name__) app = Flask(__name__)
@app.route("/") @app.route("/")
def hello(): def hello():
with getdb() as db: return "Hello, world"
return "Hello, world"
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0') app.run(debug=True, host='0.0.0.0')

View File

@ -1,5 +0,0 @@
DB_NAME = "codepage"
DB_USER = "codepage"
DB_PASS = "codepage"
DB_HOST = "database"
DB_PORT = 5432

View File

@ -1,19 +0,0 @@
"""
Database handling code for the CodePage
"""
import psycopg2
import config
DATABASE = None
def getdb():
global DATABASE
if DATABASE is None:
DATABASE = psycopg2.connect(
dbname=config.DB_NAME,
user=config.DB_USER,
password=config.DB_PASS,
host=config.DB_HOST,
port=config.DB_PORT)
return DATABASE.cursor()

View File

@ -1,20 +0,0 @@
from database import getdb
with getdb() as db:
# Initial database schema
db.execute("""
CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY NOT NULL,
dispname TEXT NOT NULL,
pwhash TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS codes (
id INT PRIMARY KEY NOT NULL,
username INT NOT NULL,
language TEXT NOT NULL,
title TEXT NOT NULL,
contents TEXT NOT NULL,
FOREIGN KEY (username) REFERENCES users(id)
);
""")