-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (52 loc) · 2.05 KB
/
Dockerfile
File metadata and controls
69 lines (52 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Multi-stage build for self-contained FilesAPI with embedded database
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Copy project files for dependency resolution
COPY ["FilesAPI/FilesAPI.csproj", "FilesAPI/"]
COPY ["Services/Services.csproj", "Services/"]
COPY ["Models/Models.csproj", "Models/"]
COPY ["Contracts/Contracts.csproj", "Contracts/"]
# Restore dependencies
RUN dotnet restore "FilesAPI/FilesAPI.csproj"
# Copy all source code
COPY . .
# Build the application
WORKDIR "/src/FilesAPI"
RUN dotnet build "FilesAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
# Publish the application as framework-dependent
RUN dotnet publish "FilesAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish \
--no-restore
# Final runtime stage - use minimal base image
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
# Install curl for health checks (optional)
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Create directories for application data and analytics
RUN mkdir -p /app/uploads /app/data /app/logs /app/wwwroot
# Copy published application
COPY --from=build /app/publish .
# Ensure analytics dashboard is available
RUN ls -la /app/wwwroot/ || echo "wwwroot directory contents:"
# Set environment variables for self-contained operation
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:8080
ENV DOTNET_RUNNING_IN_CONTAINER=true
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
# Configure for embedded database (LiteDB) instead of MongoDB
ENV USE_EMBEDDED_DATABASE=true
ENV DATABASE_PATH=/app/data/filesapi.db
ENV UPLOADS_PATH=/app/uploads
# Analytics configuration
ENV ANALYTICS_ENABLED=true
ENV ANALYTICS_RETENTION_DAYS=365
# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Expose port
EXPOSE 8080
ENTRYPOINT ["dotnet", "FilesAPI.dll"]