From 5ecf3a2c57e32fce3c6bf5ae95ecc49e2f3d7436 Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Tue, 5 Nov 2024 14:34:29 +0300 Subject: [PATCH] feat: healthcheck --- docker-compose-ghrc-tests.yml | 24 ++++++++++++++++--- docker-compose-ghrc.yml | 21 ++++++++++++++-- docker-compose-tests.yml | 24 ++++++++++++++++--- docker-compose.yml | 2 +- .../Controllers/ProfilesController.cs | 2 +- trustvpn-backend/Data/DbEnsure.cs | 2 +- trustvpn-backend/Dockerfile | 4 ++++ 7 files changed, 68 insertions(+), 11 deletions(-) diff --git a/docker-compose-ghrc-tests.yml b/docker-compose-ghrc-tests.yml index cdd2a01..d9ccb4e 100644 --- a/docker-compose-ghrc-tests.yml +++ b/docker-compose-ghrc-tests.yml @@ -11,8 +11,15 @@ services: - "8080:8080" - "8081:8081" depends_on: - - trustvpn-db - - trustvpn-container + trustvpn-db: + condition: service_healthy + trustvpn-container: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "localhost:8080/api/auth/ststus"] + interval: 10s + timeout: 5s + retries: 2 volumes: - /var/run/docker.sock:/var/run/docker.sock - logdata:/app/logs @@ -24,6 +31,11 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 volumes: - pgdata:/var/lib/postgresql/data @@ -38,6 +50,11 @@ services: sysctls: - net.ipv6.conf.all.disable_ipv6=0 - net.ipv6.conf.all.forwarding=1 + healthcheck: + test: ["CMD", "openvpn-check"] + interval: 10s + timeout: 5s + retries: 2 volumes: - ovpndata:/etc/openvpn @@ -47,7 +64,8 @@ services: container_name: trustvpn-tests command: ["run", "/home/trustvpn-tests/postman.json"] depends_on: - - trustvpn-backend + trustvpn-backend: + condition: service_healthy volumes: pgdata: {} diff --git a/docker-compose-ghrc.yml b/docker-compose-ghrc.yml index 4416bbe..dd53787 100644 --- a/docker-compose-ghrc.yml +++ b/docker-compose-ghrc.yml @@ -17,8 +17,15 @@ services: - "8080:8080" - "8081:8081" depends_on: - - trustvpn-db - - trustvpn-container + trustvpn-db: + condition: service_healthy + trustvpn-container: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "localhost:8080/api/auth/ststus"] + interval: 10s + timeout: 5s + retries: 2 volumes: - /etc/nginx/certificate:/etc/certificate - /var/run/docker.sock:/var/run/docker.sock @@ -31,6 +38,11 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 volumes: - /var/o-service/pgdata:/var/lib/postgresql/data @@ -45,5 +57,10 @@ services: sysctls: - net.ipv6.conf.all.disable_ipv6=0 - net.ipv6.conf.all.forwarding=1 + healthcheck: + test: ["CMD", "openvpn-check"] + interval: 10s + timeout: 5s + retries: 2 volumes: - /var/o-service/ovpn:/etc/openvpn diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index e182607..eb2931e 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -11,8 +11,15 @@ services: - "8080:8080" - "8081:8081" depends_on: - - trustvpn-db - - trustvpn-container + trustvpn-db: + condition: service_healthy + trustvpn-container: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "localhost:8080/api/auth/ststus"] + interval: 10s + timeout: 5s + retries: 2 volumes: - /var/run/docker.sock:/var/run/docker.sock - logdata:/app/logs @@ -25,6 +32,11 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 volumes: - pgdata:/var/lib/postgresql/data @@ -39,6 +51,11 @@ services: sysctls: - net.ipv6.conf.all.disable_ipv6=0 - net.ipv6.conf.all.forwarding=1 + healthcheck: + test: ["CMD", "openvpn-check"] + interval: 10s + timeout: 5s + retries: 2 volumes: - ovpndata:/etc/openvpn @@ -48,7 +65,8 @@ services: container_name: trustvpn-tests command: ["run", "/home/trustvpn-tests/postman.json"] depends_on: - - trustvpn-backend + trustvpn-backend: + condition: service_healthy volumes: pgdata: {} diff --git a/docker-compose.yml b/docker-compose.yml index 7f56770..62e8a62 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,7 @@ services: trustvpn-container: container_name: trustvpn-container - image: ghcr.io/maxirmx/trustvpn-container:0.2.4 + image: ghcr.io/maxirmx/trustvpn-container:latest command: ["trustvpn-container-if-start", "-u", "localhost"] ports: - "1194:1194/udp" diff --git a/trustvpn-backend/Controllers/ProfilesController.cs b/trustvpn-backend/Controllers/ProfilesController.cs index e134795..a947149 100644 --- a/trustvpn-backend/Controllers/ProfilesController.cs +++ b/trustvpn-backend/Controllers/ProfilesController.cs @@ -55,7 +55,7 @@ public async Task>> GetProfiles() { _logger.LogDebug("Get all profiles"); var res = await profileContext.Profiles.ToListAsync(); - _logger.LogDebug("Get all profiles returning:\n {res}\n", JsonSerializer.Serialize(res, JOptions.DefaultOptions)); + _logger.LogDebug("GetProfiles returning:\n {res}\n", JsonSerializer.Serialize(res, JOptions.DefaultOptions)); return res; } diff --git a/trustvpn-backend/Data/DbEnsure.cs b/trustvpn-backend/Data/DbEnsure.cs index fe176a3..cdf5905 100644 --- a/trustvpn-backend/Data/DbEnsure.cs +++ b/trustvpn-backend/Data/DbEnsure.cs @@ -150,7 +150,7 @@ public void Ensure(NpgsqlConnection connection) { _logger.LogInformation("Initializing database at 0.1.4"); Ensure_0_1_4(connection); - _logger.LogInformation("Database version 0.2.1"); + _logger.LogInformation("Database version 0.2.4"); PuVersionUpdate("0.2.1", connection); } catch (Exception ex) diff --git a/trustvpn-backend/Dockerfile b/trustvpn-backend/Dockerfile index 047a87f..94b44c5 100644 --- a/trustvpn-backend/Dockerfile +++ b/trustvpn-backend/Dockerfile @@ -6,11 +6,14 @@ WORKDIR /app EXPOSE 8080 EXPOSE 8081 +# Install curl +RUN apt-get update && apt-get install -y curl # This stage is used to build the service project FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src + COPY ["trustvpn-backend/trustvpn-backend.csproj", "trustvpn-backend/"] RUN dotnet restore "./trustvpn-backend/trustvpn-backend.csproj" COPY . . @@ -26,4 +29,5 @@ RUN dotnet publish "./trustvpn-backend.csproj" -c $BUILD_CONFIGURATION -o /app/p FROM base AS final WORKDIR /app COPY --from=publish /app/publish . + ENTRYPOINT ["dotnet", "trustvpn-backend.dll"] \ No newline at end of file