diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc8cff6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Pull the latest stable Python3 Deblian slim image +FROM python:3-slim-buster + +# Install OS level required packages +RUN apt update && apt install -y bash + +# Install pipenv +RUN pip install pipenv + +# Create new user and group and set them +# This is to keep us from running as "root" inside the container +# especially since our mounted volutes would then be set to root as the owner +RUN useradd -Ums /bin/bash -u 991 uwume + +# Set the current working directory +# the subdirectories and files here should be mounted using the volume option +# when executing docker run or by specifying volumes in docker-compose.yml +WORKDIR /usr/src/uwume + +# Copy the __init__.py and views.py files in order to run +COPY views.py views.py +COPY __init__.py __init__.py + +RUN chown -R uwume:uwume /usr/src/uwume +USER uwume + +# Copy Pipfile from local and install packages +COPY Pipfile Pipfile +RUN pipenv install + + +# Set the entrypoint +ENTRYPOINT [ "python", "-m", "pipenv", "run", "flask", "run" ] \ No newline at end of file diff --git a/__init__.py b/__init__.py index e69de29..ec1f986 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1,15 @@ +from flask import Flask +from flask_login import LoginManager +from os import urandom +app = Flask(__name__) +app.secret_key = urandom(12).hex() +''' +login_manager = LoginManager() +login_manager.init_app(app) + +@login_manager.user_loader +def load_user(user_id): + return User.get(user_id) +''' + +from . import views \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ef57041 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,22 @@ +--- +version: '3' +services: + uwume: + build: + context: . + dockerfile: Dockerfile + image: uwume:latest + user: uwume + container_name: uwu_me + environment: + - FLASK_APP=/usr/src/uwume/ + - FLASK_ENV=development + - FLASK_RUN_HOST=0.0.0.0 + - FLASK_RUN_PORT=4444 + volumes: + - ./assets:/usr/src/uwume/assets + - ./lib:/usr/src/uwume/lib + - ./static:/usr/src/uwume/static + - ./templates:/usr/src/uwume/templates + ports: + - 4444:4444 \ No newline at end of file diff --git a/setup_app.sh b/setup_app.sh deleted file mode 100644 index 10fdfd4..0000000 --- a/setup_app.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -export FLASK_APP=app.py -export FLASK_ENV=development \ No newline at end of file diff --git a/start_app.sh b/start_app.sh new file mode 100755 index 0000000..de7f3b3 --- /dev/null +++ b/start_app.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# You should use this if you want to run on bare-metal and not in a container. + +# These environment variables should be echoed in the docker-compose.yml +export FLASK_APP=$(pwd) +export FLASK_ENV=development +export FLASK_RUN_HOST=0.0.0.0 +export FLASK_RUN_PORT=4444 + +# Actually run the flask app +pipenv run flask run \ No newline at end of file diff --git a/app.py b/views.py similarity index 74% rename from app.py rename to views.py index e3f5110..4981a8d 100644 --- a/app.py +++ b/views.py @@ -1,19 +1,9 @@ -from .lib.helpers import get_static_paths, get_content_text +try: + from .lib.helpers import get_static_paths, get_content_text +except: + from lib.helpers import get_static_paths, get_content_text +from . import app from flask import Flask, render_template, redirect, url_for, request -from flask_login import LoginManager -app = Flask(__name__) -''' -login_manager = LoginManager() -login_manager.init_app(app) - -# Secret key -app.secret_key = #Don't commit this. - - -@login_manager.user_loader -def load_user(user_id): - return User.get(user_id) -''' @app.route('/home', methods=['GET'])