Automatic deploy your ASP.NET 6.0 GitHub repository to an DigitalOcean App. Auto-deploy your app from your GitHub source by committing and pushing your changes to your GitHub repository.
Create a new ASP.NET 6.0 web application
- Open your Visual Studio and create a new ASP.NET MVC application.
- In my case I choose .NET 6.0 framework
- Check the Enable Docker checkbox.
- Create the project.
- Open the
Views/Home/Index.cshtml
file and add the following code.
Create a new GitHub repository from our project
- Now we'll create a new GitHub repository from our project. You can do this by clicking on the Add to Source Control option.
- Select Git as your source control provider.
- On the next screen you can fill in the details of your repository. In my case I will use DigitalOceanDeploymentDemo as the name for my new repository. You can use the name of your repository and decide if you want to make it public or private, if you need a README, ...
- Click on the Create and Push button.
- Now you can see that the repository is created and the project is pushed to the repository.
Move the Dockerfile to the root of the project
It's important that the Dockerfile is in the root of the project. So we'll move the Dockerfile to the root of the project.
The easiest way to do this is to right-click on the Dockerfile in Visual Studio Solution Explorer and choose the Open Containing Folder option.
Now you can move the Dockerfile to the root of the project from the Windows Explorer.
- Commit and push the changes to GitHub
Now it's time to create our Digital Ocean App.
Create Digital Ocean account
- First of all, you'll need a Digital Ocean account. If you don't have an DO account than you can create an account with this referral link and you'll get $200 credits to spend in the next 60 days. (And you'll help me to keep this blog running.)
Digital Ocean App
DigitalOcean App Platform is a Platform-as-a-Service (PaaS) offering that makes it easy for developers to deploy their C# asp.net core applications to DigitalOcean servers. With App Platform, you can publish your code directly from your GitHub repository without worrying about the underlying infrastructure. This means that you can focus on building your app and let DigitalOcean take care of the rest!
Create Digital Ocean App
- Now you'll need to go to the Digital Ocean dashboard and create a new App. You can do this by clicking on the "Apps" menu item.
- Click on the "Create App" button.
Digital Ocean App configuration
- It's time to configure the Digital Ocean App. As Service Provider we will use GitHub , because we want to deploy our ASP.NET Docker image from a GitHub repository. So we select GitHub as our service provider.
- Now click on the Manage Access button to grant Digital Ocean access to your GitHub repository.
- On the next screen, choose Only select repositories and select the repository that you want to use. In this demo, we will use the Drieze/DigitalOceanDeploymentDemo repository.
- Click on the Install & Authorize button to grant Digital Ocean access to your GitHub repository.
- Now you can choose your granted repository in the dropdown menu below Repository. Choose the repository that you want to use. In my case it's the Drieze/DigitalOceanDeploymentDemo repository.
- Next you have to choose the branch on your repository that you want to be published every time you make an update on the selected branch. In my case it's the master branch.
- Leave the Source Directory on the root folder
/
. - Make sure that the Autodeploy checkbox is checked. It should be checked by default.
- Click on the Next button.
- Now you see a summary of your app. As you can see I get a random name for my app (clownfish-app), yours can be different.
- Now click on the Edit button to edit the app configuration. It's important that we change the port number. We need to change the port number to 80. Because we want to use the default port for HTTP traffic.
- Click on the Edit button in the HTTP Port section.
- Change the port number to 80 and click on the Save button.
- Click on the Back button to go back to the summary screen.
If you want, you can add an addiontal resource, but in this demo we will not add any additional resources.
Click on the Next button.
I don't have any enivronment variables, so I will skip this step. And click on Next.
- In the next screen you'll see a summary of your app. If everything is correct, click on the Next button.
- On the next screen you can do a review of your app. Scroll down to change the Billing plan.
- Click on the Edit Plan button.
You can choose the plan that you want. If you want to use some free credits , you can use this referral link to get $200 credits to spend in the next 60 days.
- I choose the Basic plan.
- And changed the Size to $5.00/mo - Basic.
- Click Back
- Now click on the Create Resources button.
- Now you can see that your app is being deployed. It can take a few minutes.
Building the Docker image
- Now you can see that the Docker image is being built. It can take a few minutes.
- Click on the Go to Build Logs button to see the build logs.
If you see an error that the Dockerfile is not found, you can check if the Dockerfile is in the root folder of your repository.
- After a succesfull build, your app is gonna be deployed.
- Now click on the Live App button to see your app live.
- Now you can see that your app is live and running on Digital Ocean.
Update the GitHub repository
Now it's time to make a change to the GitHub repository. We will change the text on the home page. I'll add a new p-tag with the text "Test".
- Now we need to commit the changes to the GitHub repository.
- Our Digital Ocean App will detect the changes and will build a new Docker image and deploy the new Docker image to our Digital Ocean App.
- After the build and deployment is done you can see that the text on the home page is changed.
GitHub repository for this demo
You can find the GitHub repository for this demo here.
Top comments (0)