MakeFile Commands

Here are some important MakeFile Commands that are to be used along with fullstackhero.

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.

Build

make build

This would internally trigger the dotnet build command against the ./src/Host/Host.csproj file.

Start API

make start

This boots up the WebAPI at http://localhost:5001. Make sure that you have your API COnnection strings configured before you run this command.

Nuget

make nuget

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

make publish

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.

<PropertyGroup>
    <ContainerImageName>dotnet-webapi</ContainerImageName>
    <ContainerImageTags>1.0.0;latest</ContainerImageTags>
    <PublishProfile>DefaultContainer</PublishProfile>
</PropertyGroup>

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.

make publish-to-hub

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 ./terraform folder.

Prerequisites

  • 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.

  • backend
  • environments/staging

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 init
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.

terraform init

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.

make tp

Terraform Apply

This command will provision resources into AWS for you.

make ta

The resources are as follows:

  1. ECS Cluster
  2. ECS Task Definitions
  3. ECS Service
  4. Cloudwatch Log Groups
  5. RDS Instance with Postgresql Engine
  6. VPC & related resources
  7. 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.

make td

Migrations

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 src/Host/Configurations/database.json and src/Host/Configurations/hangfire.json.

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

Like fullstackhero? ❤️

Here is what you can do to show your support!

Buy me a Coffee ☕ Sponsor 😍