-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (40 loc) · 1.49 KB
/
Dockerfile
File metadata and controls
54 lines (40 loc) · 1.49 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
# Dockerfile for Terminplaner API
# Multi-stage build for optimized production image
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy project files
COPY ["TerminplanerApi/TerminplanerApi.csproj", "TerminplanerApi/"]
COPY ["TerminplanerApi.Tests/TerminplanerApi.Tests.csproj", "TerminplanerApi.Tests/"]
# Restore dependencies
RUN dotnet restore "TerminplanerApi/TerminplanerApi.csproj"
# Copy remaining source code
COPY TerminplanerApi/ TerminplanerApi/
COPY TerminplanerApi.Tests/ TerminplanerApi.Tests/
# Build and test
WORKDIR /src/TerminplanerApi
RUN dotnet build "TerminplanerApi.csproj" -c Release -o /app/build
# Run tests
WORKDIR /src
RUN dotnet test "TerminplanerApi.Tests/TerminplanerApi.Tests.csproj" -c Release --no-restore
# Publish stage
WORKDIR /src/TerminplanerApi
RUN dotnet publish "TerminplanerApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
# Create non-root user for security
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Copy published app from build stage
COPY --from=build /app/publish .
# Expose port
EXPOSE 5215
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5215/api/appointments || exit 1
# Set environment variables
ENV ASPNETCORE_URLS=http://+:5215
ENV ASPNETCORE_ENVIRONMENT=Production
# Run the application
ENTRYPOINT ["dotnet", "TerminplanerApi.dll"]