-
Notifications
You must be signed in to change notification settings - Fork 497
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (58 loc) · 3.4 KB
/
Dockerfile
File metadata and controls
77 lines (58 loc) · 3.4 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Based on Docker image from: https://github.com/dotnet/dotnet-docker/
ARG ASPNET_VERSION=8.0.25
ARG ASPNET_SHA512=ddb66ac366252ab382271241b3e53a75201d2c848c9ec870a27fb178a6db18e4d949b9896a3d8530d03d255f4fd51d635367bedda3d9f3c677cb596784dbcb9c
ARG LAMBDA_RUNTIME_NAME=dotnet8
ARG AMAZON_LINUX=public.ecr.aws/lambda/provided:al2023
FROM $AMAZON_LINUX AS base
RUN dnf install libicu-67.1-7.amzn2023.0.4.x86_64 --assumeyes
FROM base AS builder-net8
ARG ASPNET_VERSION
ARG ASPNET_SHA512
WORKDIR /dotnet
# Install tar and gzip for unarchiving downloaded tar.gz
RUN dnf install tar gzip --assumeyes
# Install the ASP.NET Core shared framework
RUN curl -SL --output aspnetcore.tar.gz https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$ASPNET_VERSION/aspnetcore-runtime-$ASPNET_VERSION-linux-x64.tar.gz \
&& aspnetcore_sha512=$ASPNET_SHA512 \
&& echo "$aspnetcore_sha512 aspnetcore.tar.gz" | sha512sum -c - \
&& tar -ozxf aspnetcore.tar.gz -C /dotnet \
&& rm aspnetcore.tar.gz
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS builder
WORKDIR /src
COPY ["Libraries/src/Amazon.Lambda.RuntimeSupport", "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/"]
COPY ["Libraries/src/SnapshotRestore.Registry", "Repo/Libraries/src/SnapshotRestore.Registry/"]
COPY ["Libraries/src/Amazon.Lambda.Core", "Repo/Libraries/src/Amazon.Lambda.Core/"]
COPY ["Libraries/src/SnapshotRestore.Registry", "Repo/Libraries/src/SnapshotRestore.Registry/"]
COPY ["buildtools/", "Repo/buildtools/"]
RUN dotnet restore "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" /p:TargetFrameworks=net8.0
WORKDIR "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport"
RUN dotnet build "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net8.0 --runtime linux-x64 -c Release -o /app/build
FROM builder AS publish
RUN dotnet publish "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net8.0 -f net8.0 --runtime linux-x64 --self-contained false -p:PublishReadyToRun=true -c Release -o /app/publish
RUN apt-get update && apt-get install -y dos2unix
RUN dos2unix /app/publish/bootstrap.net8.sh && \
mv /app/publish/bootstrap.net8.sh /app/publish/bootstrap && \
chmod +x /app/publish/bootstrap
RUN touch /app/publish/empty-certificates.crt
FROM base
ARG ASPNET_VERSION
ARG LAMBDA_RUNTIME_NAME
ENV \
# Export .NET version as environment variable
DOTNET_VERSION=$ASPNET_VERSION \
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true \
# Lambda is opinionated about installing tooling under /var
DOTNET_ROOT=/var/lang/bin \
# Don't display welcome message on first run
DOTNET_NOLOGO=true \
# Disable Microsoft's telemetry collection
DOTNET_CLI_TELEMETRY_OPTOUT=true
COPY --from=builder-net8 /dotnet ${DOTNET_ROOT}
COPY --from=publish /app/publish ${LAMBDA_RUNTIME_DIR}
# Generate runtime-release file
RUN export BUILD_TIMESTAMP=$(printf '%x' $(date +%s)) && \
export LOGGING_PROTOCOL="LOGGING=amzn-stdout-tlv" && \
export LAMBDA_RUNTIME_NAME="LAMBDA_RUNTIME_NAME=${LAMBDA_RUNTIME_NAME}" && \
echo -e "NAME=dotnet\nVERSION=${ASPNET_VERSION}-${BUILD_TIMESTAMP}\n${LOGGING_PROTOCOL}\n${LAMBDA_RUNTIME_NAME}\n" > ${LAMBDA_RUNTIME_DIR}/runtime-release
# Entrypoint is inherited from public.ecr.aws/lambda/provided