| @@ -0,0 +1,23 @@ | |||||
| version: "2" | |||||
| services: | |||||
| db: | |||||
| ports: | |||||
| - "3306:3306" | |||||
| build: | |||||
| context: ./mysql | |||||
| dockerfile: Dockerfile | |||||
| app: | |||||
| build: | |||||
| context: ./src | |||||
| dockerfile: Dockerfile | |||||
| links: | |||||
| - db | |||||
| ports: | |||||
| - "8080:8080" | |||||
| - "443:443" | |||||
| @@ -0,0 +1,10 @@ | |||||
| FROM mysql:5.7.15 | |||||
| MAINTAINER me | |||||
| ENV MYSQL_DATABASE=db \ | |||||
| MYSQL_ROOT_PASSWORD=root | |||||
| ADD /sql/init.sql /docker-entrypoint-initdb.d | |||||
| EXPOSE 3306 | |||||
| @@ -1,7 +1,4 @@ | |||||
| create database db; | |||||
| use db | |||||
| CREATE TABLE `db`.`users` ( | CREATE TABLE `db`.`users` ( | ||||
| `userid` INT NOT NULL, | `userid` INT NOT NULL, | ||||
| @@ -10,7 +7,7 @@ CREATE TABLE `db`.`users` ( | |||||
| PRIMARY KEY (`userid`)); | PRIMARY KEY (`userid`)); | ||||
| insert into users values (0, "admin", "password"); | insert into users values (0, "admin", "password"); | ||||
| insert into users values (0, "bernt", "inge"); | |||||
| insert into users values (1, "bernt", "inge"); | |||||
| GRANT ALL PRIVILEGES ON db.* TO 'root'@'%'; | GRANT ALL PRIVILEGES ON db.* TO 'root'@'%'; | ||||
| @@ -0,0 +1,21 @@ | |||||
| FROM tiangolo/uwsgi-nginx:python3.7 | |||||
| ENV LISTEN_PORT 8080 | |||||
| EXPOSE 8080 | |||||
| COPY ./app /app | |||||
| WORKDIR /app | |||||
| ENV PYTHONPATH=/app | |||||
| RUN pip install --no-cache-dir -r requirements.txt | |||||
| # Move the base entrypoint to reuse it | |||||
| RUN mv /entrypoint.sh /uwsgi-nginx-entrypoint.sh | |||||
| # Copy the entrypoint that will generate Nginx additional configs | |||||
| COPY entrypoint.sh /entrypoint.sh | |||||
| RUN chmod +x /entrypoint.sh | |||||
| ENTRYPOINT ["/entrypoint.sh"] | |||||
| CMD ["/start.sh"] | |||||
| @@ -0,0 +1,32 @@ | |||||
| import web | |||||
| from web import form | |||||
| urls = ( | |||||
| '/', 'index' | |||||
| ) | |||||
| # Initialize application using the web py framework | |||||
| app = web.application(urls, globals()) | |||||
| # Get html templates | |||||
| render = web.template.render('templates/') | |||||
| login_form = form.Form( | |||||
| form.Textbox("username", description="Username"), | |||||
| form.Password("password", description="Password"), | |||||
| form.Button("submit", type="submit", description="Login"), | |||||
| ) | |||||
| class index(): | |||||
| def GET(self): | |||||
| #friends = db.select('users') | |||||
| return render.index(login_form) | |||||
| if __name__ == "__main__": | |||||
| app.run() | |||||
| application = app.wsgifunc() | |||||
| @@ -1,3 +1,2 @@ | |||||
| web.py==0.40 | web.py==0.40 | ||||
| mysql-connector==2.2.9 | mysql-connector==2.2.9 | ||||
| @@ -0,0 +1,3 @@ | |||||
| body { | |||||
| background-color: gray | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| $def with (login_form) | |||||
| <head> | |||||
| <title>Friends</title> | |||||
| <meta charset="utf-8"> | |||||
| <link rel="stylesheet" type="text/css" href="static/stylesheet.css"> | |||||
| </head> | |||||
| <body> | |||||
| <h1>Friends</h1> | |||||
| <img src="static/friends.jpeg" alt="Friends"> | |||||
| <h3>Login, or become a friend!</h3> | |||||
| <form method="POST"> | |||||
| $:login_form.render() | |||||
| </form> | |||||
| </body> | |||||
| @@ -0,0 +1,27 @@ | |||||
| #! /usr/bin/env bash | |||||
| set -e | |||||
| /uwsgi-nginx-entrypoint.sh | |||||
| # Get the URL for static files from the environment variable | |||||
| USE_STATIC_URL=${STATIC_URL:-'/static'} | |||||
| # Get the absolute path of the static files from the environment variable | |||||
| USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} | |||||
| # Get the listen port for Nginx, default to 8080 | |||||
| USE_LISTEN_PORT=${LISTEN_PORT:-8080} | |||||
| content_server='server {\n' | |||||
| content_server=$content_server" listen ${USE_LISTEN_PORT};\n" | |||||
| content_server=$content_server' location / {\n' | |||||
| content_server=$content_server' include uwsgi_params;\n' | |||||
| content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' | |||||
| content_server=$content_server' }\n' | |||||
| content_server=$content_server" location $USE_STATIC_URL {\n" | |||||
| content_server=$content_server" alias $USE_STATIC_PATH;\n" | |||||
| content_server=$content_server' }\n' | |||||
| content_server=$content_server'}\n' | |||||
| # Save generated server /etc/nginx/conf.d/nginx.conf | |||||
| printf "$content_server" > /etc/nginx/conf.d/nginx.conf | |||||
| exec "$@" | |||||
| @@ -1,3 +0,0 @@ | |||||
| body { | |||||
| background-color: whitesmoke | |||||
| } | |||||
| @@ -1,64 +0,0 @@ | |||||
| import web | |||||
| from web import form | |||||
| # Turn of debug because sessions doesnt support it | |||||
| web.config.debug = False | |||||
| # Define routes | |||||
| urls = ( | |||||
| '/', 'application', | |||||
| "/logout", "logout", | |||||
| ) | |||||
| # Initialize application using the web py framework | |||||
| app = web.application(urls, globals()) | |||||
| # Enable sessions | |||||
| session = web.session.Session(app, web.session.DiskStore("sessions"), initializer={"username": None}) | |||||
| # Get html templates | |||||
| render = web.template.render('templates/') | |||||
| render._add_global(session, 'session') | |||||
| # Connect to database | |||||
| db = web.database( | |||||
| dbn="mysql", | |||||
| host='127.0.0.1', | |||||
| port=3306, | |||||
| user='root', | |||||
| #pw='password', | |||||
| db='db' | |||||
| ) | |||||
| class application(): | |||||
| login_form = form.Form( | |||||
| form.Textbox("username", description="Username"), | |||||
| form.Password("password", description="Password"), | |||||
| form.Button("submit", type="submit", description="Login"), | |||||
| ) | |||||
| def GET(self): | |||||
| friends = db.select('users') | |||||
| return render.index(self.login_form, friends) | |||||
| def POST(self): | |||||
| friends = db.select('users') | |||||
| data = web.input() | |||||
| print("name:", data.username) | |||||
| for row in friends: | |||||
| print(row) | |||||
| print(row.username) | |||||
| if data.username == row.username and data.password == row.password: | |||||
| friends = db.select('users') | |||||
| session.username = data.username | |||||
| return render.index(self.login_form, friends) | |||||
| class logout: | |||||
| def GET(self): | |||||
| session.kill() | |||||
| return "Logged out" | |||||
| if __name__ == "__main__": | |||||
| app.run() | |||||