ARG CERT_PASSWORD ARG DOTNET_SDK_VERSION=9.0.203 ARG DOTNET_RUNTIME_VERSION=9.0.4 ARG ALPINE_VERSION=3.21 ARG CONFIG_DIRECTORY_ARG=/config FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_VERSION}-alpine${ALPINE_VERSION}-amd64 AS build-env ARG CONFIG_DIRECTORY_ARG ENV CONFIG_DIRECTORY=$CONFIG_DIRECTORY_ARG ARG CERT_PASSWORD RUN mkdir $CONFIG_DIRECTORY \ && apk upgrade --update-cache --available \ && apk add openssl \ && rm -rf /var/cache/apk/* \ && dotnet dev-certs https --export-path /config/aspnetapp.pem --password "$CERT_PASSWORD" --format PEM FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_RUNTIME_VERSION}-alpine${ALPINE_VERSION}-amd64 ARG CONFIG_DIRECTORY_ARG ENV CONFIG_DIRECTORY=$CONFIG_DIRECTORY_ARG ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://+:80;https://+:443 ENV CERTIFICATES_DIRECTORY=/usr/local/share/ca-certificates ENV ASPNETCORE_Kestrel__Certificates__Default__Path=$CERTIFICATES_DIRECTORY/aspnetapp.crt ENV ASPNETCORE_Kestrel__Certificates__Default__KeyPath=$CERTIFICATES_DIRECTORY/aspnetapp.key ENV TZ=Europe/Brussels ARG CERT_PASSWORD RUN apk update \ && apk upgrade --available \ && apk add ca-certificates \ && apk add tzdata \ && rm -rf /var/cache/apk/* \ && mkdir -p $CERTIFICATES_DIRECTORY \ && mkdir -p $CONFIG_DIRECTORY COPY --from=build-env $CONFIG_DIRECTORY $CONFIG_DIRECTORY RUN cp $CONFIG_DIRECTORY/aspnetapp.pem $ASPNETCORE_Kestrel__Certificates__Default__Path \ && cp $CONFIG_DIRECTORY/aspnetapp.key $ASPNETCORE_Kestrel__Certificates__Default__KeyPath \ && rm -rf $CONFIG_DIRECTORY \ && chmod 755 $ASPNETCORE_Kestrel__Certificates__Default__Path \ && chmod +x $ASPNETCORE_Kestrel__Certificates__Default__Path \ && chown app:app $ASPNETCORE_Kestrel__Certificates__Default__Path \ && cat $ASPNETCORE_Kestrel__Certificates__Default__Path >> /etc/ssl/certs/ca-certificates.crt \ && chmod 755 $ASPNETCORE_Kestrel__Certificates__Default__KeyPath \ && chmod +x $ASPNETCORE_Kestrel__Certificates__Default__KeyPath \ && chown app:app $ASPNETCORE_Kestrel__Certificates__Default__KeyPath \ && update-ca-certificates ENV ASPNETCORE_Kestrel__Certificates__Default__Password=$CERT_PASSWORD EXPOSE 80 EXPOSE 443