From bdd8830c8eca98fc9fbd5b56e03a5a9718d401a2 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Mon, 2 Jan 2023 02:50:33 +0100 Subject: [PATCH] add healthchecks to docker --- Docker/build/Dockerfile-MareSynchronosServer | 1 + .../build/Dockerfile-MareSynchronosServer-git | 1 + .../build/Dockerfile-MareSynchronosServices | 1 + .../Dockerfile-MareSynchronosServices-git | 1 + ...Dockerfile-MareSynchronosStaticFilesServer | 1 + ...erfile-MareSynchronosStaticFilesServer-git | 1 + Docker/run/compose/mare-sharded.yml | 40 +++++++++++++------ .../MareSynchronosServer/Startup.cs | 4 ++ .../Startup.cs | 3 ++ 9 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Docker/build/Dockerfile-MareSynchronosServer b/Docker/build/Dockerfile-MareSynchronosServer index 8b3ddbd..9a33d5c 100644 --- a/Docker/build/Dockerfile-MareSynchronosServer +++ b/Docker/build/Dockerfile-MareSynchronosServer @@ -24,6 +24,7 @@ RUN adduser \ COPY --from=BUILD /build /opt/MareSynchronosServer RUN chown -R mare:mare /opt/MareSynchronosServer +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosServer diff --git a/Docker/build/Dockerfile-MareSynchronosServer-git b/Docker/build/Dockerfile-MareSynchronosServer-git index 1e9a22f..1f643da 100644 --- a/Docker/build/Dockerfile-MareSynchronosServer-git +++ b/Docker/build/Dockerfile-MareSynchronosServer-git @@ -22,6 +22,7 @@ RUN adduser \ COPY --from=BUILD /MareSynchronosServer /opt/MareSynchronosServer RUN chown -R mare:mare /opt/MareSynchronosServer +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosServer diff --git a/Docker/build/Dockerfile-MareSynchronosServices b/Docker/build/Dockerfile-MareSynchronosServices index 46c5cb9..7dc8d35 100644 --- a/Docker/build/Dockerfile-MareSynchronosServices +++ b/Docker/build/Dockerfile-MareSynchronosServices @@ -24,6 +24,7 @@ RUN adduser \ COPY --from=BUILD /build /opt/MareSynchronosServices RUN chown -R mare:mare /opt/MareSynchronosServices +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosServices diff --git a/Docker/build/Dockerfile-MareSynchronosServices-git b/Docker/build/Dockerfile-MareSynchronosServices-git index 82cb1e7..1e47631 100644 --- a/Docker/build/Dockerfile-MareSynchronosServices-git +++ b/Docker/build/Dockerfile-MareSynchronosServices-git @@ -22,6 +22,7 @@ RUN adduser \ COPY --from=BUILD /MareSynchronosServices /opt/MareSynchronosServices RUN chown -R mare:mare /opt/MareSynchronosServices +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosServices diff --git a/Docker/build/Dockerfile-MareSynchronosStaticFilesServer b/Docker/build/Dockerfile-MareSynchronosStaticFilesServer index bcd2cb4..ad5499a 100644 --- a/Docker/build/Dockerfile-MareSynchronosStaticFilesServer +++ b/Docker/build/Dockerfile-MareSynchronosStaticFilesServer @@ -24,6 +24,7 @@ RUN adduser \ COPY --from=BUILD /build /opt/MareSynchronosStaticFilesServer RUN chown -R mare:mare /opt/MareSynchronosStaticFilesServer +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosStaticFilesServer diff --git a/Docker/build/Dockerfile-MareSynchronosStaticFilesServer-git b/Docker/build/Dockerfile-MareSynchronosStaticFilesServer-git index c6a97bc..2270ed2 100644 --- a/Docker/build/Dockerfile-MareSynchronosStaticFilesServer-git +++ b/Docker/build/Dockerfile-MareSynchronosStaticFilesServer-git @@ -22,6 +22,7 @@ RUN adduser \ COPY --from=BUILD /MareSynchronosStaticFilesServer /opt/MareSynchronosStaticFilesServer RUN chown -R mare:mare /opt/MareSynchronosStaticFilesServer +RUN apt-get update; apt-get install curl -y USER mare:mare WORKDIR /opt/MareSynchronosStaticFilesServer diff --git a/Docker/run/compose/mare-sharded.yml b/Docker/run/compose/mare-sharded.yml index f330eec..afe9527 100644 --- a/Docker/run/compose/mare-sharded.yml +++ b/Docker/run/compose/mare-sharded.yml @@ -12,6 +12,7 @@ services: healthcheck: test: ["CMD-SHELL", "pg_isready -U mare"] interval: 5s + start_period: 5s timeout: 5s retries: 5 @@ -22,7 +23,10 @@ services: - 6000:6000/tcp volumes: - ../config/sharded/haproxy-shards.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - + depends_on: + mare-server: + condition: service_healthy + redis: image: redis:latest command: [sh, -c, "rm -f /data/dump.rdb && redis-server --save \"\" --appendonly no --requirepass secretredispassword"] @@ -45,6 +49,11 @@ services: depends_on: postgres: condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "curl --fail http://localhost:6000/health || exit 1"] + retries: 60 + start_period: 10s + timeout: 1s mare-shard-1: image: darkarchon/mare-synchronos-server:latest @@ -54,8 +63,8 @@ services: - ../log/server-shard-1/:/opt/MareSynchronosServer/logs/:rw - postgres_socket:/var/run/postgresql/:rw depends_on: - - "postgres" - - "mare-server" + mare-server: + condition: service_healthy mare-shard-2: image: darkarchon/mare-synchronos-server:latest @@ -65,8 +74,8 @@ services: - ../log/server-shard-2/:/opt/MareSynchronosServer/logs/:rw - postgres_socket:/var/run/postgresql/:rw depends_on: - - "postgres" - - "mare-server" + mare-server: + condition: service_healthy mare-services: image: darkarchon/mare-synchronos-services:latest @@ -78,8 +87,8 @@ services: - ../log/services-standalone/:/opt/MareSynchronosServices/logs/:rw - postgres_socket:/var/run/postgresql/:rw depends_on: - - "postgres" - - "mare-server" + mare-server: + condition: service_healthy mare-files: image: darkarchon/mare-synchronos-staticfilesserver:latest @@ -90,8 +99,13 @@ services: - postgres_socket:/var/run/postgresql/:rw - ../data/files-shard-main/:/marecache/:rw depends_on: - - "postgres" - - "mare-server" + mare-server: + condition: service_healthy + healthcheck: + test: curl --fail http://localhost:6200/health || exit 1 + retries: 60 + start_period: 10s + timeout: 1s mare-files-shard-1: image: darkarchon/mare-synchronos-staticfilesserver:latest @@ -104,8 +118,8 @@ services: ports: - 6200:6200/tcp depends_on: - - "postgres" - - "mare-files" + mare-files: + condition: service_healthy mare-files-shard-2: image: darkarchon/mare-synchronos-staticfilesserver:latest @@ -118,8 +132,8 @@ services: ports: - 6201:6200/tcp depends_on: - - "postgres" - - "mare-files" + mare-files: + condition: service_healthy volumes: cache: diff --git a/MareSynchronosServer/MareSynchronosServer/Startup.cs b/MareSynchronosServer/MareSynchronosServer/Startup.cs index bfe6c28..48abe0a 100644 --- a/MareSynchronosServer/MareSynchronosServer/Startup.cs +++ b/MareSynchronosServer/MareSynchronosServer/Startup.cs @@ -60,6 +60,8 @@ public class Startup // configure mare specific services ConfigureMareServices(services, mareConfig); + + services.AddHealthChecks(); } private static void ConfigureMareServices(IServiceCollection services, IConfigurationSection mareConfig) @@ -303,6 +305,8 @@ public class Startup endpoints.MapGrpcService().AllowAnonymous(); endpoints.MapGrpcService>().AllowAnonymous(); } + + endpoints.MapHealthChecks("/health").WithMetadata(new AllowAnonymousAttribute()); }); } } diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs index 24e2738..00597b5 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs @@ -136,6 +136,8 @@ public class Startup ); services.AddHostedService(p => (MareConfigurationServiceClient)p.GetService>()); + + services.AddHealthChecks(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -161,6 +163,7 @@ public class Startup e.MapGrpcService(); } e.MapControllers(); + e.MapHealthChecks("/health").WithMetadata(new AllowAnonymousAttribute()); }); } } \ No newline at end of file