|
1 | 1 | # Specify the base image for the build stage
|
2 | 2 | ARG DOTNET_VERSION=6.0
|
3 |
| -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build |
| 3 | +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-alpine AS build |
4 | 4 | ARG TARGETARCH
|
5 | 5 | ARG TARGETVARIANT
|
6 | 6 | WORKDIR /app
|
7 | 7 |
|
8 |
| -# Copy everything and restore as distinct layers |
9 |
| -COPY . ./ |
10 |
| -RUN dotnet restore Tv7Playlist.sln |
| 8 | +# Copy csproj and restore as distinct layers |
| 9 | +COPY ["Tv7Playlist/Tv7Playlist.csproj", "Tv7Playlist/"] |
| 10 | +COPY ["Tv7Playlist.Core/Tv7Playlist.Core.csproj", "Tv7Playlist.Core/"] |
| 11 | +COPY ["Tv7Playlist.Data/Tv7Playlist.Data.csproj", "Tv7Playlist.Data/"] |
| 12 | +RUN dotnet restore "Tv7Playlist/Tv7Playlist.csproj" |
11 | 13 |
|
| 14 | +# Copy everything else and build |
| 15 | +COPY . . |
12 | 16 | # Build and publish
|
13 | 17 | RUN if [ "$TARGETARCH" = "amd64" ]; then \
|
14 |
| - RID=linux-x64; \ |
| 18 | + RID=linux-musl-x64; \ |
15 | 19 | elif [ "$TARGETARCH" = "arm64" ]; then \
|
16 |
| - RID=linux-arm64; \ |
| 20 | + RID=linux-musl-arm64; \ |
17 | 21 | elif [ "$TARGETARCH" = "arm" ] && [ "$TARGETVARIANT" = "v7" ]; then \
|
18 |
| - RID=linux-arm; \ |
19 |
| - elif [ "$TARGETARCH" = "386" ]; then \ |
20 |
| - RID=linux-x86; \ |
| 22 | + RID=linux-musl-arm; \ |
21 | 23 | else \
|
22 | 24 | echo "Unsupported architecture: $TARGETARCH$TARGETVARIANT"; \
|
23 | 25 | exit 1; \
|
24 | 26 | fi && \
|
25 |
| - dotnet publish -c Release -o out --no-restore --self-contained false -r $RID Tv7Playlist.sln |
| 27 | + echo "Building for RID: $RID" && \ |
| 28 | + dotnet publish Tv7Playlist/Tv7Playlist.csproj -c Release -o out --no-restore \ |
| 29 | + --self-contained true \ |
| 30 | + -r $RID \ |
| 31 | + /p:PublishSingleFile=true \ |
| 32 | + /p:PublishTrimmed=false \ |
| 33 | + /p:IncludeNativeLibrariesForSelfExtract=true \ |
| 34 | + /p:InvariantGlobalization=true \ |
| 35 | + /p:UseSystemResourceKeys=true \ |
| 36 | + /p:IlcGenerateStackTraceData=false \ |
| 37 | + /p:IlcOptimizationPreference=Size \ |
| 38 | + /p:IlcDisableReflection=false \ |
| 39 | + /p:DebugType=None \ |
| 40 | + /p:DebugSymbols=false \ |
| 41 | + /p:StripSymbols=true \ |
| 42 | + /p:EnableCompressionInSingleFile=true |
26 | 43 |
|
27 |
| -# Build runtime image |
28 |
| -FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION} |
| 44 | +# Runtime stage |
| 45 | +FROM mcr.microsoft.com/dotnet/runtime-deps:${DOTNET_VERSION}-alpine |
29 | 46 | WORKDIR /app
|
30 |
| -RUN mkdir /data |
31 |
| - |
32 | 47 | COPY --from=build /app/out .
|
33 | 48 |
|
| 49 | +# Remove unnecessary files |
| 50 | +RUN find . -name '*.pdb' -type f -delete && \ |
| 51 | + find . -name '*.xml' -type f -delete && \ |
| 52 | + rm -rf *.dev.json |
| 53 | + |
| 54 | +# Create a non-root user and set up permissions |
| 55 | +RUN adduser -u 5678 --disabled-password --gecos "" appuser && \ |
| 56 | + mkdir -p /app/data && \ |
| 57 | + chown -R appuser:appuser /app |
| 58 | + |
| 59 | +USER appuser |
| 60 | + |
34 | 61 | ENV ASPNETCORE_URLS=http://+:80
|
| 62 | +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 |
35 | 63 | EXPOSE 80
|
36 | 64 |
|
37 |
| -VOLUME [ "/data" ] |
| 65 | +VOLUME [ "/app/data" ] |
38 | 66 |
|
39 |
| -ENTRYPOINT ["dotnet", "Tv7Playlist.dll"] |
| 67 | +ENTRYPOINT ["./Tv7Playlist"] |
0 commit comments