Files
ChatBot/ChatBot/Dockerfile
Leonid Pershin 96026fb69e
Some checks failed
SonarQube / Build and analyze (pull_request) Failing after 2m58s
fix sec
2025-10-22 04:05:04 +03:00

48 lines
1.2 KiB
Docker

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy project file
COPY ChatBot.csproj ./
# Restore dependencies
RUN dotnet restore
# Copy all source files
COPY . .
# Build the application
RUN dotnet build -c Release -o /app/build
# Publish stage
FROM build AS publish
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
WORKDIR /app
# Install PostgreSQL client, create user, and prepare directories
RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client && rm -rf /var/lib/apt/lists/* \
&& groupadd -r appuser && useradd -r -g appuser appuser \
&& mkdir -p /app/logs
# Copy published application (safe: only contains compiled output from dotnet publish)
COPY --from=publish /app/publish .
# Set ownership after copying files
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose ports (if needed for health checks or metrics)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD dotnet ChatBot.dll --health-check || exit 1
# Run the application
ENTRYPOINT ["dotnet", "ChatBot.dll"]