From f56f592c4c78292f3cd348bc03512a74a6445b81 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Mon, 14 Apr 2025 22:35:38 +0200 Subject: [PATCH] Added distroless dockerfile. Updated docker compose --- .dockerignore | 6 +++++- .gitignore | 2 +- Moonlight.ApiServer/Dockerfile | 32 +++++++++++++++++++++------- compose.yml | 38 ++++++++++++++++++++-------------- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/.dockerignore b/.dockerignore index b3053aa5..2a8688fc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,5 +22,9 @@ **/secrets.dev.yaml **/values.dev.yaml **/storage +**/compose.yml LICENSE -README.md \ No newline at end of file +README.md + +# For the people who run moonlight inside the main repo with the relative data path +data diff --git a/.gitignore b/.gitignore index 8d91b6d2..f1b5721e 100644 --- a/.gitignore +++ b/.gitignore @@ -422,7 +422,7 @@ FodyWeavers.xsd # Moonlight storage/ -/.idea/.idea.Moonlight/.idea +**/.idea/** style.min.css core.min.css diff --git a/Moonlight.ApiServer/Dockerfile b/Moonlight.ApiServer/Dockerfile index 205c7879..ca790bd6 100644 --- a/Moonlight.ApiServer/Dockerfile +++ b/Moonlight.ApiServer/Dockerfile @@ -1,37 +1,53 @@ -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base -USER $APP_UID +# Prepare runtime docker image +FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS base WORKDIR /app +# Prepare build image FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build - ARG BUILD_CONFIGURATION=Release -WORKDIR /src +# Install nodejs and npm so we can build tailwind +RUN apt-get update && apt-get install nodejs npm -y && apt-get clean +# Copy package.json file +WORKDIR /src +COPY ["Moonlight.Client/Styles/package.json", "Moonlight.Client/Styles/"] + +# Install npm packages +WORKDIR /src/Moonlight.Client/Styles/ +RUN npm i + +# Copy project configuration files +WORKDIR /src COPY ["Moonlight.ApiServer/Moonlight.ApiServer.csproj", "Moonlight.ApiServer/"] COPY ["Moonlight.Client/Moonlight.Client.csproj", "Moonlight.Client/"] COPY ["Moonlight.Shared/Moonlight.Shared.csproj", "Moonlight.Shared/"] +# Restore the nuget packages RUN dotnet restore "Moonlight.ApiServer/Moonlight.ApiServer.csproj" +# Copy all files COPY . . -WORKDIR "/src/Moonlight.ApiServer" +# Build tailwindcss +WORKDIR "/src/Moonlight.Client/Styles" +RUN npx tailwindcss -i style.css -o ../wwwroot/css/core.min.css --minify +# Build ApiServer project +WORKDIR "/src/Moonlight.ApiServer" RUN dotnet build "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/build +# Publish application FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +# Create final small image with the built content FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -# Create storage directory a volume can bind to -RUN mkdir -p /app/storage - ENTRYPOINT ["dotnet", "Moonlight.ApiServer.dll"] diff --git a/compose.yml b/compose.yml index 691f572e..fcbb34b8 100644 --- a/compose.yml +++ b/compose.yml @@ -1,5 +1,7 @@ services: api-server: + user: 0:0 + restart: always image: moonlightpanel/panel:custom build: context: . @@ -10,31 +12,35 @@ services: db: condition: service_healthy environment: - - MOONLIGHT_APP_DATABASE_HOST=db - - MOONLIGHT_APP_DATABASE_PORT=3306 - - MOONLIGHT_APP_DATABASE_USERNAME=moonlight - - MOONLIGHT_APP_DATABASE_PASSWORD=s3cret - - MOONLIGHT_APP_DATABASE_DATABASE=moonlight - - MOONLIGHT_APP_PUBLICURL=http://localhost:9069 + - MOONLIGHT_DATABASE_HOST=db + - MOONLIGHT_DATABASE_PORT=5432 + - MOONLIGHT_DATABASE_USERNAME=moonlight + - MOONLIGHT_DATABASE_PASSWORD=s3cret + - MOONLIGHT_DATABASE_DATABASE=moonlight + - MOONLIGHT_PUBLICURL=http://localhost:9069 + - MOONLIGHT_AUTHENTICATION_OAUTH2_ACCESSENDPOINT=http://localhost:8080 # Use this when moonlight is using local oauth2 and a different port as the public url volumes: - - api_data:/app/storage + - ./data/moonlight:/app/storage links: - db pull_policy: build db: - image: mysql:latest + image: postgres:latest + restart: always + ports: + - "5555:5432" environment: - - MYSQL_ROOT_PASSWORD=s3cret - - MYSQL_PASSWORD=s3cret - - MYSQL_DATABASE=moonlight - - MYSQL_USER=moonlight + - POSTGRES_USER=moonlight + - POSTGRES_DB=moonlight + - POSTGRES_PASSWORD=s3cret volumes: - - db_data:/var/lib/mysql + - ./data/database:/var/lib/postgresql/data healthcheck: - test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ] - timeout: 1s - retries: 10 + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 volumes: api_data: