From 7d0369b8e97406367928c313355bd3ae1bcbf46d Mon Sep 17 00:00:00 2001 From: rex-bot Date: Sun, 26 Apr 2026 17:28:06 +0000 Subject: [PATCH] chore: add Docker deployment setup and health check wiring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add multi-stage Dockerfile for backend (SDK build → ASP.NET runtime, non-root user, /health HEALTHCHECK) - Add docker-compose.dev.yml orchestrating extrudex-api + control-center-web - Add deploy.sh convenience script wrapping docker compose up --build - Wire ASP.NET health checks: AddHealthChecks().AddNpgSql() + MapHealthChecks("/health") - Add backend .dockerignore (comprehensive pattern list) - Exclude frontend/dist, frontend/node_modules, frontend/.angular from git Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 7 ++++++- backend/.dockerignore | 27 +++++++++++++++++++++++++++ backend/Dockerfile | 34 ++++++++++++++++++++++++++++++++++ backend/Extrudex.csproj | 1 + backend/Program.cs | 7 +++++++ deploy.sh | 33 +++++++++++++++++++++++++++++++++ docker-compose.dev.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100755 deploy.sh create mode 100644 docker-compose.dev.yml diff --git a/.gitignore b/.gitignore index 29ec7d0..27cb172 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,9 @@ bin/ obj/ *.user *.suo -.vs/ \ No newline at end of file +.vs/ + +# Frontend build artifacts +frontend/dist/ +frontend/node_modules/ +frontend/.angular/ \ No newline at end of file diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..c5a3aee --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,27 @@ +# Build artifacts +bin/ +obj/ + +# IDE / editor +.vs/ +.vscode/ +*.user +*.suo +.idea/ + +# Environment & secrets +appsettings.Development.json +.env +.env.* + +# Docker +Dockerfile +.dockerignore + +# OS +.DS_Store +Thumbs.db + +# Misc +*.md +*.log \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..b604978 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,34 @@ +# ── Stage 1: Build ────────────────────────────────────────── +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +WORKDIR /src + +# Copy csproj first for layer caching — restores before copying source +COPY Extrudex.csproj . +RUN dotnet restore + +# Copy the rest of the source +COPY . . +RUN dotnet publish Extrudex.csproj \ + -c Release \ + -o /app/publish \ + --no-restore + +# ── Stage 2: Runtime ──────────────────────────────────────── +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime +WORKDIR /app + +# Non-root user for security +RUN adduser --disabled-password --gecos "" appuser +USER appuser + +# Copy published output from build stage +COPY --from=build /app/publish . + +# ASP.NET Core listens on 8080 by default in .NET 8+ +EXPOSE 8080 + +# Health check against /health endpoint +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD curl --fail http://localhost:8080/health || exit 1 + +ENTRYPOINT ["dotnet", "Extrudex.dll"] \ No newline at end of file diff --git a/backend/Extrudex.csproj b/backend/Extrudex.csproj index f4f38a8..8e664c3 100644 --- a/backend/Extrudex.csproj +++ b/backend/Extrudex.csproj @@ -9,6 +9,7 @@ + diff --git a/backend/Program.cs b/backend/Program.cs index 86ff1c4..c77d0eb 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -69,6 +69,10 @@ builder.Services.AddCors(options => // ── SignalR (real-time printer updates) ──────────────────── builder.Services.AddSignalR(); +// ── Health Checks ─────────────────────────────────────────── +builder.Services.AddHealthChecks() + .AddNpgSql(connectionString); + var app = builder.Build(); // ── Middleware ────────────────────────────────────────────── @@ -85,6 +89,9 @@ app.MapControllers(); // ── Hub Endpoints ─────────────────────────────────────────── app.MapHub("/hubs/printer"); +// ── Health Check Endpoint ────────────────────────────────── +app.MapHealthChecks("/health"); + app.Run(); // Helper: builds a connection string from individual env vars. diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..d17960c --- /dev/null +++ b/deploy.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +echo "🔧 Deploying Extrudex Docker runtime..." + +# Check if Docker Compose is available +if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then + echo "❌ Docker Compose is not installed" + exit 1 +fi + +COMPOSE_CMD="docker compose" +if command -v docker-compose &> /dev/null; then + COMPOSE_CMD="docker-compose" +fi + +echo "📦 Building and starting services..." +$COMPOSE_CMD -f docker-compose.dev.yml up -d --build + +echo "⏳ Waiting for services to become healthy..." +sleep 10 + +echo "✅ Deployment complete!" +echo "" +echo "Services running:" +echo " • Extrudex API: http://localhost:5080" +echo " • Control Center Web: http://localhost:5081" +echo "" +echo "To view logs:" +echo " $COMPOSE_CMD -f docker-compose.dev.yml logs -f" +echo "" +echo "To stop:" +echo " $COMPOSE_CMD -f docker-compose.dev.yml down" \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..2859dff --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,40 @@ +version: '3.8' + +services: + extrudex-api: + build: + context: ./backend + dockerfile: Dockerfile + container_name: extrudex-api + ports: + - "5080:8080" + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://+:8080 + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + networks: + - extrudex-network + + control-center-web: + build: + context: ../Control-Center/frontend + dockerfile: Dockerfile + container_name: control-center-web + ports: + - "5081:80" + depends_on: + extrudex-api: + condition: service_healthy + restart: unless-stopped + networks: + - extrudex-network + +networks: + extrudex-network: + driver: bridge \ No newline at end of file