From 16dff5b89db3da9b8f1592e4270895389a300617 Mon Sep 17 00:00:00 2001 From: Phil Asmar Date: Fri, 8 Nov 2024 13:44:26 -0500 Subject: [PATCH 1/2] feat: update lambda container images and test tool to .NET9 --- .autover/autover.json | 4 +- .../5f868ca3-fd40-4adc-8f0b-3b492276cc77.json | 11 + .../Images/{net7 => net9}/amd64/Dockerfile | 29 +- .../Images/{net7 => net9}/arm64/Dockerfile | 62 +- .../Infrastructure/README.md | 23 +- .../src/Infrastructure/Configuration.cs | 63 +- .../src/Infrastructure/DockerBuild/build.ps1 | 10 + .../Infrastructure/DockerBuild/buildspec.yml | 4 +- .../src/Infrastructure/Infrastructure.csproj | 4 +- .../src/Infrastructure/PipelineStack.cs | 908 +++++++++--------- .../src/Infrastructure/Program.cs | 41 +- .../Infrastructure/SmokeTests/buildspec.yml | 4 +- .../ImageFunction.SmokeTests.csproj | 6 +- .../test/ImageFunction/ImageFunction.csproj | 6 +- LambdaRuntimeDockerfiles/build.ps1 | 19 +- Tools/LambdaTestTool/README.md | 3 +- ...Amazon.Lambda.TestTool.BlazorTester.csproj | 22 +- ...Lambda.TestTool.BlazorTester60-pack.csproj | 2 +- ...Lambda.TestTool.BlazorTester80-pack.csproj | 2 +- ...ambda.TestTool.BlazorTester90-pack.csproj} | 10 +- .../Constants.cs | 4 +- .../Amazon.Lambda.TestTool.csproj | 24 +- .../Amazon.Lambda.TestTool/TestToolStartup.cs | 4 +- bootstrap.ps1 | 42 +- 24 files changed, 654 insertions(+), 653 deletions(-) create mode 100644 .autover/changes/5f868ca3-fd40-4adc-8f0b-3b492276cc77.json rename LambdaRuntimeDockerfiles/Images/{net7 => net9}/amd64/Dockerfile (75%) rename LambdaRuntimeDockerfiles/Images/{net7 => net9}/arm64/Dockerfile (62%) rename Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/{Amazon.Lambda.TestTool.BlazorTester70-pack.csproj => Amazon.Lambda.TestTool.BlazorTester90-pack.csproj} (79%) diff --git a/.autover/autover.json b/.autover/autover.json index 48140834e..446a27d0a 100644 --- a/.autover/autover.json +++ b/.autover/autover.json @@ -124,8 +124,8 @@ "Paths": [ "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester.csproj", "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester60-pack.csproj", - "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester70-pack.csproj", - "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj" + "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj", + "Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester90-pack.csproj" ] } ], diff --git a/.autover/changes/5f868ca3-fd40-4adc-8f0b-3b492276cc77.json b/.autover/changes/5f868ca3-fd40-4adc-8f0b-3b492276cc77.json new file mode 100644 index 000000000..516f112fc --- /dev/null +++ b/.autover/changes/5f868ca3-fd40-4adc-8f0b-3b492276cc77.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.TestTool.BlazorTester", + "Type": "Minor", + "ChangelogMessages": [ + "Update Lambda Test Tool to add a .NET9 target" + ] + } + ] +} \ No newline at end of file diff --git a/LambdaRuntimeDockerfiles/Images/net7/amd64/Dockerfile b/LambdaRuntimeDockerfiles/Images/net9/amd64/Dockerfile similarity index 75% rename from LambdaRuntimeDockerfiles/Images/net7/amd64/Dockerfile rename to LambdaRuntimeDockerfiles/Images/net9/amd64/Dockerfile index e62003224..1720840be 100644 --- a/LambdaRuntimeDockerfiles/Images/net7/amd64/Dockerfile +++ b/LambdaRuntimeDockerfiles/Images/net9/amd64/Dockerfile @@ -1,21 +1,23 @@ # Based on Docker image from: https://github.com/dotnet/dotnet-docker/ -ARG ASPNET_VERSION=7.0.20 -ARG ASPNET_SHA512=62ed9743972043a72e48d5aa2f7fdf3483cf684a32b051315004d1c778e9712bf66e5e7a97a5a53993fa8e92daf5bacaf2cdb3eae44bb9a9e25532b9a80f4f70 +ARG ASPNET_VERSION=9.0.0-rc.2.24474.3 +ARG ASPNET_SHA512=9370c26174cd7f1b2fef58e0a53041c94b7d5412f15ea5865fbc653a65b148b1f92e7992f147610a6ca2e92011ff28c43480ab26a6e7f8cd56f2189af0610be8 -ARG LAMBDA_RUNTIME_NAME=dotnet7 -ARG AMAZON_LINUX=public.ecr.aws/lambda/provided:al2 +ARG LAMBDA_RUNTIME_NAME=dotnet9 +ARG AMAZON_LINUX=public.ecr.aws/lambda/provided:al2023 FROM $AMAZON_LINUX AS base -FROM base AS builder-net7 +RUN dnf install libicu-67.1-7.amzn2023.0.3.x86_64 --assumeyes + +FROM base AS builder-net9 ARG ASPNET_VERSION ARG ASPNET_SHA512 WORKDIR /dotnet # Install tar and gzip for unarchiving downloaded tar.gz -RUN yum install tar gzip --assumeyes +RUN dnf install tar gzip --assumeyes # Install the ASP.NET Core shared framework RUN curl -SL --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$ASPNET_VERSION/aspnetcore-runtime-$ASPNET_VERSION-linux-x64.tar.gz \ @@ -25,22 +27,23 @@ RUN curl -SL --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/a && rm aspnetcore.tar.gz -FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS builder +FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim AS builder WORKDIR /src COPY ["Libraries/src/Amazon.Lambda.RuntimeSupport", "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/"] COPY ["Libraries/src/Amazon.Lambda.Core", "Repo/Libraries/src/Amazon.Lambda.Core/"] COPY ["buildtools/", "Repo/buildtools/"] -RUN dotnet restore "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" /p:TargetFrameworks=net7.0 +RUN dotnet restore "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" /p:TargetFrameworks=net9.0 WORKDIR "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport" -RUN dotnet build "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net7.0 --runtime linux-x64 -c Release -o /app/build +RUN dotnet build "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net9.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=net7.0 -f net7.0 --runtime linux-x64 --self-contained false -p:PublishReadyToRun=true -c Release -o /app/publish +RUN dotnet publish "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net9.0 -f net9.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.sh && \ - mv /app/publish/bootstrap.sh /app/publish/bootstrap && \ +RUN dos2unix /app/publish/bootstrap-al2023.sh && \ + mv /app/publish/bootstrap-al2023.sh /app/publish/bootstrap && \ chmod +x /app/publish/bootstrap +RUN touch /app/publish/empty-certificates.crt FROM base @@ -60,7 +63,7 @@ ENV \ # Disable Microsoft's telemetry collection DOTNET_CLI_TELEMETRY_OPTOUT=true -COPY --from=builder-net7 /dotnet ${DOTNET_ROOT} +COPY --from=builder-net9 /dotnet ${DOTNET_ROOT} COPY --from=publish /app/publish ${LAMBDA_RUNTIME_DIR} # Generate runtime-release file diff --git a/LambdaRuntimeDockerfiles/Images/net7/arm64/Dockerfile b/LambdaRuntimeDockerfiles/Images/net9/arm64/Dockerfile similarity index 62% rename from LambdaRuntimeDockerfiles/Images/net7/arm64/Dockerfile rename to LambdaRuntimeDockerfiles/Images/net9/arm64/Dockerfile index 83ddd8431..4857566a8 100644 --- a/LambdaRuntimeDockerfiles/Images/net7/arm64/Dockerfile +++ b/LambdaRuntimeDockerfiles/Images/net9/arm64/Dockerfile @@ -1,51 +1,23 @@ # Based on Docker image from: https://github.com/dotnet/dotnet-docker/ -ARG ASPNET_VERSION=7.0.20 -ARG ASPNET_SHA512=dfb1c1bef4d826defd3d995599a5c03e1bf1a64c65d98b675d6c05dbb7380d98233953e68d53fc5ebec60ad4ef75417073fb1fb3256a0176bb964f0e01161f6c +ARG ASPNET_VERSION=9.0.0-rc.2.24474.3 +ARG ASPNET_SHA512=b6de668ce8714476be78ae00ed66027f3a5b06d95c6768ad6b3eca4d0f396c91843267c0e8c03160b709a7acdcbc2b09047f1ec8d46309d40c3d31f849cc981f -ARG ICU_VERSION=68.1 -ARG ICU_MD5=6a99b541ea01f271257b121a4433c7c0 - -ARG LAMBDA_RUNTIME_NAME=dotnet7 -ARG AMAZON_LINUX=public.ecr.aws/lambda/provided:al2 +ARG LAMBDA_RUNTIME_NAME=dotnet9 +ARG AMAZON_LINUX=public.ecr.aws/lambda/provided:al2023 FROM $AMAZON_LINUX AS base -FROM base AS builder-libicu -WORKDIR / - -# Install depedencies to extract and build ICU library -RUN yum install -d1 -y \ - tar \ - gzip \ - make \ - gcc-c++ - -# Download, validate and extract ICU library -# https://github.com/unicode-org/icu/releases/tag/release-68-1 -ARG ICU_VERSION -ARG ICU_MD5 -RUN curl -SL https://github.com/unicode-org/icu/releases/download/release-${ICU_VERSION//./-}/icu4c-${ICU_VERSION//./_}-src.tgz -o icu-src.tgz \ - && echo "$ICU_MD5 icu-src.tgz" | md5sum -c - \ - && tar -xzf icu-src.tgz \ - && rm icu-src.tgz - -# Build ICU library -RUN mkdir /libicu -WORKDIR /icu/source/ -RUN ./configure --prefix=/libicu \ - && make \ - && make install - - -FROM base AS builder-net7 +RUN dnf install libicu-67.1-7.amzn2023.0.3.aarch64 --assumeyes + +FROM base AS builder-net9 ARG ASPNET_VERSION ARG ASPNET_SHA512 WORKDIR /dotnet # Install tar and gzip for unarchiving downloaded tar.gz -RUN yum install tar gzip --assumeyes +RUN dnf install tar gzip --assumeyes # Install the ASP.NET Core shared framework RUN curl -SL --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$ASPNET_VERSION/aspnetcore-runtime-$ASPNET_VERSION-linux-arm64.tar.gz \ @@ -55,25 +27,23 @@ RUN curl -SL --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/a && rm aspnetcore.tar.gz -FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS builder +FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim AS builder WORKDIR /src COPY ["Libraries/src/Amazon.Lambda.RuntimeSupport", "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/"] COPY ["Libraries/src/Amazon.Lambda.Core", "Repo/Libraries/src/Amazon.Lambda.Core/"] COPY ["buildtools/", "Repo/buildtools/"] -RUN dotnet restore "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" /p:TargetFrameworks=net7.0 +RUN dotnet restore "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" /p:TargetFrameworks=net9.0 WORKDIR "Repo/Libraries/src/Amazon.Lambda.RuntimeSupport" -RUN dotnet build "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net7.0 --runtime linux-arm64 -c Release -o /app/build +RUN dotnet build "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net9.0 --runtime linux-arm64 -c Release -o /app/build FROM builder AS publish -RUN dotnet publish "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net7.0 -f net7.0 --runtime linux-arm64 --self-contained false -p:PublishReadyToRun=true -c Release -o /app/publish +RUN dotnet publish "Amazon.Lambda.RuntimeSupport.csproj" /p:ExecutableOutputType=true /p:GenerateDocumentationFile=false /p:TargetFrameworks=net9.0 -f net9.0 --runtime linux-arm64 --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.sh && \ - mv /app/publish/bootstrap.sh /app/publish/bootstrap && \ +RUN dos2unix /app/publish/bootstrap-al2023.sh && \ + mv /app/publish/bootstrap-al2023.sh /app/publish/bootstrap && \ chmod +x /app/publish/bootstrap - -# Copy native dependencies -COPY --from=builder-libicu /libicu /app/publish +RUN touch /app/publish/empty-certificates.crt FROM base @@ -93,7 +63,7 @@ ENV \ # Disable Microsoft's telemetry collection DOTNET_CLI_TELEMETRY_OPTOUT=true -COPY --from=builder-net7 /dotnet ${DOTNET_ROOT} +COPY --from=builder-net9 /dotnet ${DOTNET_ROOT} COPY --from=publish /app/publish ${LAMBDA_RUNTIME_DIR} # Generate runtime-release file diff --git a/LambdaRuntimeDockerfiles/Infrastructure/README.md b/LambdaRuntimeDockerfiles/Infrastructure/README.md index 2ff713b79..d9400adce 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/README.md +++ b/LambdaRuntimeDockerfiles/Infrastructure/README.md @@ -8,7 +8,7 @@ Infrastructure project allows to create pipeline to build and push .NET Lambda R 2. [AWS Account and User](https://portal.aws.amazon.com/billing/signup) 3. [Node.js](https://nodejs.org/) 4. [AWS CDK Toolkit](https://www.npmjs.com/package/aws-cdk) -5. [.NET Core 3.1 SDK or above](https://dotnet.microsoft.com/download) +5. [.NET 8 SDK or above](https://dotnet.microsoft.com/download) ### Bootstrap @@ -17,28 +17,24 @@ Infrastructure project allows to create pipeline to build and push .NET Lambda R ```powershell .\bootstrap.ps1 ` -PipelineAccountId "AccountId" ` --CodeCommitAccountId "CodeCommitAccountId" ` --Profile "AccountProfile" ` --CodeCommitAccountProfile "CodeCommitAccountProfile" ` -Region "AwsRegion" ` --SourceRepositoryArn "arn:aws:codecommit:us-west-2:CodeCommitAccountId:aws-lambda-dotnet" ` --SourceBranchName "main" ` +-GitHubTokenSecretName "SecretName" ` +-GitHubTokenSecretKey "Key" ` +-GitHubRepoOwner "GitHubOwner" ` +-GitHubRepoName "GitHubRepo" ` +-GitHubRepoBranch "GitHubBranch" ` -StageEcr "AccountId.dkr.ecr.us-west-2.amazonaws.com" ` -BetaEcrs "AccountId.dkr.ecr.us-west-2.amazonaws.com;AccountId.dkr.ecr.us-west-2.amazonaws.com" ` -ProdEcrs "AccountId.dkr.ecr.us-west-2.amazonaws.com;AccountId.dkr.ecr.us-west-2.amazonaws.com" ` --EcrRepositoryName "awslambda/dotnet6.0-runtime;awslambda/dotnet7-runtime;awslambda/dotnet8-runtime" ` --TargetFramework "net6;net7;net8" ` --DotnetChannel "6.0;7.0;8.0" +-EcrRepositoryName "awslambda/dotnet6.0-runtime;awslambda/dotnet8-runtime;awslambda/dotnet9-runtime" ` +-TargetFramework "net6;net8;net9" ` +-DotnetChannel "6.0;8.0;9.0" ``` #### Notes - AWS Profiles used to execute `bootstrap.ps1` must have administrator access. - All resources used to bootstrap the pipeline must already exist. - `AccountId` is AWS AccountId used for deploying CDK App. - - `CodeCommitAccountId` is AWS AccountId that contains source repository. - - If the CodeCommit repository is in the same account, use the same account Id for `PipelineAccountId` and `CodeCommitAccountId`. - - When doing a cross-account deployment, you need to have AWS Profiles for both accounts. - - `bootstrap.ps1` will run 2 `cdk bootstrap` commands for the cross account deployments to establish a trust relationships between the accounts. This way, we do not require a separate IAM role to be created manually. ## Useful commands * `npx cdk bootstrap --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess` bootstrap this app @@ -46,4 +42,3 @@ Infrastructure project allows to create pipeline to build and push .NET Lambda R * `cdk deploy` deploy this stack to your default AWS account/region * `cdk diff` compare deployed stack with current state * `cdk synth` emits the synthesized CloudFormation template - diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs index 11d23036f..977de78c8 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs @@ -16,41 +16,38 @@ using System; using System.Collections.Generic; -namespace Infrastructure +namespace Infrastructure; + +internal class Configuration { - internal class Configuration - { - public string AccountId { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_ACCOUNT_ID"); - public string CodeCommitAccountId { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_CODECOMMIT_ACCOUNT_ID"); - public string Region { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_REGION"); + public string AccountId { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_ACCOUNT_ID"); + public string Region { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_REGION"); - public Source Source { get; } = new Source(); - public Ecrs Ecrs { get; } = new Ecrs(); - public readonly string[] EcrRepositoryNames = Environment.GetEnvironmentVariable("AWS_LAMBDA_ECR_REPOSITORY_NAME")?.Split(";"); - public const string ProjectRoot = "LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure"; - public const string ProjectName = "aws-lambda-container-images"; - public readonly string[] DockerARM64Images = new string[] { "net6", "net7", "net8" }; - // DotnetSdkVersions is used to specify a specific version of the .NET SDK to be installed on the CodeBuild image - // The default behavior is to specify a channel and that installs the latest version in that channel - // By specifying a specific .NET SDK version, you override the default channel behavior - public readonly Dictionary DotnetSdkVersions = new Dictionary { }; - public readonly Dictionary DockerBuildImages = new Dictionary { {"net6", "6.0-bullseye-slim"}, {"net7", "7.0-bullseye-slim"}, {"net8", "8.0-bookworm-slim"} }; - public readonly Dictionary BaseImageAMD64Tags = new Dictionary { { "net6", "contributed-base-image-x86_64" }, { "net7", "contributed-base-image-x86_64" }, { "net8", "contributed-base-image-x86_64" } }; - public readonly Dictionary BaseImageARM64Tags = new Dictionary { { "net6", "contributed-base-image-arm64" }, { "net7", "contributed-base-image-arm64" }, { "net8", "contributed-base-image-arm64" } }; - public readonly string[] Frameworks = Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_VERSION")?.Split(";"); - public readonly string[] Channels = Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL")?.Split(";"); - } + public string GitHubTokenSecretName { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_TOKEN_SECRET_NAME"); - internal class Source - { - public string RepositoryArn { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_SOURCE_REPOSITORY_ARN"); - public string BranchName { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_SOURCE_BRANCH_NAME"); - } + public string GitHubTokenSecretKey { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_TOKEN_SECRET_KEY"); + public string GitHubOwner { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER"); + public string GitHubRepository { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME"); + public string GitHubBranch { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH"); + public Ecrs Ecrs { get; } = new Ecrs(); + public readonly string[] EcrRepositoryNames = Environment.GetEnvironmentVariable("AWS_LAMBDA_ECR_REPOSITORY_NAME")?.Split(";"); + public const string ProjectRoot = "LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure"; + public static readonly string ProjectName = $"aws-lambda-container-images{Environment.GetEnvironmentVariable("AWS_LAMBDA_PIPELINE_NAME_SUFFIX")}"; + public readonly string[] DockerArm64Images = new string[] { "net6", "net8", "net9" }; + // DotnetSdkVersions is used to specify a specific version of the .NET SDK to be installed on the CodeBuild image + // The default behavior is to specify a channel and that installs the latest version in that channel + // By specifying a specific .NET SDK version, you override the default channel behavior + public readonly Dictionary DotnetSdkVersions = new Dictionary { }; + public readonly Dictionary DockerBuildImages = new Dictionary { {"net6", "6.0-bullseye-slim"}, {"net8", "8.0-bookworm-slim"}, {"net9", "9.0-bookworm-slim"} }; + public readonly Dictionary BaseImageAmd64Tags = new Dictionary { { "net6", "contributed-base-image-x86_64" }, { "net8", "contributed-base-image-x86_64" }, { "net9", "contributed-base-image-x86_64" } }; + public readonly Dictionary BaseImageArm64Tags = new Dictionary { { "net6", "contributed-base-image-arm64" }, { "net8", "contributed-base-image-arm64" }, { "net9", "contributed-base-image-arm64" } }; + public readonly string[] Frameworks = Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_VERSION")?.Split(";"); + public readonly string[] Channels = Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL")?.Split(";"); +} - internal class Ecrs - { - public string Stage { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_STAGE_ECR"); - public string Beta { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_BETA_ECRS"); - public string Prod { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PROD_ECRS"); - } +internal class Ecrs +{ + public string Stage { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_STAGE_ECR"); + public string Beta { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_BETA_ECRS"); + public string Prod { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_PROD_ECRS"); } \ No newline at end of file diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/build.ps1 b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/build.ps1 index 5e715d815..104a6b378 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/build.ps1 +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/build.ps1 @@ -28,6 +28,16 @@ if (!$?) $SourceNameTagPair = "aws-lambda-${Framework}:latest" +# Check if the repository exists +aws ecr describe-repositories --repository-names $EcrRepositoryName --region $StageRegion +if (!$?) { + Write-Output "Repository '$EcrRepositoryName' does not exist. Creating it..." + aws ecr create-repository --repository-name $EcrRepositoryName --region $StageRegion +} +else { + Write-Output "Repository '$EcrRepositoryName' exists." +} + # Build runtime docker image try { diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/buildspec.yml b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/buildspec.yml index c41dd8ae4..cb734f7bb 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/buildspec.yml +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/buildspec.yml @@ -2,6 +2,8 @@ version: 0.2 phases: pre_build: commands: + # Find and delete the global.json files that were added by CodeBuild. This causes issues when multiple SDKs are installed. + - find / -type f -name 'global.json' -delete - | if [ "$AWS_LAMBDA_DOTNET_SDK_VERSION" = "" ]; then curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel $AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL @@ -11,7 +13,7 @@ phases: - export PATH="$PATH:$HOME/.dotnet" - export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 - rm -rf /usr/bin/pwsh - - curl -sSL https://raw.githubusercontent.com/PowerShell/PowerShell/master/docker/InstallTarballPackage.sh | bash /dev/stdin $AWS_LAMBDA_POWERSHELL_VERSION + - dotnet tool install --global PowerShell --version $AWS_LAMBDA_POWERSHELL_VERSION build: commands: - pwsh LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/DockerBuild/build.ps1 diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Infrastructure.csproj b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Infrastructure.csproj index 4b4b61fbf..ddb058822 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Infrastructure.csproj +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Infrastructure.csproj @@ -2,14 +2,14 @@ Exe - netcoreapp3.1 + net8 Major - +