Beralih dari Azure ke GCP, ASP.NET MVC ke ASP.NET Core 3.1

Penulis: Andrey Zhukov, Ketua Tim .NET, DataArt





Dalam artikel ini, saya menjelaskan pengalaman sukses saya sendiri dalam memigrasi proyek nyata dari satu platform cloud ke platform cloud lainnya. Tentu saja, ini bukan satu-satunya cara yang mungkin. Tetapi saya rasa di sini Anda dapat menemukan tip yang akan membuat hidup lebih mudah bagi semua orang yang akan melakukan transisi seperti itu. Namun, Anda perlu mempertimbangkan spesifikasi proyek Anda dan menggunakan akal sehat. 





, : Azure -> GCP

(Azure) (Google Cloud Platform). Node.js full-stack typescript-. ASP.NET MVC , . GCP.





, , GCP

ASP.NET MVC-, MS SQL . Azure App Services.





Web Portal — , Razor, TypeScript, JavaScript, Knockout Bootstrap. . , Azure: Azure Service Bus, Azure Blobs, Azure Tables storage, Azure Queue storage. - , . . GCP . , Azure Cache for Redis. Azure WebJob, Azure Service Bus. , , .





Awalnya, arsitektur Portal Web dalam proyek kami terlihat seperti ini
Web Portal

Azure WebJobs - . — , , Hangfire, IHostedService Microsoft.





Web API — ASP.NET WEB API. MS SQL . , , . .





, : , , ASP.NET MVC . . , , , . .





, ASP.NET MVC ASP.NET Core 3.1, WebJob c .NET Framework .NET Core, Linux. Windows GCP , . , Azure, - Azure WebJob, , GCP, . . Azure App Services. Docker. - .





, : , .





, . . Smoke tests.





, , , . . .   , , , .





: , . , - . , , . , , , , , . . , , .





Azure GCP-, cloud-agnostic-. .





, - , . . , . . – , , . 





  1. Web Portal c ASP.NET MVC ASP.NET Core





    1.1.  Web Portal Azure , .





    1.2.  Web Portal .NET Core.





    1.3.  .





    1.4.  Merge Web Portal , .





    1.5.  Web Portal.





    1.6.  Web Portal, Azure.





  2. Web API c ASP.NET MVC ASP.NET Core





    2.1.  E2E Web API.





    2.2.  Web API Azure , .





    2.3.  Web API.





    2.4.  Web API .NET Core.





    2.5.  Web API .





    2.6.  Merge Web API , .





    2.7.  Web API.





    2.8.  Web API, Azure.





  3. Azure





    3.1.  Web Portal Azure.





  4. GCP





    4.1.  Web Portal GCP.





    4.2.  Web Portal .





    4.3.  .





    4.4.  Web API GCP.





    4.5.  Web API .





    4.6.  prod-.





    4.7.  Web Portal Web API prod GCP.





, , , .





.NET Framework -> .NET Core

.Net Framework .Net Core Microsoft ASP.NET ASP.NET Core.





-Web- :





  • NuGet- Visual Studio 2019;





  • ;





  • App.config XML settings.json .





NuGet- Azure SDK , . , .NET Core , . Azure Service Bus WebJobs SDK. Azure Service Bus , WebJob , SDK.





C ASP.NET MVC ASP.NET Core . Web-. ASP.NET Core , . ASP.NET Core , ASP.NET MVC . , , ASP.NET MVC ASP.NET Core.





  1. ASP.NET Core ASP.NET MVC .





  2. ( NuGet-, . ).





  3. Web.config appsettings.json .





  4. Dependency injection .NET Core , Asp.NET MVC .





  5.   StaticFiles middleware : , , JavaScript-, CSS- . .





app.UseStaticFiles(); // wwwroot
app.UseStaticFiles(new StaticFileOptions
   	{
     	FileProvider = new PhysicalFileProvider(
         Path.Combine(Directory.GetCurrentDirectory(), "Scripts")),
     	RequestPath = "/Scripts"
});
      
      



wwwroot



.





6. bundleconfig.json JavaScript CSS- . JavaScript CSS:





<link rel="stylesheet" href="~/bundles/Content.css" asp-append-version="true" />
<script src="~/bundles/modernizr.js" asp-append-version="true"></script>
      
      



asp-append-version="true"



, (bundles) , . . wwwroot



( ).









7. UnhadledExceptions: ASP.NET Core , , .





8.     : ASP.NET Core Serilog. , , -, structured logging c .





9.     Session — , , .





10.  Routing: , templates, - .





11.  JSON-:  ASP.NET Core System.Text.Json Newtonsoft.Json. Microsoft , , , , , Newtonsoft.Json . , Newtonsoft.Json. , , Web API , , , . Newtonsoft.Json





12.  Typescript 2.3. , Node.js, Microsoft.TypeScript.MSBuild, tsconfig.json, (Definitions) Knockout, - //@ts-ignore







13.  HTTPS . , HttpsOnly, .





14.  , body , URL , HTTP Headers HttpContext , . . API ASP.NET MVC. , binding (Actions) (Controllers).





15.  Swagger c Swashbuckle.AspNetCore.Swagger.





16.  Authentication .





, . , .





Azure?

ASP.NET Core Azure-. , , - GCP. .





Azure Service Bus Redis Pub/Sub. , , , RabbitMQ. , , Redis . — . , , . , Redis Pub/Sub , .





Azure Blobs GCP Blobs. , - : GCP Blobs . CSV. Google Google Cloud operations suite, Stackdriver.





Azure Table Storage Web Portal. , . Microsoft, . . ILogger. , Serilog. GCP Stackdriver.





- GCP, Azure. , , , : IBlobService, IRequestLogger, ILogReader. Serilog. , Web Portal, , Azure Table Storage, Serilog.Sinks.AzureTableStorage.KeyGenerator.IKeyGenerator. GCP Google Cloud operations Log Router Sinks, BigQuery, .





Azure WebJobs?

Azure WebJobs Azure App Services on Windows. , Azure WebJobs SDK. SDK . :





static async Task Main(string[] args)
{
….
 
  var builder = new HostBuilder();

  ...            	

  var host = builder.Build();

  using (host)
  {
     await host.RunAsync();
  }
...
}
      
      



Dependency Injection





public class RedisPubSubMessageProcessor : Microsoft.Extensions.Hosting.IHostedService
{
...
	public async Task StartAsync(CancellationToken cancellationToken)
...
	public async Task StopAsync(CancellationToken cancellationToken)
...
}
      
      



.NET Core . Azure WebJob SDK, Azure WebJob. Linux Docker- Kubernetes, . 





. , . , . , Microsoft. , , . Web API . Azure- , .





, , .





Docker

Docker . Dockerfile Visual Studio. , , Web Portal, Web API, WebJob ( ). Dockerfile Microsoft — Dockerfile Web Portal Node.js. build TypeScript.





RUN apt-get update && \
	apt-get -y install curl gnupg && \
	curl -sL https://deb.nodesource.com/setup_12.x  | bash - && \
	apt-get -y install nodejs
      
      



Azure App Services -> GKE

.NET Core- GCP, :





  • App Engine Flex.





  • Kubernetes Engine.





  • Compute Engine.





Google Kubernetes Engine (GKE). (Linux). GKE, , , . , . - .





GCP, MS SQL Server, Cloud SQL Google. 





Arsitektur sistem kami setelah migrasi ke GCP
GCP

Web Portal , Smoke-. . , Prod, , , Product Owner. QA-, , , . , . Puppeteer-, - . CICD. - - - .





Web API, , . Postman, CICD Newman. Swagger, . . IIS (Internet Information Services), . . , , Postman- . , , Staging, Prod, Dev.





, . , . Web API , , , .





Azure MS SQL -> GCP Managed MS SQL

MS SQL Managed Azure GCP Cloud SQL , . :





  • (Azure :  Database data storage /





    Used space 181GB).





  •     .





  •   Azure GCP Cloud SQL.





, Google Chrome. , .





, . Azure SQL bacpac, backup . 6 bacpac 154 backup. GCP Cloud backup, , MS SQL bacpac backup . Microsoft SQL Server Management Studio, MS SQL Server . , . Azure SQL prod , . - , . SSD- 1 .





Azure App Services GCP Kubernetes CICD, Feature Branch deployments, Blue/Green deployment. Kubernetes , Github Actions. Iac (Infrastructure-as-Code) Pulumi.





. — .








All Articles