From e5fe1db71d7c63a1306afb3742591748359e8083 Mon Sep 17 00:00:00 2001 From: Lapis Date: Fri, 19 Jun 2026 17:28:50 -0400 Subject: [PATCH] feat: dockerfile --- .dockerignore | 13 +++++++++ CannedNet.Admin/Dockerfile | 19 +++++++++++++ CannedNet.Admin/admin_config.json | 3 -- CannedNet/Dockerfile | 20 ++++++++++++++ docker-compose.yaml | 46 +++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 CannedNet.Admin/Dockerfile delete mode 100644 CannedNet.Admin/admin_config.json create mode 100644 CannedNet/Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e8c7d7f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +**/bin/ +**/obj/ +.git/ +.gitmodules/ +.idea/ +.DS_Store +*.user +*.DotSettings +CannedNet/Data/PrivateKey.pem +CannedNet/Data/PublicKey.pem +CannedNet/config.json +CannedNet.Admin/admin_users.json +CannedNet.Admin/admin_config.json diff --git a/CannedNet.Admin/Dockerfile b/CannedNet.Admin/Dockerfile new file mode 100644 index 0000000..ce9889f --- /dev/null +++ b/CannedNet.Admin/Dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src +COPY CannedNet.slnx ./ +COPY CannedNet.Shared/CannedNet.Shared.csproj CannedNet.Shared/ +COPY CannedNet.Admin/CannedNet.Admin.csproj CannedNet.Admin/ +RUN dotnet restore CannedNet.Admin/CannedNet.Admin.csproj +COPY . . +WORKDIR /src/CannedNet.Admin +RUN dotnet publish -c Release -o /app + +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime +WORKDIR /app +COPY --from=build /app . +RUN chown -R app:app /app +EXPOSE 8080 +ENV ASPNETCORE_URLS=http://+:8080 +ENV ASPNETCORE_ENVIRONMENT=Production +USER app +ENTRYPOINT ["dotnet", "CannedNet.Admin.dll"] \ No newline at end of file diff --git a/CannedNet.Admin/admin_config.json b/CannedNet.Admin/admin_config.json deleted file mode 100644 index a10bbd4..0000000 --- a/CannedNet.Admin/admin_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "ServerBaseUrl": "https://cannednet.lapis.codes" -} \ No newline at end of file diff --git a/CannedNet/Dockerfile b/CannedNet/Dockerfile new file mode 100644 index 0000000..343f461 --- /dev/null +++ b/CannedNet/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src +COPY CannedNet.slnx ./ +COPY CannedNet.Shared/CannedNet.Shared.csproj CannedNet.Shared/ +COPY CannedNet/CannedNet.csproj CannedNet/ +RUN dotnet restore CannedNet/CannedNet.csproj +COPY . . +WORKDIR /src/CannedNet +RUN dotnet publish -c Release -o /app + +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime +WORKDIR /app +COPY --from=build /app . +COPY --from=build /src/CannedNet/JSON JSON/ +RUN mkdir -p Data Images && chown -R app:app /app && chmod -R u+w /app +EXPOSE 5000 +ENV ASPNETCORE_URLS=http://+:5000 +VOLUME ["/app/Data", "/app/Images"] +USER app +ENTRYPOINT ["dotnet", "CannedNet.dll"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..2a4990f --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,46 @@ +services: + postgres: + image: postgres:alpine + restart: always + container_name: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 + env_file: ".env" + volumes: + - cannednet_pgdata:/var/lib/postgresql/cannednet/data + ports: + - "5532:5432" + + cannednet: + build: + context: . + dockerfile: CannedNet/Dockerfile + restart: always + ports: + - "5000:5000" + environment: + ConnectionStrings__DefaultConnection: "Host=postgres;Port=5432;Database=cannednet;Username=postgres;Password=${POSTGRES_PASSWORD:-postgres}" + volumes: + - cannednet_data:/app/Data + - cannednet_images:/app/Images + depends_on: + postgres: + condition: service_healthy + + admin: + build: + context: . + dockerfile: CannedNet.Admin/Dockerfile + restart: always + ports: + - "5271:8080" + depends_on: + - cannednet + +volumes: + cannednet_pgdata: + cannednet_data: + cannednet_images: