refactor forest src

This commit is contained in:
deflax 2024-02-24 14:46:14 +02:00
parent 1ca27ea862
commit f9b1c432ae
137 changed files with 48 additions and 142 deletions

View file

@ -2,7 +2,7 @@ version: '3'
services:
db:
image: postgres:13
image: postgres:15
volumes:
- "./data/db/pgdata:/var/lib/postgresql/data/"
env_file:
@ -10,6 +10,7 @@ services:
restart: always
networks:
- internal
pgadmin:
image: dpage/pgadmin4
#volumes:
@ -23,23 +24,22 @@ services:
- internal
depends_on:
- db
flask:
build:
context: ./flask
dockerfile: Dockerfile
command: gunicorn --bind 0.0.0.0:5000 manage:app
forest:
depends_on:
- "db"
build: ./src/forest
image: forest:latest
ports:
- 5000:5000
environment:
- "FLASK_ENV=production"
- "FLASK_APP=forest/__init__.py"
- "APP_HOME=/app"
env_file:
- ./.env
restart: unless-stopped
networks:
- internal
depends_on:
- db
- internal
labels:
- meta.role=forest
osmtile:
image: overv/openstreetmap-tile-server:2.3.0
hostname: osmtile
@ -55,5 +55,6 @@ services:
networks:
- internal
restart: always
networks:
internal: {}

View file

@ -1,34 +0,0 @@
FROM python:3
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup --system app && adduser --system --group app
# create the appropriate directories
ENV APP_HOME=/app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd gcc
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# copy entrypoint.sh
COPY ./entrypoint.sh $APP_HOME
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

View file

@ -1,14 +0,0 @@
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done
echo "PostgreSQL started"
fi
exec "$@"

View file

@ -1,23 +0,0 @@
from flask.cli import FlaskGroup
from project import app, db, User
cli = FlaskGroup(app)
@cli.command("create_db")
def create_db():
db.drop_all()
db.create_all()
db.session.commit()
@cli.command("seed_db")
def seed_db():
db.session.add(User(email="daniel@deflax.net"))
db.session.commit()
if __name__ == "__main__":
cli()

View file

@ -1,54 +0,0 @@
#!/usr/bin/env python
import os
from flask.cli import FlaskGroup
from forest import app, db
from forest.models import User
from flask_migrate import Migrate
cli = FlaskGroup(app)
migrate = Migrate()
migrate.init_app(app, db)
@cli.command("create_db")
def create_db():
db.drop_all()
db.create_all()
db.session.commit()
@cli.command("seed_db")
def seed_db():
db.session.add(User(email="daniel@deflax.net"))
db.session.commit()
@cli.command("upgrade_db")
def upgrade_db():
"""Run deployment tasks."""
from flask_migrate import upgrade
from app.models import Role, User
# migrate database to latest revision
upgrade()
# create user roles
Role.insert_roles()
@cli.command("restore_db")
def restore_db(restore_file):
""" recreate db from grid export with python3 manage.py restore /path/grid.tar.bz2 """
print(str(restore_file))
#TODO
from app.models import User
db.session.add(User(email=str(user), password=str(password), confirmed=True, confirmed_on=datetime.datetime.now()))
db.session.commit()
if __name__ == "__main__":
cli()

23
src/forest/Dockerfile Normal file
View file

@ -0,0 +1,23 @@
FROM python:3-bookworm
# install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
netcat-openbsd \
gcc \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# create the appropriate directories
ENV APP_HOME=/app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# copy project
COPY . $APP_HOME
RUN pip3 install -r requirements.txt
EXPOSE 8080
CMD [ "waitress-serve", "--port=5000", "--call", "forest:create_app"]

View file

@ -1,6 +1,8 @@
gunicorn
psycopg2-binary
alembic
APScheduler
requests
blinker
click
waitress
Flask
Flask-SQLAlchemy
Flask-Admin
@ -11,9 +13,14 @@ Flask-Migrate
Flask-Moment
Flask-Uploads
Flask-WTF
itsdangerous
Jinja2
PyQRCode
WTForms
onetimepass
MarkupSafe
Werkzeug
email_validator
iso3166
iso3166
psycopg2-binary
alembic

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

Before

Width:  |  Height:  |  Size: 7 KiB

After

Width:  |  Height:  |  Size: 7 KiB

View file

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View file

Before

Width:  |  Height:  |  Size: 1,015 B

After

Width:  |  Height:  |  Size: 1,015 B

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View file

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 242 KiB

View file

Before

Width:  |  Height:  |  Size: 8.2 MiB

After

Width:  |  Height:  |  Size: 8.2 MiB

View file

Before

Width:  |  Height:  |  Size: 797 B

After

Width:  |  Height:  |  Size: 797 B

View file

Before

Width:  |  Height:  |  Size: 251 KiB

After

Width:  |  Height:  |  Size: 251 KiB

View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 981 B

After

Width:  |  Height:  |  Size: 981 B

View file

Before

Width:  |  Height:  |  Size: 941 B

After

Width:  |  Height:  |  Size: 941 B

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View file

Before

Width:  |  Height:  |  Size: 999 B

After

Width:  |  Height:  |  Size: 999 B

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 568 B

After

Width:  |  Height:  |  Size: 568 B

View file

Before

Width:  |  Height:  |  Size: 311 KiB

After

Width:  |  Height:  |  Size: 311 KiB

View file

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 179 KiB

View file

Before

Width:  |  Height:  |  Size: 311 KiB

After

Width:  |  Height:  |  Size: 311 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 85 B

After

Width:  |  Height:  |  Size: 85 B

View file

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View file

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View file

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

Before

Width:  |  Height:  |  Size: 402 KiB

After

Width:  |  Height:  |  Size: 402 KiB

View file

Before

Width:  |  Height:  |  Size: 424 KiB

After

Width:  |  Height:  |  Size: 424 KiB

Some files were not shown because too many files have changed in this diff Show more