WATCH OVERVIEW VIDEO
A Quick Video about how you can get started with the .NET 7 Web API Boilerplate. Watch this first!🔥
Subscribe to my YouTube
Makefile is included within this solution to give a better developer experience. Here are the makefile commands available for this solution.
Note the the makefile commands have to be executed at the root of the solution where Makefile file exists.
This would internally trigger the
dotnet build command against the
Start API #
This boots up the WebAPI at http://localhost:5001. Make sure that you have your API COnnection strings configured before you run this command.
This packs your Solution into a nuget package. The required .template.config folder is not included as part of the solution generated by the fsh tool, since the nuget part wont be used by many. You can get the folder in the fullstackhero dotnet webapi github repository.
Publish Docker Image #
Using .NET 7’s Built-In Containerization feature, this command builds the docker image for you using the
dotnet publish command internally. Here is how to setup the metadata of your docker image.
Navigate to src/Host/Host.csproj file and modify the following as per your requirement.
So, my image name is dotnet-webapi and the image will be tagged with 1.0.0 and latest.
Ensure that you have docker instances running before you execute this command.
Build & Publish to Docker Hub #
Similar to the previous command, you can build and push docker images directly to docker hub. In this case, you really dont need a docker instance running to build your docker image.
Note : Currently, the docker repository is set to mine. You can modify this to yours in the Makefile.
Terraform & AWS Deployments #
The terraform scripts are available at the
- Install Terraform
- Install & Configure AWS CLI profiles to allow terraform to provision resources for you. I have made a video about AWS Credentials Management.
The fullstackhero webapi boilerplate comes with built-in terraform scripts to provision docker containers with your webapi image to aws infrastructure with just one line of command!
Your images will be deployed to an ECS Container (FARGATE) and an RDS instance with postgresql engine would be spun up, to which your webapi container will connect to!
In brief, the terraform folder has 2 sub-folders.
The Backend folder is internally used by Terraform for state management and locking. There is a one-time setup you have to do against this folder. Navigate to the backend folder and run the command.
terraform apply -auto-approve
This would create the required S3 Buckets and DDB table for you.
Next is the
environments/staging folder. Here too, run the following command.
Once done, you can go the terraform.tfvars file to change the variables like,
- project tags
- docker image name
- ecs cluster name and so on.
After that, simply navigate back to the root of the solution and run the following commands.
Terraform Plan #
The below command gives you the plan of resources that needs to be created/modified/deleted in the aws world.
Terraform Apply #
This command will provision resources into AWS for you.
The resources are as follows:
- ECS Cluster
- ECS Task Definitions
- ECS Service
- Cloudwatch Log Groups
- RDS Instance with Postgresql Engine
- VPC & related resources
- Load Balancers
Once the command has completed, you will be getting an API URL, which you can use for testing!
Terraform Destroy #
The below commands destroys all the resources created, related to fullstackhero.
This command is to be executed from the Host Directory of the project.
dotnet ef migrations add <CommitMessage> --project .././Migrators/Migrators.<Provider>/ --context ApplicationDbContext -o Migrations/Application
CommitMessage : Enter a commit message here.
Provider : Enter the available DB Provider name. MSSQL , MySQL , PostgreSQL , Oracle
While adding migrations for a particular provider, ensure that you have configured a valid connection string to the provider’s database at both
Docker Compose #
This project also comes with examples of docker compose files, where you can spin up the webapi and database instance in your local containers with the following commands.
make dcu #docker compose up - Boots up the webapi & postgresql container
make dcd #docker compose down - Shuts down the webapi & postgresql containers
There are also examples for mysql & mssql variations of the fsh webapi. You can find the other docker-compose files under the ./docker-compose folder. Read more about fullstackhero’s docker-compose instructions & files here