From 5c0b5315629420fa4939a52d51515db99e897f08 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Thu, 18 Sep 2025 16:52:25 -0400 Subject: [PATCH 1/6] add staging update bootstrap --- .../src/Infrastructure/Configuration.cs | 7 ++- .../src/Infrastructure/PipelineStack.cs | 55 ++++++++++--------- .../src/Infrastructure/PipelinesStage.cs | 27 ++++++++- .../src/Infrastructure/Program.cs | 2 +- .../SelfMutatingPipelineStack.cs | 12 +++- bootstrap.ps1 | 15 ++++- 6 files changed, 87 insertions(+), 31 deletions(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs index 3a52fea23..4b38578e7 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Configuration.cs @@ -29,9 +29,14 @@ internal class Configuration 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 string GitHubOwnerStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING"); + public string GitHubRepositoryStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME_STAGING"); + public string GitHubBranchStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING"); + public Ecrs Ecrs { get; } = new Ecrs(); public const string ProjectRoot = "LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure"; - public static readonly string ProjectName = "aws-lambda-container-images"; + public string ProjectName { get; } = "aws-lambda-container-images"; public readonly FrameworkConfiguration[] Frameworks = new[] { diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs index e47cb40b5..d4b0f2ce9 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs @@ -34,6 +34,9 @@ internal PipelineStack( string id, Configuration configuration, FrameworkConfiguration frameworkConfiguration, + string gitHubOwner, + string gitHubRepository, + string gitHubBranch, IStackProps props = null) : base(scope, id, props) { var sourceArtifact = new Artifact_(); @@ -47,11 +50,11 @@ internal PipelineStack( var sourceAction = new GitHubSourceAction(new GitHubSourceActionProps { - ActionName = configuration.GitHubRepository, + ActionName = gitHubRepository, Output = sourceArtifact, - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - Branch = configuration.GitHubBranch, + Owner = gitHubOwner, + Repo = gitHubRepository, + Branch = gitHubBranch, Trigger = GitHubTrigger.WEBHOOK, OauthToken = SecretValue.SecretsManager(configuration.GitHubTokenSecretName, new SecretsManagerSecretOptions { @@ -62,7 +65,7 @@ internal PipelineStack( var pipeline = new Pipeline(this, "CodePipeline", new PipelineProps { PipelineType = PipelineType.V2, - PipelineName = $"{Configuration.ProjectName}-{frameworkConfiguration.Framework}", + PipelineName = id, RestartExecutionOnUpdate = true, Stages = [ @@ -91,9 +94,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -130,9 +133,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -174,9 +177,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -224,9 +227,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -338,9 +341,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -387,9 +390,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { @@ -447,9 +450,9 @@ internal PipelineStack( }, Source = Source.GitHub(new GitHubSourceProps { - Owner = configuration.GitHubOwner, - Repo = configuration.GitHubRepository, - BranchOrRef = configuration.GitHubBranch + Owner = gitHubOwner, + Repo = gitHubRepository, + BranchOrRef = gitHubBranch }), EnvironmentVariables = new Dictionary { diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index cd1e6e022..6d6042069 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -13,13 +13,38 @@ public PipelinesStage( string id, Configuration configuration, IStageProps props = null) : base(scope, id, props) + { + // Create pipelines for main repository + CreatePipelinesForRepository(configuration, + configuration.ProjectName, + configuration.GitHubOwner, + configuration.GitHubRepository, + configuration.GitHubBranch); + + // Create pipelines for staging repository + CreatePipelinesForRepository(configuration, + $"{configuration.ProjectName}-staging", + configuration.GitHubOwnerStaging, + configuration.GitHubRepositoryStaging, + configuration.GitHubBranchStaging); + } + + private void CreatePipelinesForRepository( + Configuration configuration, + string pipelinePrefix, + string gitHubOwner, + string gitHubRepository, + string gitHubBranch) { for (var i = 0; i < configuration.Frameworks.Length; i++) { new PipelineStack(this, - configuration.Frameworks[i].Framework, + $"{pipelinePrefix}-{configuration.Frameworks[i].Framework}", configuration, configuration.Frameworks[i], + gitHubOwner, + gitHubRepository, + gitHubBranch, new StackProps { TerminationProtection = true, diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Program.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Program.cs index ae63d3630..75fe97257 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Program.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/Program.cs @@ -26,7 +26,7 @@ public static void Main(string[] args) new SelfMutatingPipelineStack( app, - Configuration.ProjectName, + configuration.ProjectName, configuration, new StackProps { diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/SelfMutatingPipelineStack.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/SelfMutatingPipelineStack.cs index 2c30a006d..e3140244a 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/SelfMutatingPipelineStack.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/SelfMutatingPipelineStack.cs @@ -65,9 +65,19 @@ internal SelfMutatingPipelineStack( { "AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL", new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value = System.Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL") ?? string.Empty } }, + { "AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING", + new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value = + System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING") ?? string.Empty } }, + { "AWS_LAMBDA_GITHUB_REPO_NAME_STAGING", + new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value = + System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME_STAGING") ?? string.Empty } }, + { "AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING", + new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value = + System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING") ?? string.Empty } }, }; // Self mutation + var pipeline = new CodePipeline(this, "SelfMutatingPipeline", new CodePipelineProps { PipelineName = id, @@ -114,6 +124,6 @@ internal SelfMutatingPipelineStack( }); // Add a stage in the pipeline to deploy the Lambda container pipelines - pipeline.AddStage(new PipelinesStage(this, Configuration.ProjectName, configuration)); + pipeline.AddStage(new PipelinesStage(this, configuration.ProjectName, configuration)); } } diff --git a/bootstrap.ps1 b/bootstrap.ps1 index 7cbeba9c1..d68182226 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -23,6 +23,15 @@ param ( [Parameter(Mandatory = $true, HelpMessage = "GitHub repository branch name.")] [string] $GitHubRepoBranch, + [Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository owner name.")] + [string] $GitHubRepoOwnerStaging, + + [Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository name.")] + [string] $GitHubRepoNameStaging, + + [Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository branch name.")] + [string] $GitHubRepoBranchStaging, + [Parameter(Mandatory = $false, HelpMessage = "ECR URI to store Stage images.")] [string] $StageEcr, @@ -44,9 +53,13 @@ $env:AWS_LAMBDA_GITHUB_REPO_OWNER = $GitHubRepoOwner $env:AWS_LAMBDA_GITHUB_REPO_NAME = $GitHubRepoName $env:AWS_LAMBDA_GITHUB_REPO_BRANCH = $GitHubRepoBranch +$env:AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING = $GitHubRepoOwnerStaging +$env:AWS_LAMBDA_GITHUB_REPO_NAME_STAGING = $GitHubRepoNameStaging +$env:AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING = $GitHubRepoBranchStaging + $env:AWS_LAMBDA_STAGE_ECR = $StageEcr $env:AWS_LAMBDA_BETA_ECRS = $BetaEcrs $env:AWS_LAMBDA_PROD_ECRS = $ProdEcrs npx cdk bootstrap --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess aws://$PipelineAccountId/$Region -npx cdk deploy --require-approval never --all \ No newline at end of file +npx cdk deploy --require-approval never --all From 3f3c0058f5fa510a0250e91564c5302eb6156898 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Fri, 19 Sep 2025 10:06:47 -0400 Subject: [PATCH 2/6] update stack names --- .../Infrastructure/src/Infrastructure/PipelinesStage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index 6d6042069..ecb19d434 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -16,14 +16,14 @@ public PipelinesStage( { // Create pipelines for main repository CreatePipelinesForRepository(configuration, - configuration.ProjectName, + string.Empty, configuration.GitHubOwner, configuration.GitHubRepository, configuration.GitHubBranch); // Create pipelines for staging repository CreatePipelinesForRepository(configuration, - $"{configuration.ProjectName}-staging", + "staging", configuration.GitHubOwnerStaging, configuration.GitHubRepositoryStaging, configuration.GitHubBranchStaging); From 1ac1f9f6bcd462f6c8af5dedadfe41d7faea7e24 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Fri, 19 Sep 2025 10:13:18 -0400 Subject: [PATCH 3/6] add comments --- .../Infrastructure/src/Infrastructure/PipelinesStage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index ecb19d434..58d67ed9b 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -16,14 +16,14 @@ public PipelinesStage( { // Create pipelines for main repository CreatePipelinesForRepository(configuration, - string.Empty, + string.Empty, // cloudformation already prepends the parent stack name which is configuration.ProjectName so we don't need to add it again configuration.GitHubOwner, configuration.GitHubRepository, configuration.GitHubBranch); // Create pipelines for staging repository CreatePipelinesForRepository(configuration, - "staging", + "staging", // cloudformation already prepends the parent stack name which is configuration.ProjectName so we just add staging prefix only configuration.GitHubOwnerStaging, configuration.GitHubRepositoryStaging, configuration.GitHubBranchStaging); From f4c16087428b396c55c5c97fa570533c61ba5a2a Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Fri, 19 Sep 2025 10:21:30 -0400 Subject: [PATCH 4/6] update naming --- .../Infrastructure/src/Infrastructure/PipelineStack.cs | 3 ++- .../Infrastructure/src/Infrastructure/PipelinesStage.cs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs index d4b0f2ce9..101c0f113 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelineStack.cs @@ -37,6 +37,7 @@ internal PipelineStack( string gitHubOwner, string gitHubRepository, string gitHubBranch, + string pipelineName, IStackProps props = null) : base(scope, id, props) { var sourceArtifact = new Artifact_(); @@ -65,7 +66,7 @@ internal PipelineStack( var pipeline = new Pipeline(this, "CodePipeline", new PipelineProps { PipelineType = PipelineType.V2, - PipelineName = id, + PipelineName = pipelineName, RestartExecutionOnUpdate = true, Stages = [ diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index 58d67ed9b..c44391ab7 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -38,6 +38,11 @@ private void CreatePipelinesForRepository( { for (var i = 0; i < configuration.Frameworks.Length; i++) { + + var pipelineName = string.IsNullOrEmpty(pipelinePrefix) + ? $"{configuration.ProjectName}-{configuration.Frameworks[i].Framework}" // "aws-lambda-container-images-net8" + : $"{configuration.ProjectName}-{pipelinePrefix}-{configuration.Frameworks[i].Framework}"; // "aws-lambda-container-images-staging-net8" + new PipelineStack(this, $"{pipelinePrefix}-{configuration.Frameworks[i].Framework}", configuration, @@ -45,6 +50,7 @@ private void CreatePipelinesForRepository( gitHubOwner, gitHubRepository, gitHubBranch, + pipelineName, new StackProps { TerminationProtection = true, From b45b0e9c68048c6d95bcdffc09c9585f98149912 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Fri, 19 Sep 2025 10:45:16 -0400 Subject: [PATCH 5/6] update naming convetion --- .../Infrastructure/src/Infrastructure/PipelinesStage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index c44391ab7..7decee46b 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -16,14 +16,14 @@ public PipelinesStage( { // Create pipelines for main repository CreatePipelinesForRepository(configuration, - string.Empty, // cloudformation already prepends the parent stack name which is configuration.ProjectName so we don't need to add it again + configuration.ProjectName, configuration.GitHubOwner, configuration.GitHubRepository, configuration.GitHubBranch); // Create pipelines for staging repository CreatePipelinesForRepository(configuration, - "staging", // cloudformation already prepends the parent stack name which is configuration.ProjectName so we just add staging prefix only + $"{configuration.ProjectName}-staging", configuration.GitHubOwnerStaging, configuration.GitHubRepositoryStaging, configuration.GitHubBranchStaging); From 8aaa48068965b37498321f187c71c4965ccfff7c Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Fri, 19 Sep 2025 10:47:17 -0400 Subject: [PATCH 6/6] update naming convetion --- .../Infrastructure/src/Infrastructure/PipelinesStage.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs index 7decee46b..49a65b068 100644 --- a/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs +++ b/LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure/PipelinesStage.cs @@ -39,9 +39,7 @@ private void CreatePipelinesForRepository( for (var i = 0; i < configuration.Frameworks.Length; i++) { - var pipelineName = string.IsNullOrEmpty(pipelinePrefix) - ? $"{configuration.ProjectName}-{configuration.Frameworks[i].Framework}" // "aws-lambda-container-images-net8" - : $"{configuration.ProjectName}-{pipelinePrefix}-{configuration.Frameworks[i].Framework}"; // "aws-lambda-container-images-staging-net8" + var pipelineName = $"{pipelinePrefix}-{configuration.Frameworks[i].Framework}"; new PipelineStack(this, $"{pipelinePrefix}-{configuration.Frameworks[i].Framework}",