Fix docker dev db persistence (#264)

* Fix docker dev db persistence

* Make run.sh the only startup script for prod + dev

Credits to @hay-kot for run.sh script logic

* Restore dev backend initialization in non-docker setup

* Make run.sh POSIX-friendly

* Allow dev backend to auto-reload in Docker
This commit is contained in:
sephrat 2021-04-06 23:10:05 +02:00 committed by GitHub
parent 6706918736
commit a396604520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 14 deletions

View File

@ -14,12 +14,9 @@ RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-
# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml /app/
# RUN poetry install
COPY ./mealie /app/mealie
RUN poetry install
RUN ["poetry", "run", "python", "mealie/db/init_db.py"]
RUN ["poetry", "run", "python", "mealie/services/image/minify.py"]
CMD ["poetry", "run", "python", "mealie/app.py"]
RUN chmod +x /app/mealie/run.sh
CMD /app/mealie/run.sh reload

View File

@ -29,7 +29,7 @@ services:
db_type: sqlite
TZ: America/Anchorage # Specify Correct Timezone for Date/Time to line up correctly.
volumes:
- ./app_data:/app_data
- ./dev/data:/app/dev/data
- ./mealie:/app/mealie
# Mkdocs

View File

@ -51,7 +51,7 @@ start_scheduler()
def main():
uvicorn.run(
"app:app",
host="0.0.0.0",

View File

@ -47,11 +47,12 @@ def default_user_init(session: Session):
logger.info("Generating Default User")
db.users.create(session, default_user)
if __name__ == "__main__":
def main():
if sql_exists:
print("Database Exists")
exit()
else:
print("Database Doesn't Exists, Initializing...")
init_db()
if __name__ == "__main__":
main()

View File

@ -1,5 +1,8 @@
#!/bin/sh
# Get Reload Arg `run.sh reload` for dev server
ARG1=${1:-production}
# Initialize Database Prerun
python mealie/db/init_db.py
python mealie/services/image/minify.py
@ -7,8 +10,17 @@ python mealie/services/image/minify.py
## Migrations
# TODO
## Web Server
caddy start --config ./Caddyfile
if [ "$ARG1" = "reload" ]
then
echo "Hot reload"
# Start API
uvicorn mealie.app:app --host 0.0.0.0 --port 9000
# Start API
uvicorn mealie.app:app --host 0.0.0.0 --port 9000 --reload
else
echo "Production config"
# Web Server
caddy start --config ./Caddyfile
# Start API
uvicorn mealie.app:app --host 0.0.0.0 --port 9000
fi