From 536610a46f1913bd5cd97953e7896d727ead34fd Mon Sep 17 00:00:00 2001 From: Ske Date: Tue, 25 Aug 2020 20:37:31 +0200 Subject: [PATCH] Docker setup optimizations/tweaks --- .dockerignore | 25 +++++++++---------------- Dockerfile | 25 +++++++++++++++---------- docker-compose.yml | 36 ++++++++++++++++++++++-------------- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/.dockerignore b/.dockerignore index 095d093b..ea37ec39 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,18 +1,11 @@ -/.git/ -/.github/ -/.idea/ -/docs/ -/logs/ -/scripts/ +# Start by excluding everything +* -bin/ -obj/ +# Include project code and build files +!PluralKit.*/ +!PluralKit.sln +!nuget.config -*.conf -*.md -*.sql -*.gz -*.tar - -Dockerfile -docker-compose.yml \ No newline at end of file +# Re-exclude host build artifact directories +**/bin +**/obj \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b19634bf..d4a240a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,19 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build - -WORKDIR /app -COPY . /app -RUN dotnet publish -c Release -o out -f netcoreapp3.1 - FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine WORKDIR /app -RUN dotnet tool install --global dotnet-trace && dotnet tool install --global dotnet-dump && dotnet tool install --global dotnet-counters -COPY --from=build /app/PluralKit.*/bin/Release/netcoreapp3.1 ./ +# Restore/fetch dependencies excluding app code to make use of caching +COPY PluralKit.sln nuget.config /app/ +COPY PluralKit.API/PluralKit.API.csproj /app/PluralKit.API/ +COPY PluralKit.Bot/PluralKit.Bot.csproj /app/PluralKit.Bot/ +COPY PluralKit.Core/PluralKit.Core.csproj /app/PluralKit.Core/ +COPY PluralKit.Tests/PluralKit.Tests.csproj /app/PluralKit.Tests/ +RUN dotnet restore PluralKit.sln + +# Copy the rest of the code and build +COPY . /app +RUN dotnet build -c Release -o bin + +# Run :) +# Allow overriding CMD from eg. docker-compose to run API layer too ENTRYPOINT ["dotnet"] -CMD ["PluralKit.Bot.dll"] - +CMD ["bin/PluralKit.Bot.dll"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index af1b8cfe..6f6f0a3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,13 @@ +# API port: 2838, InfluxDB port: 2839, both listen on localhost only +# Reads `pluralkit.conf` from current directory, and logs to `/var/log/pluralkit`. + version: "3" + services: bot: image: pluralkit # This image is reused in the other containers due to the build: . # build instruction right here - command: ["PluralKit.Bot.dll"] + command: ["bin/PluralKit.Bot.dll"] environment: - "PluralKit:Database=Host=db;Username=postgres;Password=postgres;Database=postgres;Maximum Pool Size=1000" - "PluralKit:InfluxUrl=http://influx:8086" @@ -12,35 +16,39 @@ services: volumes: - "./pluralkit.conf:/app/pluralkit.conf:ro" - "/var/log/pluralkit:/var/log/pluralkit" - links: - - db - - influx - restart: always + restart: unless-stopped + api: image: pluralkit - command: ["PluralKit.API.dll"] + command: ["bin/PluralKit.API.dll"] environment: - "PluralKit:Database=Host=db;Username=postgres;Password=postgres;Database=postgres;Maximum Pool Size=1000" - links: - - db ports: - "127.0.0.1:2838:5000" - restart: always + restart: unless-stopped + db: - image: postgres:11-alpine + image: postgres:12-alpine volumes: - "db_data:/var/lib/postgresql/data" - restart: always - command: ["postgres", "-c", "max-connections=1000"] + - "/var/run/postgresql:/var/run/postgresql" + command: ["postgres", + "-c", "max-connections=1000", + "-c", "timezone='Etc/UTC'", + "-c", "max_wal_size=1GB", + "-c", "min_wal_size=80MB", + "-c", "shared_buffers=128MB"] environment: - "POSTGRES_PASSWORD=postgres" + restart: unless-stopped + influx: image: influxdb:alpine volumes: - "influx_data:/var/lib/influxdb" ports: - - 2839:8086 - restart: always + - 127.0.0.1:2839:8086 + restart: unless-stopped volumes: db_data: