-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Configure Docker and test with simple endpoints #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: legal-assistant | ||
|
|
||
| services: | ||
| web-api: | ||
| image: ${DOCKER_REGISTRY-}webapi | ||
| container_name: web-api | ||
| build: | ||
| context: . | ||
| dockerfile: src/Web.Api/Dockerfile | ||
| ports: | ||
| - 10000:8080 # HTTP | ||
| - 10001:8081 # HTTPS | ||
| environment: | ||
| - ASPNETCORE_ENVIRONMENT=Development | ||
| - ConnectionStrings__DefaultConnection=Host=postgres;Database=legal-assistant;Username=postgres;Password=postgres;Port=5432 | ||
| depends_on: | ||
| - postgres | ||
|
|
||
| postgres: | ||
| image: postgres:17 | ||
| container_name: postgres | ||
| environment: | ||
| - POSTGRES_DB=legal-assistant | ||
| - POSTGRES_USER=postgres | ||
| - POSTGRES_PASSWORD=postgres | ||
| - TZ=UTC | ||
| - PGTZ=UTC | ||
| volumes: | ||
| - ./.containers/db:/var/lib/postgresql/data | ||
| ports: | ||
| - 5432:5432 | ||
|
|
||
| # seq: | ||
| # image: datalust/seq:2024.3 | ||
| # container_name: seq | ||
| # environment: | ||
| # - ACCEPT_EULA=Y | ||
| # ports: | ||
| # - 8081:80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using System.Diagnostics; | ||
| using System.Reflection; | ||
| using System.Security.Cryptography; | ||
|
|
||
| namespace Web.Api.Controllers.V1; | ||
|
|
||
| /// <summary> | ||
| /// Health check controller for system monitoring and testing | ||
| /// </summary> | ||
| [ApiController] | ||
| [Route("api/v{version:apiVersion}/[controller]")] | ||
| [ApiVersion("1.0")] | ||
| public sealed class HealthController : BaseController | ||
| { | ||
| private readonly ILogger<HealthController> _logger; | ||
|
|
||
| public HealthController(ILogger<HealthController> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Basic health check endpoint | ||
| /// </summary> | ||
| /// <returns>System health status</returns> | ||
| [HttpGet] | ||
| [ProducesResponseType(typeof(HealthResponse), StatusCodes.Status200OK)] | ||
| public IActionResult GetHealth() | ||
| { | ||
| _logger.LogInformation("Health check requested"); | ||
|
|
||
| var response = new HealthResponse | ||
| { | ||
| Status = "Healthy", | ||
| Timestamp = DateTime.UtcNow, | ||
| Version = GetApplicationVersion(), | ||
| Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production", | ||
| MachineName = Environment.MachineName, | ||
| ProcessId = Environment.ProcessId, | ||
| UpTime = GetUpTime() | ||
| }; | ||
|
|
||
| return Ok(response); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Detailed system information for testing | ||
| /// </summary> | ||
| /// <returns>Detailed system information</returns> | ||
| [HttpGet("detailed")] | ||
| [ProducesResponseType(typeof(DetailedHealthResponse), StatusCodes.Status200OK)] | ||
| public IActionResult GetDetailedHealth() | ||
| { | ||
| _logger.LogInformation("Detailed health check requested"); | ||
|
|
||
| var response = new DetailedHealthResponse | ||
| { | ||
| Status = "Healthy", | ||
| Timestamp = DateTime.UtcNow, | ||
| Version = GetApplicationVersion(), | ||
| Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production", | ||
| MachineName = Environment.MachineName, | ||
| ProcessId = Environment.ProcessId, | ||
| UpTime = GetUpTime(), | ||
| SystemInfo = new SystemInfo | ||
| { | ||
| OperatingSystem = Environment.OSVersion.ToString(), | ||
| ProcessorCount = Environment.ProcessorCount, | ||
| WorkingSet = Environment.WorkingSet, | ||
| RuntimeVersion = Environment.Version.ToString(), | ||
| CurrentDirectory = Environment.CurrentDirectory | ||
| }, | ||
| Services = new ServicesStatus | ||
| { | ||
| Database = "Connected", // TODO: Check actual database connection | ||
| Cache = "Available", // TODO: Check Redis if configured | ||
| ExternalApis = "Online" // TODO: Check external services | ||
| } | ||
| }; | ||
|
|
||
| return Ok(response); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Simple ping endpoint for quick availability check | ||
| /// </summary> | ||
| /// <returns>Pong response</returns> | ||
| [HttpGet("ping")] | ||
| [ProducesResponseType(typeof(PingResponse), StatusCodes.Status200OK)] | ||
| public IActionResult Ping() | ||
| { | ||
| return Ok(new PingResponse | ||
| { | ||
| Message = "Pong", | ||
| Timestamp = DateTime.UtcNow, | ||
| RequestId = HttpContext.TraceIdentifier | ||
| }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test endpoint that always returns success for testing purposes | ||
| /// </summary> | ||
| /// <returns>Test success response</returns> | ||
| [HttpGet("test")] | ||
| [ProducesResponseType(typeof(TestResponse), StatusCodes.Status200OK)] | ||
| public IActionResult Test() | ||
| { | ||
| _logger.LogInformation("Test endpoint called"); | ||
|
|
||
| return Ok(new TestResponse | ||
| { | ||
| Success = true, | ||
| Message = "Legal Assistant API is working correctly!", | ||
| Timestamp = DateTime.UtcNow, | ||
| TestData = new | ||
| { | ||
| RandomNumber = RandomNumberGenerator.GetInt32(1, 1000), | ||
| CurrentUser = User?.Identity?.Name ?? "Anonymous", | ||
| Headers = Request.Headers.Count, | ||
| Request.Method, | ||
| Path = Request.Path.Value | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private static string GetApplicationVersion() | ||
| { | ||
| var assembly = Assembly.GetExecutingAssembly(); | ||
| var version = assembly.GetName().Version; | ||
| return version?.ToString() ?? "Unknown"; | ||
| } | ||
|
|
||
| private static TimeSpan GetUpTime() | ||
| { | ||
| return DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime(); | ||
| } | ||
| } | ||
|
|
||
| #region Response Models | ||
|
|
||
| public sealed record HealthResponse | ||
| { | ||
| public required string Status { get; init; } | ||
| public required DateTime Timestamp { get; init; } | ||
| public required string Version { get; init; } | ||
| public required string Environment { get; init; } | ||
| public required string MachineName { get; init; } | ||
| public required int ProcessId { get; init; } | ||
| public required TimeSpan UpTime { get; init; } | ||
| } | ||
|
|
||
| public sealed record DetailedHealthResponse | ||
| { | ||
| public required string Status { get; init; } | ||
| public required DateTime Timestamp { get; init; } | ||
| public required string Version { get; init; } | ||
| public required string Environment { get; init; } | ||
| public required string MachineName { get; init; } | ||
| public required int ProcessId { get; init; } | ||
| public required TimeSpan UpTime { get; init; } | ||
| public required SystemInfo SystemInfo { get; init; } | ||
| public required ServicesStatus Services { get; init; } | ||
| } | ||
|
|
||
| public sealed record SystemInfo | ||
| { | ||
| public required string OperatingSystem { get; init; } | ||
| public required int ProcessorCount { get; init; } | ||
| public required long WorkingSet { get; init; } | ||
| public required string RuntimeVersion { get; init; } | ||
| public required string CurrentDirectory { get; init; } | ||
| } | ||
|
|
||
| public sealed record ServicesStatus | ||
| { | ||
| public required string Database { get; init; } | ||
| public required string Cache { get; init; } | ||
| public required string ExternalApis { get; init; } | ||
| } | ||
|
|
||
| public sealed record PingResponse | ||
| { | ||
| public required string Message { get; init; } | ||
| public required DateTime Timestamp { get; init; } | ||
| public required string RequestId { get; init; } | ||
| } | ||
|
|
||
| public sealed record TestResponse | ||
| { | ||
| public required bool Success { get; init; } | ||
| public required string Message { get; init; } | ||
| public required DateTime Timestamp { get; init; } | ||
| public required object TestData { get; init; } | ||
| } | ||
|
|
||
| #endregion | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # This Docker file uses the .NET 8 runtime | ||
| FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
| USER app | ||
| WORKDIR /app | ||
| EXPOSE 8080 | ||
| EXPOSE 8081 | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
| ARG BUILD_CONFIGURATION=Release | ||
| WORKDIR /src | ||
| COPY ["Directory.Build.props", "."] | ||
| COPY ["src/Web.Api/Web.Api.csproj", "src/Web.Api/"] | ||
| COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"] | ||
| COPY ["src/Application/Application.csproj", "src/Application/"] | ||
| COPY ["src/Domain/Domain.csproj", "src/Domain/"] | ||
| RUN dotnet restore "./src/Web.Api/Web.Api.csproj" | ||
| COPY . . | ||
| WORKDIR "/src/src/Web.Api" | ||
| RUN dotnet build "./Web.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
|
||
| FROM build AS publish | ||
| ARG BUILD_CONFIGURATION=Release | ||
| RUN dotnet publish "./Web.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
|
||
| FROM base AS final | ||
| WORKDIR /app | ||
| COPY --from=publish /app/publish . | ||
| ENTRYPOINT ["dotnet", "Web.Api.dll"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.