From a3a61710d3ce0d07e83e49d6b3dbc07497185944 Mon Sep 17 00:00:00 2001 From: maxDorninger <97409287+maxDorninger@users.noreply.github.com> Date: Mon, 30 Jun 2025 15:46:59 +0200 Subject: [PATCH 1/2] trying to optimize runtime of worklfow building the frontend containers --- .github/workflows/build-push-frontend.yml | 6 +++++- web/Dockerfile | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-push-frontend.yml b/.github/workflows/build-push-frontend.yml index 6473617..2c2e824 100644 --- a/.github/workflows/build-push-frontend.yml +++ b/.github/workflows/build-push-frontend.yml @@ -26,8 +26,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: '20' + cache: 'npm' + cache-dependency-path: './web/package-lock.json' - name: Install dependencies - run: npm install + run: npm ci working-directory: ./web - name: Lint code run: npm run lint @@ -91,3 +93,5 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | VERSION=${{ steps.version.outputs.version }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/web/Dockerfile b/web/Dockerfile index b056f28..e4967c7 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -4,16 +4,15 @@ FROM node:24-alpine AS deps WORKDIR /app COPY package*.json ./ -RUN npm ci --only=production +RUN npm ci --only=production && npm cache clean --force FROM node:24-alpine AS build WORKDIR /app ARG VERSION ARG BASE_URL -COPY --from=deps /app/node_modules ./node_modules COPY package*.json ./ -RUN npm ci +RUN npm ci && npm cache clean --force COPY . . RUN env PUBLIC_VERSION=${VERSION} BASE_URL=${BASE_URL} npm run build @@ -30,7 +29,8 @@ ENV PUBLIC_SSR_WEB=false COPY --from=build /app/build/ ./build/ COPY package*.json ./ COPY --chmod=755 mediamanager-frontend-startup.sh ./ -RUN npm ci --only=production + +COPY --from=deps /app/node_modules ./node_modules EXPOSE 3000 USER node From 4d67db6545cafbc68b9715b74cd57c5dcba4d564 Mon Sep 17 00:00:00 2001 From: maxDorninger <97409287+maxDorninger@users.noreply.github.com> Date: Mon, 30 Jun 2025 17:17:21 +0200 Subject: [PATCH 2/2] fix the docker files and startup scripts, also fix a bug in the hello world route of the backend --- Dockerfile | 6 ++-- media_manager/main.py | 5 ++-- mediamanager-backend-startup.sh | 10 ++++--- web/Dockerfile | 28 ++++++++++--------- ...ager-frontend-startup.sh => entrypoint.sh} | 8 +++--- 5 files changed, 31 insertions(+), 26 deletions(-) rename web/{mediamanager-frontend-startup.sh => entrypoint.sh} (76%) diff --git a/Dockerfile b/Dockerfile index 7805f94..8e510f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,8 @@ ENV IMAGE_DIRECTORY=/data/images \ MOVIE_DIRECTORY=/data/movies \ TORRENT_DIRECTORY=/data/torrents \ OPENID_ENABLED=FALSE \ - PUBLIC_VERSION=${VERSION} + PUBLIC_VERSION=${VERSION} \ + UV_PROJECT_ENVIRONMENT=/app/.venv RUN apt-get update && \ apt-get install -y --no-install-recommends ca-certificates && \ @@ -29,7 +30,8 @@ RUN apt-get update && \ WORKDIR /app -COPY --from=builder /usr/local/lib/python3.*/site-packages /usr/local/lib/python3.*/site-packages/ +COPY --from=builder /app/.venv /app/.venv +COPY --from=builder /app/pyproject.toml /app/uv.lock ./ COPY --chmod=755 mediamanager-backend-startup.sh . COPY media_manager ./media_manager diff --git a/media_manager/main.py b/media_manager/main.py index 2f81674..75984dd 100644 --- a/media_manager/main.py +++ b/media_manager/main.py @@ -289,13 +289,12 @@ except Exception as e: raise -@app.get("/", response_model={"message": str, "version": str}) -async def hello_world(): +@app.get("/") +async def hello_world() -> dict: """ A simple endpoint to check if the API is running. """ return {"message": "Hello World!", "version": os.getenv("PUBLIC_VERSION")} - if __name__ == "__main__": uvicorn.run(app, host="127.0.0.1", port=5049, log_config=LOGGING_CONFIG) diff --git a/mediamanager-backend-startup.sh b/mediamanager-backend-startup.sh index bdf8af5..169b803 100644 --- a/mediamanager-backend-startup.sh +++ b/mediamanager-backend-startup.sh @@ -3,16 +3,18 @@ # text created with https://patorjk.com/software/taag/ font: Slanted -cat << EOF +echo " __ ___ ___ __ ___ ____ __ __ / |/ /__ ____/ (_)___ _/ |/ /___ _____ ____ _____ ____ _____ / __ )____ ______/ /_____ ____ ____/ / - / /|_/ / _ \/ __ / / __ `/ /|_/ / __ `/ __ \/ __ `/ __ `/ _ \/ ___/ / __ / __ `/ ___/ //_/ _ \/ __ \/ __ / + / /|_/ / _ \/ __ / / __ \`/ /|_/ / __ \`/ __ \/ __ \`/ __ \`/ _ \/ ___/ / __ / __ \`/ ___/ //_/ _ \/ __ \/ __ / / / / / __/ /_/ / / /_/ / / / / /_/ / / / / /_/ / /_/ / __/ / / /_/ / /_/ / /__/ ,< / __/ / / / /_/ / /_/ /_/\___/\__,_/_/\__,_/_/ /_/\__,_/_/ /_/\__,_/\__, /\___/_/ /_____/\__,_/\___/_/|_|\___/_/ /_/\__,_/ /____/ -EOF +" echo "Buy me a coffee at https://buymeacoffee.com/maxdorninger" echo "Running DB migrations..." + uv run alembic upgrade head + echo "Starting MediaManager backend service..." -uv run fastapi run /app/media_manager/main.py \ No newline at end of file +uv run fastapi run /app/media_manager/main.py --port 8000 diff --git a/web/Dockerfile b/web/Dockerfile index e4967c7..11ab5e5 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,37 +1,39 @@ ARG VERSION ARG BASE_URL="" -FROM node:24-alpine AS deps -WORKDIR /app - -COPY package*.json ./ -RUN npm ci --only=production && npm cache clean --force - FROM node:24-alpine AS build WORKDIR /app ARG VERSION ARG BASE_URL +# Copy package files first for better layer caching COPY package*.json ./ RUN npm ci && npm cache clean --force +# Copy source code after dependencies are installed COPY . . RUN env PUBLIC_VERSION=${VERSION} BASE_URL=${BASE_URL} npm run build FROM node:24-alpine AS frontend ARG VERSION + +USER node +EXPOSE 3000 WORKDIR /app + LABEL version=${VERSION} LABEL description="Docker image for the web frontend of MediaManager" + ENV PUBLIC_VERSION=${VERSION} ENV PUBLIC_SSR_WEB=false -COPY --from=build /app/build/ ./build/ -COPY package*.json ./ -COPY --chmod=755 mediamanager-frontend-startup.sh ./ +# Copy built application and package files +COPY --from=build /app/build ./build +COPY --from=build /app/package*.json ./ +COPY --chmod=755 entrypoint.sh . -COPY --from=deps /app/node_modules ./node_modules +# Install only production dependencies needed for the Node adapter +RUN npm ci --only=production && npm cache clean --force + +CMD ["/app/entrypoint.sh"] -EXPOSE 3000 -USER node -CMD ["/app/mediamanager-frontend-startup.sh"] diff --git a/web/mediamanager-frontend-startup.sh b/web/entrypoint.sh similarity index 76% rename from web/mediamanager-frontend-startup.sh rename to web/entrypoint.sh index 72da9c6..0acf8d1 100644 --- a/web/mediamanager-frontend-startup.sh +++ b/web/entrypoint.sh @@ -1,16 +1,16 @@ -#!/bin/bash -# This script is used to start the MediaManager backend service. +#!/bin/sh +# This script is used to start the MediaManager frontend service. # text created with https://patorjk.com/software/taag/ font: Slanted cat << EOF __ ___ ___ __ ___ ______ __ __ / |/ /__ ____/ (_)___ _/ |/ /___ _____ ____ _____ ____ _____ / ____/________ ____ / /____ ____ ____/ / - / /|_/ / _ \/ __ / / __ `/ /|_/ / __ `/ __ \/ __ `/ __ `/ _ \/ ___/ / /_ / ___/ __ \/ __ \/ __/ _ \/ __ \/ __ / + / /|_/ / _ \/ __ / / __ \`/ /|_/ / __ \`/ __ \/ __ \`/ __ \`/ _ \/ ___/ / /_ / ___/ __ \/ __ \/ __/ _ \/ __ \/ __ / / / / / __/ /_/ / / /_/ / / / / /_/ / / / / /_/ / /_/ / __/ / / __/ / / / /_/ / / / / /_/ __/ / / / /_/ / /_/ /_/\___/\__,_/_/\__,_/_/ /_/\__,_/_/ /_/\__,_/\__, /\___/_/ /_/ /_/ \____/_/ /_/\__/\___/_/ /_/\__,_/ /____/ EOF echo "Buy me a coffee at https://buymeacoffee.com/maxdorninger" echo "Starting MediaManager frontend service..." -node build/index.js \ No newline at end of file +node build/index.js