From 6035a246532dc1bcbd3f80e6017ca2c6dbff1dde Mon Sep 17 00:00:00 2001 From: Brassn <48657890+Brassn@users.noreply.github.com> Date: Thu, 19 Feb 2026 00:07:54 +0100 Subject: [PATCH 1/2] docker container configuration --- .env.example | 5 ++++ .gitignore | 6 ++++ docker-compose.yml | 53 +++++++++++++++++++++++++++++++++++ src/cli/OpenPlzApi.CLI.csproj | 3 +- src/cli/Program.cs | 1 + src/cli/dockerfile | 20 +++++++++++++ src/webservice/dockerfile | 18 ++++++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .env.example create mode 100644 docker-compose.yml create mode 100644 src/cli/dockerfile create mode 100644 src/webservice/dockerfile diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..909c576 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DATABASE=OpenPlzApi +DBUSERNAME=plzuser +DBPASSWORD=qwertz +ENVIRONMENT=Development +TZ=Europe/Berlin diff --git a/.gitignore b/.gitignore index 3260fc8..9c730df 100644 --- a/.gitignore +++ b/.gitignore @@ -363,3 +363,9 @@ FodyWeavers.xsd # No development configurations appsettings.Development.json + +# No Docker environment configurations +.env + +# No downloads +downloads/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f0ed6cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +services: + db: + image: postgres:18-alpine + restart: unless-stopped + shm_size: 256mb + volumes: + - pgdata:/var/lib/postgresql + environment: + POSTGRES_DB: ${DATABASE} + POSTGRES_USER: ${DBUSERNAME} + POSTGRES_PASSWORD: ${DBPASSWORD} + + api: + image: openplzapi-webservice:latest + build: + context: ./src + dockerfile: ./webservice/dockerfile + restart: unless-stopped + depends_on: + - db + environment: + ASPNETCORE_ENVIRONMENT: ${ENVIRONMENT} + ASPNETCORE_HTTP_PORTS: 8080 + Database__Server: db + Database__Database: ${DATABASE} + Database__Username: ${DBUSERNAME} + Database__Password: ${DBPASSWORD} + TZ: ${TZ:-Europe/Berlin} + ports: + - 8080:8080 + + cli: + image: openplzapi-cli:latest + build: + context: ./src + dockerfile: ./cli/dockerfile + # uncomment the following line for initialization of the database, then comment it again for regular usage + # command: ["initdb","--import"] + restart: "no" + depends_on: + - db + environment: + ASPNETCORE_ENVIRONMENT: ${ENVIRONMENT} + Database__Server: db + Database__Database: ${DATABASE} + Database__Username: ${DBUSERNAME} + Database__Password: ${DBPASSWORD} + TZ: ${TZ:-Europe/Berlin} + volumes: + - ./downloads:/downloads + +volumes: + pgdata: diff --git a/src/cli/OpenPlzApi.CLI.csproj b/src/cli/OpenPlzApi.CLI.csproj index ff6576d..74da1d1 100644 --- a/src/cli/OpenPlzApi.CLI.csproj +++ b/src/cli/OpenPlzApi.CLI.csproj @@ -27,6 +27,7 @@ + @@ -35,7 +36,7 @@ - + diff --git a/src/cli/Program.cs b/src/cli/Program.cs index 0a77970..12886a1 100644 --- a/src/cli/Program.cs +++ b/src/cli/Program.cs @@ -38,6 +38,7 @@ public static async Task Main(string[] args) .AddJsonFile("appsettings.json", optional: false) .AddJsonFile("appsettings.Development.json", optional: true) .AddJsonFile("appsettings.Production.json", optional: true) + .AddEnvironmentVariables() .Build(); // Bind configuration diff --git a/src/cli/dockerfile b/src/cli/dockerfile new file mode 100644 index 0000000..e8224ae --- /dev/null +++ b/src/cli/dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /App + +# Copy everything +COPY ./cli ./ +COPY ./datalayer /datalayer +# Restore as distinct layers +RUN dotnet restore +# Build and publish a release +RUN dotnet publish -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/runtime:10.0 +WORKDIR /App +COPY --from=build /App/out . +ENV Sources__RootFolderName=/downloads +RUN mkdir /downloads +ENTRYPOINT ["dotnet", "OpenPlzApi.CLI.dll"] +# Default to showing help when no command is provided; user can pass any subcommand +CMD ["-h"] diff --git a/src/webservice/dockerfile b/src/webservice/dockerfile new file mode 100644 index 0000000..1deb93d --- /dev/null +++ b/src/webservice/dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /App + +# Copy everything +COPY ./webservice ./ +COPY ./datalayer /datalayer +# Restore as distinct layers +RUN dotnet restore +# Build and publish a release +RUN dotnet publish -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:10.0 +WORKDIR /App +COPY --from=build /App/out . +EXPOSE 8080 +USER $APP_UID +ENTRYPOINT ["dotnet", "OpenPlzApi.WebService.dll"] From e850972f6875f67c699924313838a1b05b68bba2 Mon Sep 17 00:00:00 2001 From: Brassn <48657890+Brassn@users.noreply.github.com> Date: Wed, 11 Mar 2026 23:17:40 +0100 Subject: [PATCH 2/2] container names --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index f0ed6cc..73a3400 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ services: db: image: postgres:18-alpine + container_name: openplz-db restart: unless-stopped shm_size: 256mb volumes: @@ -15,6 +16,7 @@ services: build: context: ./src dockerfile: ./webservice/dockerfile + container_name: openplz-api restart: unless-stopped depends_on: - db @@ -34,6 +36,7 @@ services: build: context: ./src dockerfile: ./cli/dockerfile + container_name: openplz-cli # uncomment the following line for initialization of the database, then comment it again for regular usage # command: ["initdb","--import"] restart: "no"