.NET WebAPI project with basic authentication configured using MySQL Database, RESTful API, and OpenAI API(ChatGPT).
Requirements:
- .NET 7 SDK installed.
- Docker installed. (Required only for MySQL Database, if you have already MySQL installed, you can skip to step 3 of Running the app but you need to update the
appsettings.Development.jsonconnection strings)
- Using Docker secrets, in the root of the project create a text file named
db_root_password.txtand fill the content as the database root password, you should set the password totoor12345, if you choose something else you need to update theappsettings.Development.json! - Run
docker-compose up -dto add & install MySQL container to Docker.
The application uses .NET "Secret manager" More info can be found here
cdintoAPIproject / folder and run the following command to set up the required secret key for this app:dotnet user-secrets set "OpenAPIKey" "[Value]"
This command will create a secrets.json on your local machine that will be used only for this app!
As mentioned in the documentation, that will be stored in:
- For windows -
%APPDATA%\Microsoft\UserSecrets\0889f9dd-f77a-406d-9163-55089035a422\secrets.json - For Linux/macOs -
~/.microsoft/usersecrets/0889f9dd-f77a-406d-9163-55089035a422/secrets.json
- Run
dotnet watch --project .\API\or any other running command, just make sure you run theAPIas an entry project.
The application is configured to be deployed and hosted in AWS Elastic Beanstalk using CodePipeline together with CodeBuild and CodeDeploy services to archive CI/CD a software development best practice and in order to prevent too frequent deployments it has been set up to track any changes to production branch, so any change to production branch will trigger a new deployment process.
To trigger a new deployment process:
- Do any changes to
masterbranch and test it, make sure it works, once that ready make agit commit. - Switch to
productionbranch then make agit merge masterto sync with the master branch. - Upload the changed code to
productionbranch usinggit push -u origin productioncommand. - Done. Switch back to
masterto avoid mistakes.
- https://aws.amazon.com/blogs/devops/building-net-7-applications-with-aws-codebuild/ - as for the current project building time, support for
.NET 7.0on AWS yet to be released and a manual installation is required and archived by connecting to the AWS Elastic Beanstalk instance withSSHClient using AWS EC2 service with aKey Pair. - https://codewithmukesh.com/blog/deploying-aspnet-core-web-api-to-aws-elastic-beanstalk-using-aws-codepipeline/
http://todo-ai-server.us-east-1.elasticbeanstalk.com/swagger/index.html