From b1b65d1f484a971f1813d558ce58d2a776921358 Mon Sep 17 00:00:00 2001 From: Sheuly Debnath Date: Sun, 23 Aug 2026 23:53:57 +0200 Subject: [PATCH] Add Docker containerization and local compose stack --- .dockerignore | 18 ++++++++++++++++++ Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1416bb7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +**/bin/ +**/obj/ + +.git/ +.github/ + +.vscode/ +.idea/ + +*.user +*.suo + +.DS_Store + +tests/ + +README.md +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6f73d77 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# ------------------------- +# Build stage +# ------------------------- +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build + +WORKDIR /src + +COPY ["src/TransitPulse.API/TransitPulse.API.csproj", "src/TransitPulse.API/"] +COPY ["src/TransitPulse.Application/TransitPulse.Application.csproj", "src/TransitPulse.Application/"] +COPY ["src/TransitPulse.Domain/TransitPulse.Domain.csproj", "src/TransitPulse.Domain/"] +COPY ["src/TransitPulse.Infrastructure/TransitPulse.Infrastructure.csproj", "src/TransitPulse.Infrastructure/"] + +RUN dotnet restore "src/TransitPulse.API/TransitPulse.API.csproj" + +COPY . . + +WORKDIR "/src/src/TransitPulse.API" + +RUN dotnet build "TransitPulse.API.csproj" \ + --configuration Release \ + --no-restore \ + --output /app/build + + +# ------------------------- +# Publish stage +# ------------------------- +FROM build AS publish + +RUN dotnet publish "TransitPulse.API.csproj" \ + --configuration Release \ + --no-restore \ + --output /app/publish \ + /p:UseAppHost=false + + +# ------------------------- +# Runtime stage +# ------------------------- +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final + +WORKDIR /app + +COPY --from=publish /app/publish . + +EXPOSE 8080 + +ENV ASPNETCORE_HTTP_PORTS=8080 + +ENTRYPOINT ["dotnet", "TransitPulse.API.dll"] \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..b6a5dfe --- /dev/null +++ b/compose.yml @@ -0,0 +1,40 @@ +services: + postgres: + image: postgres:17 + container_name: transitpulse-postgres + environment: + POSTGRES_DB: transitpulse + POSTGRES_USER: transitpulse + POSTGRES_PASSWORD: transitpulse_dev_password + ports: + - "5432:5432" + volumes: + - transitpulse-postgres-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U transitpulse -d transitpulse"] + interval: 5s + timeout: 5s + retries: 10 + + api: + build: + context: . + dockerfile: Dockerfile + image: transitpulse-api:local + container_name: transitpulse-api + depends_on: + postgres: + condition: service_healthy + environment: + ASPNETCORE_ENVIRONMENT: Development + ASPNETCORE_HTTP_PORTS: "8080" + ConnectionStrings__TransitPulseDb: "Host=postgres;Port=5432;Database=transitpulse;Username=transitpulse;Password=transitpulse_dev_password" + Jwt__SecretKey: "TransitPulse-Docker-Development-Secret-Key-2026" + Jwt__Issuer: "TransitPulse" + Jwt__Audience: "TransitPulseUsers" + Jwt__ExpiryMinutes: "60" + ports: + - "8080:8080" + +volumes: + transitpulse-postgres-data: