Deploy To Production
Continuous Delivery Options
When launching anything
into production, it's essential to eliminate any uncertain elements. This is
where Continuous Integration and Continuous Delivery/Deployment (CI/CD) become
relevant. GitHub Actions and Azure DevOps (or Azure Pipelines) are two Microsoft
options for implementing CI/CD. There are numerous other alternatives, such as
Jenkins, TeamCity, and GitLab - the options are extensive. If our current CI/CD
solution is compatible with deploying ASP.NET, it will also be capable of
managing Blazor since Blazor essentially functions as an ASP.NET application.
We should ensure that we
establish tests as a component of our CI/CD pipeline. The great aspect is that
there is no requirement for additional hardware to test our components, it will
function as long as our CI/CD pipeline can execute unit tests (nUnit, xUnit).
We can execute all builds
and tests whenever a pull request is made. If both the build and tests are
successful, a team member conducts a code review and gives their approval for
the change. Once approved by the team member, this initiates a release that
deploys the site to our testing environment. Our testers will go through the
testing protocols and give their approval for the changes. At the end of the
sprint, the tester will complete the full testing protocol and approve the
site. We then initiate another release that deploys the site to production.
Deploying The Database
When it comes to
deploying our database, Entity Framework takes care of much for us. It
generates code to both apply and undo changes, so it should be relatively
secure to allow it to operate autonomously. There is an alternative, which is
allowing Entity Framework to create SQL scripts that we can execute manually.
By adding the script
flag, we will get a SQL script we can run against our database-
dotnet
ef migrations script 20180904195021_InitialCreate
There are many different
databases we can use, such as Microsoft SQL, MySQL, and, SQLite. We could also
go for a non-relational type of database. Blazor supports it all, so whatever
is right for the project is what we should use.
Hosting Options
When it comes to
deploying Blazor applications, there are numerous choices available. Any cloud
platform capable of hosting ASP.NET Core applications should have no issues
running Blazor.
Hosting Blazor Server
If the cloud provider
offers the ability to turn WebSockets on or off, we should turn them on because
that is the protocol utilized by SignalR. Based on the traffic, we may consider
utilizing a service like Azure SignalR Service, which will manage all connections
and allow our application to accommodate a larger number of users.
In certain situations,
the cloud provider might offer support for .NET Core 3.x, yet not provide
built-in support for .NET 5. However, by publishing our application in
self-contained deployment mode, we ensure that all files needed to run the
project are included (this might vary across different hosting providers).
Additionally, this approach is beneficial to guarantee that we are operating on
the specific framework version that we anticipate.
Hosting Blazor
WebAssembly
When utilizing a .NET
Core backend (as we do for the blog), we are hosting a .NET Core application,
meaning the same principles apply as with hosting a Blazor Server. There are
some other considerations when it comes to hosting Blazor WebAssembly, such as
these:
- We may need a .NET Core backend.
- The data we are getting may be static or hosted somewhere else.
In either of these cases,
we can host our application in Azure Static Websites or even GitHub Pages.
Hosting On IIS
We can additionally
deploy our application using Internet Information Server (IIS). By installing
the hosting bundle, you will ensure that the ASP.NET Core IIS module is
included, provided that IIS is installed on the machine. Remember to activate
the WebSocket protocol on the server.
Conclusion
Deploying is perhaps the
most important step when it comes to an application. Without deploying our
application, it's just code. With the things we mentioned above, such as CI/CD,
hosting, and deployment, we can easily deploy the code.
Comments
Post a Comment