diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31c98fb --- /dev/null +++ b/docker-compose.yml @@ -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" + diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 0000000..486a081 --- /dev/null +++ b/mysql/Dockerfile @@ -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 diff --git a/static/sql/init.sql b/mysql/sql/init.sql similarity index 76% rename from static/sql/init.sql rename to mysql/sql/init.sql index 2faa50a..06c3a45 100644 --- a/static/sql/init.sql +++ b/mysql/sql/init.sql @@ -1,7 +1,4 @@ -create database db; - -use db CREATE TABLE `db`.`users` ( `userid` INT NOT NULL, @@ -10,7 +7,7 @@ CREATE TABLE `db`.`users` ( PRIMARY KEY (`userid`)); 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'@'%'; diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..a90d2ef --- /dev/null +++ b/src/Dockerfile @@ -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"] diff --git a/src/app/main.py b/src/app/main.py new file mode 100644 index 0000000..636355e --- /dev/null +++ b/src/app/main.py @@ -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() diff --git a/requirements.txt b/src/app/requirements.txt similarity index 97% rename from requirements.txt rename to src/app/requirements.txt index 4695e76..c8ba3f5 100644 --- a/requirements.txt +++ b/src/app/requirements.txt @@ -1,3 +1,2 @@ web.py==0.40 mysql-connector==2.2.9 - diff --git a/static/images/friends.jpeg b/src/app/static/friends.jpeg similarity index 100% rename from static/images/friends.jpeg rename to src/app/static/friends.jpeg diff --git a/src/app/static/stylesheet.css b/src/app/static/stylesheet.css new file mode 100644 index 0000000..3704e43 --- /dev/null +++ b/src/app/static/stylesheet.css @@ -0,0 +1,3 @@ +body { + background-color: gray +} \ No newline at end of file diff --git a/src/app/templates/index.html b/src/app/templates/index.html new file mode 100644 index 0000000..bd2742a --- /dev/null +++ b/src/app/templates/index.html @@ -0,0 +1,24 @@ +$def with (login_form) + +
+
+
+