Added docker files, modified flask app start structure, modified startup script for bare metal deployment.
This commit is contained in:
parent
677e7908ce
commit
0401944b09
6 changed files with 87 additions and 19 deletions
33
Dockerfile
Normal file
33
Dockerfile
Normal file
|
@ -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" ]
|
15
__init__.py
15
__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
|
22
docker-compose.yaml
Normal file
22
docker-compose.yaml
Normal file
|
@ -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
|
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export FLASK_APP=app.py
|
|
||||||
export FLASK_ENV=development
|
|
12
start_app.sh
Executable file
12
start_app.sh
Executable file
|
@ -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
|
|
@ -1,19 +1,9 @@
|
||||||
|
try:
|
||||||
from .lib.helpers import get_static_paths, get_content_text
|
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 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'])
|
@app.route('/home', methods=['GET'])
|
Reference in a new issue