-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (52 loc) · 1.59 KB
/
Dockerfile
File metadata and controls
70 lines (52 loc) · 1.59 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
70
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
# Set working directory
WORKDIR /app
# Copy project files
COPY Menlo.slnx ./
COPY Directory.Build.props ./
COPY Directory.Packages.props ./
# Copy source code
COPY src/ ./src/
# Restore dependencies
RUN dotnet restore
# Build the application
RUN dotnet build --no-restore --configuration Release
# Test stage (optional - can be skipped in production builds)
FROM build AS test
RUN dotnet test --no-build --configuration Release --verbosity normal
# Publish stage
FROM build AS publish
RUN dotnet publish src/api/Menlo.Api/Menlo.Api.csproj \
--no-build \
--configuration Release \
--output /app/publish \
--self-contained false \
--verbosity normal
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
# Install curl for health checks
RUN apt-get update && \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/*
# Create app user (use shadow utils commands)
RUN groupadd --system --gid 1001 appgroup && \
useradd --system --uid 1001 --gid 1001 --create-home appuser
# Set working directory
WORKDIR /app
# Copy published application
COPY --from=publish /app/publish .
# Change ownership to app user
RUN chown -R appuser:appgroup /app
# Switch to app user
USER appuser
# Expose port
EXPOSE 8080
# Configure ASP.NET Core
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Start the application
ENTRYPOINT ["dotnet", "Menlo.Api.dll"]