-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathdockerfile
71 lines (51 loc) · 1.65 KB
/
dockerfile
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
71
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR /app
EXPOSE 8080
LABEL org.opencontainers.image.authors="Łukasz Kurzyniec" \
org.opencontainers.image.title="HappyCode.NetCoreBoilerplate" \
org.opencontainers.image.description="Simple API written in .NET 8."
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
ENV \
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8
RUN apk add --upgrade --no-cache \
icu-data-full \
icu-libs \
tzdata \
curl
# --------------
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS restore
WORKDIR /work
ENV DOTNET_NOLOGO=true
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
COPY ./Directory.Build.props ./
COPY ./Directory.Packages.props ./
COPY src/*/*.csproj ./
RUN for projectFile in $(ls *.csproj); \
do \
mkdir -p ${projectFile%.*}/ && mv $projectFile ${projectFile%.*}/; \
done
RUN cd /work/HappyCode.NetCoreBoilerplate.Api && dotnet restore -r linux-musl-x64
COPY src .
# --------------
FROM restore AS publish
WORKDIR /work/HappyCode.NetCoreBoilerplate.Api
ENV DOTNET_NOLOGO=true
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
RUN dotnet publish -c Release -r linux-musl-x64 \
-o /app --no-restore
# --------------
FROM base AS final
COPY --from=publish /app .
ENV DOTNET_NOLOGO=true
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
ARG VERSION=2.0.0
ARG SHA=none
ENV HC_SHA=${SHA}
ENV HC_VERSION=${VERSION}
HEALTHCHECK --interval=5m --timeout=3s --start-period=10s --retries=1 \
CMD curl --fail http://localhost:8080/healthz/live || exit 1
RUN chown "$APP_UID":"$APP_UID" /app
USER $APP_UID
ENTRYPOINT ["dotnet", "HappyCode.NetCoreBoilerplate.Api.dll"]