-
Notifications
You must be signed in to change notification settings - Fork 880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an ASP.NET app that runs in AWS ECS Fargate #532
Conversation
This adds an example of a basic ASP.NET app that runs in AWS ECS Fargate. This includes the infrastructure required to build and publish that application as a Docker container image to a private ECR repo, spin up a new ECS Fargate cluster, run a load balancer listening for external Internet traffic on port 80, and run services across all subnets in the default VPC for the target deployment region.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Several nits on formatting.
aws-cs-fargate/App/Program.cs
Outdated
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace dotnet_core_tutorial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the namespace to something .NET-y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, all of this is whatever dotnet new
spit out, fwiw.
"Microsoft": "Information" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, but I would omit this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! Was autogenerated by dotnet new
, wasn't sure what it is 😄
@@ -0,0 +1,2 @@ | |||
/bin/ | |||
/obj/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe merge .gitignore
s in the root folder of the example?
aws-cs-fargate/Infra/Program.cs
Outdated
// Create a SecurityGroup that permits HTTP ingress and unrestricted egress. | ||
var webSg = new Ec2.SecurityGroup("web-sg", new Ec2.SecurityGroupArgs { | ||
VpcId = vpc.Id, | ||
Egress = new[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new[]
is not required here and down below
aws-cs-fargate/Infra/Program.cs
Outdated
{ | ||
static Task<int> Main() | ||
{ | ||
return Deployment.RunAsync(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's common to put {
on a new line, also in our .NET code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, will fix those that are obvious.
Not quite sure what the style is meant to be in all places, e.g.
LoadBalancers = {
x
},
or
LoadBalancers =
{
x
},
Do we have plans to add style/linter checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my, the code is now twice as long! 🤦♂ But I shall resist the temptation to comment on style guidelines ... (oh wait, too late)
ImageName = appRepo.RepositoryUrl, | ||
Registry = new Docker.ImageRegistry { | ||
Server = appRepo.RepositoryUrl, | ||
Username = appRepoCreds.Apply(creds => creds[0]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to do appRepoCreds.Get(0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm: error CS1061: 'Output<string[]>' does not contain a definition for 'Get' and no accessible extension method 'Get' accepting a first argument of type 'Output<string[]>' could be found (are you missing a using directive or an assembly reference?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, should be GetAt
https://github.com/pulumi/pulumi/blob/master/sdk/dotnet/Pulumi/Core/OutputExtensions.cs#L22
aws-cs-fargate/Infra/Program.cs
Outdated
NetworkMode = "awsvpc", | ||
RequiresCompatibilities = new[] { "FARGATE" }, | ||
ExecutionRoleArn = taskExecRole.Arn, | ||
ContainerDefinitions = image.ImageName.Apply(imgName => @"[{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imgName
-> imageName
in .NET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
aws-cs-fargate/Infra/Program.cs
Outdated
|
||
// Export the resulting web address. | ||
return new Dictionary<string, object?>{ | ||
{ "url", webLb.DnsName.Apply(url => $"http://{url}") }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try changing to Output.Format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
aws-cs-fargate/README.md
Outdated
* [Install Pulumi](https://www.pulumi.com/docs/get-started/install/) | ||
* [Install .NET Core 3](https://dotnet.microsoft.com/download) | ||
* [Connect Pulumi to AWS](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/) (if your AWS CLI is | ||
configured, this will just work) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docker is another pre
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed.
2 changes. 9 unchanged | ||
``` | ||
|
||
Notice that `pulumi up` redeploys just the parts of the application/infrastructure that you've edited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does the re-publishing of the docker image work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does! I filed an issue for the lack of diffs (pulumi/pulumi-docker#131) which led me astray. The root problem was that I was using the ECR registry URL and not the built image's full name, which is just the ECR registry plus the hash. The hash is required to ensure the ECS service gets restarted upon a new image being pushed.
* Add an ASP.NET app that runs in AWS ECS Fargate This adds an example of a basic ASP.NET app that runs in AWS ECS Fargate. This includes the infrastructure required to build and publish that application as a Docker container image to a private ECR repo, spin up a new ECS Fargate cluster, run a load balancer listening for external Internet traffic on port 80, and run services across all subnets in the default VPC for the target deployment region. * Incorporate code review feedback * More brace movement
This adds an example of a basic ASP.NET app that runs in AWS ECS
Fargate. This includes the infrastructure required to build and publish
that application as a Docker container image to a private ECR repo,
spin up a new ECS Fargate cluster, run a load balancer listening for
external Internet traffic on port 80, and run services across all
subnets in the default VPC for the target deployment region.