public WorkshopPipelineStack(Constructs.Construct scope = null, string id = null, IStackProps props = null) : base(scope, id, props) { var repo = new Repository(this, "WorkshopRepo", new RepositoryProps { RepositoryName = "WorkshopRepo" }); var sourceArtifact = new Artifact_(); var cloudAssemblyArtifact = new Artifact_(); var pipeline = new CdkPipeline(this, "Pipeline", new CdkPipelineProps { PipelineName = "WorkshopPipeline", CloudAssemblyArtifact = cloudAssemblyArtifact, SourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps { ActionName = "CodeCommit", Output = sourceArtifact, Repository = repo }), SynthAction = SimpleSynthAction.StandardNpmSynth(new StandardNpmSynthOptions { SourceArtifact = sourceArtifact, CloudAssemblyArtifact = cloudAssemblyArtifact, InstallCommand = "npm install -g aws-cdk" + " && wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb" + " && dpkg -i packages-microsoft-prod.deb" + " && apt-get update" + " && apt-get install -y dotnet-sdk-3.1", BuildCommand = "dotnet build src" }) }); var deploy = new WorkshopPipelineStage(this, "Deploy"); var deployStage = pipeline.AddApplicationStage(deploy); }
internal PipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { Artifact_ sourceArtifact = new Artifact_(); Artifact_ cloudAssemblyArtifact = new Artifact_(); CdkPipeline pipeline = new CdkPipeline(this, "LambdaApiSolutionPipeline", new CdkPipelineProps() { CloudAssemblyArtifact = cloudAssemblyArtifact, PipelineName = "LambdaApiSolutionPipeline", SourceAction = new GitHubSourceAction(new GitHubSourceActionProps() { ActionName = "GitHubSource", Output = sourceArtifact, OauthToken = SecretValue.SecretsManager(Constants.GitHubTokenSecretsManagerId), Owner = Constants.Owner, Repo = Constants.RepositoryName, Branch = Constants.Branch, Trigger = GitHubTrigger.POLL }), SynthAction = new SimpleSynthAction(new SimpleSynthActionProps() { Environment = new BuildEnvironment { // required for .NET 5 // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html BuildImage = LinuxBuildImage.STANDARD_5_0 }, SourceArtifact = sourceArtifact, CloudAssemblyArtifact = cloudAssemblyArtifact, Subdirectory = "LambdaApiSolution", InstallCommands = new[] { "npm install -g aws-cdk" }, BuildCommands = new[] { "dotnet build src/LambdaApiSolution.sln" }, SynthCommand = "cdk synth" }) }); CdkStage developmentStage = pipeline.AddApplicationStage(new SolutionStage(this, "Development")); CdkStage testStage = pipeline.AddApplicationStage(new SolutionStage(this, "Test")); testStage.AddManualApprovalAction(new AddManualApprovalOptions() { ActionName = "PromoteToProduction" }); CdkStage productionStage = pipeline.AddApplicationStage(new SolutionStage(this, "Production")); }
public WorkshopPipelineStack(Construct parent, string id, IStackProps props = null) : base(parent, id, props) { // Creates a CodeCommit repository called 'WorkshopRepo' var repo = new Repository(this, "WorkshopRepo", new RepositoryProps { RepositoryName = "WorkshopRepo" }); // Defines the artifact representing the sourcecode var sourceArtifact = new Artifact_(); // Defines the artifact representing the cloud assembly // (cloudformation template + all other assets) var cloudAssemblyArtifact = new Artifact_(); // The basic pipeline declaration. This sets the initial structure // of our pipeline var pipeline = new CdkPipeline(this, "Pipeline", new CdkPipelineProps { PipelineName = "WorkshopPipeline", CloudAssemblyArtifact = cloudAssemblyArtifact, // Generates the source artifact from the repo we created in the last step SourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps { ActionName = "CodeCommit", // Any Git-based source control Output = sourceArtifact, // Indicates where the artifact is stored Repository = repo // Designates the repo to draw code from }), // Builds our source code outlined above into a could assembly artifact SynthAction = SimpleSynthAction.StandardNpmSynth(new StandardNpmSynthOptions { SourceArtifact = sourceArtifact, // Where to get source code to build CloudAssemblyArtifact = cloudAssemblyArtifact, // Where to place built source InstallCommands = new [] { "npm install -g aws-cdk", "sudo apt-get install -y dotnet-sdk-3.1" }, BuildCommands = new [] { "dotnet build" } // Language-specific build cmd }) }); var deploy = new WorkshopPipelineStage(this, "Deploy"); var deployStage = pipeline.AddApplicationStage(deploy); deployStage.AddActions(new ShellScriptAction(new ShellScriptActionProps { ActionName = "TestViewerEndpoint", UseOutputs = new Dictionary <string, StackOutput> { { "ENDPOINT_URL", pipeline.StackOutput(deploy.HCViewerUrl) } }, Commands = new string[] { "curl -Ssf $ENDPOINT_URL" } })); deployStage.AddActions(new ShellScriptAction(new ShellScriptActionProps { ActionName = "TestAPIGatewayEndpoint", UseOutputs = new Dictionary <string, StackOutput> { { "ENDPOINT_URL", pipeline.StackOutput(deploy.HCEndpoint) } }, Commands = new string[] { "curl -Ssf $ENDPOINT_URL/", "curl -Ssf $ENDPOINT_URL/hello", "curl -Ssf $ENDPOINT_URL/test" } })); }