Add option to serve local archive files

Set an environment variable in the docker compose file, then reference
that variable in main.py to mount the local archive so that the links
generated by auto-archiver will work correctly. Fixes #8
This commit is contained in:
Lilia Kai
2023-09-05 16:10:37 +02:00
parent 9b622d1393
commit 91762f58b7
2 changed files with 7 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ services:
environment:
- CELERY_BROKER_URL=redis://:${REDIS_PASSWORD}@redis:6379/0
- CELERY_RESULT_BACKEND=redis://:${REDIS_PASSWORD}@redis:6379/0
- SERVE_LOCAL_ARCHIVE=/app/local_archive # See orchestration.yaml local_storage.save_to
depends_on:
- redis

View File

@@ -44,6 +44,11 @@ Instrumentator().instrument(app).expose(app, dependencies=[Depends(get_basic_aut
app.mount("/static", StaticFiles(directory="static"), name="static")
SERVE_LOCAL_ARCHIVE = os.environ.get("SERVE_LOCAL_ARCHIVE", "")
if len(SERVE_LOCAL_ARCHIVE) > 1 and os.path.isdir(SERVE_LOCAL_ARCHIVE):
logger.info(f"mounting local archive {SERVE_LOCAL_ARCHIVE}")
app.mount(SERVE_LOCAL_ARCHIVE, StaticFiles(directory=SERVE_LOCAL_ARCHIVE), name=SERVE_LOCAL_ARCHIVE)
def get_db():
session = SessionLocal()
try: yield session
@@ -186,4 +191,4 @@ async def on_startup():
@repeat_every(seconds=60 * 60) # 1 hour
async def on_startup():
db: Session = next(get_db())
crud.upsert_user_groups(db)
crud.upsert_user_groups(db)