-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
53 lines (40 loc) · 1.44 KB
/
Dockerfile.api
File metadata and controls
53 lines (40 loc) · 1.44 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
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy solution and project files
COPY services/SoundHub.sln .
COPY services/SoundHub.Api/*.csproj ./SoundHub.Api/
COPY services/SoundHub.Application/*.csproj ./SoundHub.Application/
COPY services/SoundHub.Domain/*.csproj ./SoundHub.Domain/
COPY services/SoundHub.Infrastructure/*.csproj ./SoundHub.Infrastructure/
COPY services/tests/SoundHub.Tests/*.csproj ./tests/SoundHub.Tests/
# Copy source code
COPY services/ ./src/
# Restore dependencies
RUN dotnet restore
# Build and publish
RUN dotnet publish src/SoundHub.Api/SoundHub.Api.csproj -c Release -o /app/publish
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
# Install curl for health checks
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Copy published app
COPY --from=build /app/publish .
# Create app user
RUN adduser --disabled-password --gecos "" appuser
# Create data directory
RUN mkdir -p /data && chown -R appuser:appuser /data
# Run as non-root
USER appuser
# Expose ports
EXPOSE 5001 5001
# Set environment variables
ENV ASPNETCORE_URLS=http://+:5001
ENV ASPNETCORE_ENVIRONMENT=Production
ENV DevicesFilePath=/data/devices.json
ENV SecretsFilePath=/data/secrets.json
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:5001/health || exit 1
ENTRYPOINT ["dotnet", "SoundHub.Api.dll"]