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: services:
db: db:
image: postgres:13 image: postgres:15
volumes: volumes:
- "./data/db/pgdata:/var/lib/postgresql/data/" - "./data/db/pgdata:/var/lib/postgresql/data/"
env_file: env_file:
@ -10,6 +10,7 @@ services:
restart: always restart: always
networks: networks:
- internal - internal
pgadmin: pgadmin:
image: dpage/pgadmin4 image: dpage/pgadmin4
#volumes: #volumes:
@ -23,23 +24,22 @@ services:
- internal - internal
depends_on: depends_on:
- db - db
flask:
build: forest:
context: ./flask depends_on:
dockerfile: Dockerfile - "db"
command: gunicorn --bind 0.0.0.0:5000 manage:app build: ./src/forest
image: forest:latest
ports: ports:
- 5000:5000 - 5000:5000
environment:
- "FLASK_ENV=production"
- "FLASK_APP=forest/__init__.py"
- "APP_HOME=/app"
env_file: env_file:
- ./.env - ./.env
restart: unless-stopped
networks: networks:
- internal - internal
depends_on: labels:
- db - meta.role=forest
osmtile: osmtile:
image: overv/openstreetmap-tile-server:2.3.0 image: overv/openstreetmap-tile-server:2.3.0
hostname: osmtile hostname: osmtile
@ -55,5 +55,6 @@ services:
networks: networks:
- internal - internal
restart: always restart: always
networks: networks:
internal: {} 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 APScheduler
psycopg2-binary requests
alembic blinker
click
waitress
Flask Flask
Flask-SQLAlchemy Flask-SQLAlchemy
Flask-Admin Flask-Admin
@ -11,9 +13,14 @@ Flask-Migrate
Flask-Moment Flask-Moment
Flask-Uploads Flask-Uploads
Flask-WTF Flask-WTF
itsdangerous
Jinja2 Jinja2
PyQRCode PyQRCode
WTForms WTForms
onetimepass onetimepass
MarkupSafe
Werkzeug
email_validator 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