Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Moving an ASP.NET Core from Azure App Service on Windows to Linux by testing in WSL and Docker first

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Moving an ASP.NET Core from Azure App Service on Windows to Linux by testing in WSL and Docker first


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: feeds.hanselman.com

I updated one of my websites from ASP.NET Core 2.2 to the latest LTS (Long Term Support) version of ASP.NET Core 3.1 this week. Now I want to do the same with my podcast site AND move it to Linux at the same time. Azure App Service for Linux has some very good pricing and allowed me to move over to a Premium v2 plan from Standard which gives me double the memory at 35% off.

My podcast has historically run on ASP.NET Core on Azure App Service for Windows. How do I know if it'll run on Linux? Well, I'll try it see!

I use WSL (Windows Subsystem for Linux) and so should you. It's very likely that you have WSL ready to go on you machine and you just haven't turned it on. Combine WSL (or the new WSL2) with the Windows Terminal and you're in a lovely spot on Windows with the ability to develop anything for anywhere.

First, let's see if I can run my existing ASP.NET Core podcast site (now updated to .NET Core 3.1) on Linux. I'll start up Ubuntu 18.04 on Windows and run dotnet --version to see if I have anything installed already. You may have nothing. I have 3.0 it seems:

$ dotnet --version

3.0.100

Ok, I'll want to install .NET Core 3.1 on WSL's Ubuntu instance. Remember, just because I have .NET 3.1 installed in Windows doesn't mean it's installed in my Linux/WSL instance(s). I need to maintain those on my own. Another way to think about it is that I've got the win-x64 install of .NET 3.1 and now I need the linux-x64 one.

  • NOTE: It is true that I could "dotnet publish -r linux-x64" and then scp the resulting complete published files over to Linux/WSL. It depends on how I want to divide responsibility. Do I want to build on Windows and run on Linux/Linux? Or do I want to build and run from Linux. Both are valid, it just depends on your choices, patience, and familiarity.
  • GOTCHA: Also if you're accessing Windows files at /mnt/c under WSL that were git cloned from Windows, be aware that there are subtleties if Git for Windows and Git for Ubuntu are accessing the index/files at the same time. It's easier and safer and faster to just git clone another copy within the WSL/Linux filesystem.

I'll head over to https://dotnet.microsoft.com/download and get .NET Core 3.1 for Ubuntu. If you use apt, and I assume you do, there's some preliminary setup and then it's a simple

sudo apt-get install dotnet-sdk-3.1

No sweat. Let's "dotnet build" and hope for the best!

Building my site under WSL

It might be surprising but if you aren't doing anything tricky or Windows-specific, your .NET Core app should just build the same on Windows as it does on Linux. If you ARE doing something interesting or OS-specific you can #ifdef your way to glory if you insist.

Bonus points if you have Unit Tests - and I do - so next I'll run my unit tests and see how it goes.

OPTION: I write things like build.ps1 and test.ps1 that use PowerShell as PowerShell is on Windows already. Then I install PowerShell (just for the scripting, not the shelling) on Linux so I can use my .ps1 scripts everywhere. The same test.ps1 and build.ps1 and dockertest.ps1, etc just works on all platforms. Make sure you have a shebang #!/usr/bin/pwsh at the top of your ps1 files so you can just run them (chmod +x) on Linux.

I run test.ps1 which runs this command

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov .hanselminutes.core.tests

with coverlet for code coverage and...it works! Again, this might be surprising but if you don't have any hard coded paths, make any assumptions about a C: drive existing, and avoid the registry and other Windows-specific things, things work.

Test Run Successful.

Total tests: 23
Passed: 23
Total time: 9.6340 Seconds

Calculating coverage result...
Generating report './lcov.info'

+--------------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+--------------------------+--------+--------+--------+
| hanselminutes.core.Views | 60.71% | 59.03% | 41.17% |
+--------------------------+--------+--------+--------+
| hanselminutes.core | 82.51% | 81.61% | 85.39% |
+--------------------------+--------+--------+--------+

I can build, I can test, but can I run it? What about running and testing in containers?

I'm running WSL2 on my system and I've doing all this in Ubuntu 18.04 AND I'm running the Docker WSL Tech Preview. Why not see if I can run my tests under Docker as well? From Docker for Windows I'll enabled the Experimental WSL2 support and then from the Resources menu, WSL Integration I'll enable Docker within my Ubuntu 18.04 instance (your instances and their names will be your own).

Docker under WSL2

I can confirm it's working with "docker info" under WSL and talking to a working instance. I should be able to run "docker info" in BOTH Windows AND WSL.

$ docker info

Client:
Debug Mode: false

Server:
Containers: 18
Running: 18
Paused: 0
Stopped: 0
Images: 31
Server Version: 19.03.5
Storage Driver: overlay2
Backing Filesystem: extfs
...snip...

Cool. I remembered I also I needed to update my Dockerfile as well from the 2.2 SDK on the Docker hub to the 3.1 SDK from Microsoft Container Registry, so this one line change:

#FROM microsoft/dotnet:2.2-sdk AS build

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build

as well as the final runtime version for the app later in the Dockerfile. Basically make sure your Dockerfile uses the right versions.

#FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime

I also volume mount the tests results so there's this offensive If statement in the test.ps1. YES, I know I should just do all the paths with / and make them relative.

#!/usr/bin/pwsh
docker build --pull --target testrunner -t podcast:test .
if ($IsWindows)
{
 docker run --rm -v d:githubhanselminutes-coreTestResults:/app/hanselminutes.core.tests/TestResults podcast:test
}
else
{
 docker run --rm -v ~/hanselminutes-core/TestResults:/app/hanselminutes.core.tests/TestResults podcast:test
}

Regardless, it works and it works wonderfully. Now I've got tests running in Windows and Linux and in Docker (in a Linux container) managed by WSL2. Everything works everywhere. Now that it runs well on WSL, I know it'll work great in Azure on Linux.

Moving from Azure App Service on Windows to Linux

This was pretty simple as well.

I'll blog in detail how I build andd eploy the sites in Azure DevOps and how I've moved from .NET 2.2 with Classic "Wizard Built" DevOps Pipelines to a .NET Core 3.1 and a source control checked-in YAML pipeline next week.

The short version is, make a Linux App Service Plan (remember that an "App Service Plan " is a VM that you don't worry about. See in the pick below that the Linux Plan has a penguin icon. Also remember that you can have as many apps inside your plan as you'd like (and will fit in memory and resources). When you select a "Stack" for your app within Azure App Service for Linux you're effectively selecting a Docker Image that Azure manages for you.

I started by deploying to staging.mydomain.com and trying it out. You can use Azure Front Door or CloudFlare to manage traffic and then swap the DNS. I tested on Staging for a while, then just changed DNS directly. I waited a few hours for traffic to drain off the Windows podcast site and then stopped it. After a day or two of no traffic I deleted it. If I did my job right, none of you noticed the site moved from Windows to Linux, from .NET Core 2.2 to .NET Core 3.1. It should be as fast or faster with no downtime.

Here's a snap of my Azure Portal. As of today, I've moved my home page, my blood sugar management portal, and my podcast site all onto a single Linux App Service Plan. Each is hosted on GitHub and each is deploying automatically with Azure DevOps.

Azure Plan with 3 apps on Linux

Next big migration to the cloud will be this blog which still runs .NET Framework 4.x. I'll blog how the podcast gets checked into GitHub then deployed with Azure DevOps next week.

What cool migrations have YOU done lately, Dear Reader?


Sponsor: Like C#? We do too! Thatโ€™s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows. Try JetBrains Rider today!


ยฉ 2019 Scott Hanselman. All rights reserved.
ย ย ย ย ย 
...



๐Ÿ“Œ Moving an ASP.NET Core from Azure App Service on Windows to Linux by testing in WSL and Docker first


๐Ÿ“ˆ 90.37 Punkte

๐Ÿ“Œ what are competitive alternatives of .NET Core, ASP.NET Core, and EF Core for development/deployment on Linux?


๐Ÿ“ˆ 46.15 Punkte

๐Ÿ“Œ Visual Studio for Mac + ASP.NET Core โ€“ Getting started with ASP.NET Core using eShopOnWeb


๐Ÿ“ˆ 46.13 Punkte

๐Ÿ“Œ C# (C Sharp) CRUD Rest API using .NET 7, ASP.NET, Entity Framework, Postgres, Docker and Docker Compose


๐Ÿ“ˆ 42.94 Punkte

๐Ÿ“Œ Microsoft .NET Maze: Understand .NET Core Vs .NET Framework Vs ASP.NET


๐Ÿ“ˆ 42.01 Punkte

๐Ÿ“Œ .NET Core, ASP.NET Core und Entity Framework Core 2.1 sind fertig


๐Ÿ“ˆ 41.88 Punkte

๐Ÿ“Œ Using SkipToken for Paging in Asp.Net OData and Asp.Net Core OData


๐Ÿ“ˆ 41.68 Punkte

๐Ÿ“Œ Upcoming SameSite Cookie Changes in ASP.NET and ASP.NET Core


๐Ÿ“ˆ 41.68 Punkte

๐Ÿ“Œ Leveraging Azure Cloud and Docker for ASP.NET Core Projects: A Comprehensive Guide for Businesses


๐Ÿ“ˆ 40.3 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request denial of service


๐Ÿ“ˆ 38.37 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core System.IO.Pipelines denial of service


๐Ÿ“ˆ 38.37 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request Denial of Service


๐Ÿ“ˆ 38.37 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 6


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 7


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 8


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 9


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ Announcing a Microsoft .NET Core and ASP.NET Core Bug Bounty


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0 Release Candidate 1


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core and Blazor updates in .NET Core 3.0


๐Ÿ“ˆ 37.43 Punkte

๐Ÿ“Œ ASP.NET Core Series: Performance Testing Techniques | On .NET


๐Ÿ“ˆ 36.87 Punkte

๐Ÿ“Œ Setting up Azure DevOps CI/CD for a .NET Core 3.1 Web App hosted in Azure App Service for Linux


๐Ÿ“ˆ 36.77 Punkte

๐Ÿ“Œ ASP.NET Core Series: Deploying your Microservice to Azure Container Instances | On .NET


๐Ÿ“ˆ 35.81 Punkte

๐Ÿ“Œ Microsoft legt Bug-Bounty-Programm fรผr .NET Core und ASP.NET Core neu auf


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Microsoft legt Bug-Bounty-Programm fรผr .NET Core und ASP.NET Core neu auf


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ ASP.NET Core 3.0 lรคuft nur noch auf .NET Core


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ .NET Core und ASP.NET Core 2.2.0 Preview 3 verfรผgbar


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ 4021279 - Vulnerabilities in .NET Core, ASP.NET Core Could Allow Elevation of Privilege - Version: 1.1


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request spoofing


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request privilege escalation


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ ASP.NET Core updates in .NET Core 3.1 Preview 2


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Updating an ASP.NET Core 2.2 Web Site to .NET Core 3.1 LTS


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request Spoofing [CVE-2017-0256]


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ ASP.NET Core updates in .NET Core 3.1 Preview 3


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ Microsoft ASP.NET Core/.NET Core Web Request erweiterte Rechte


๐Ÿ“ˆ 35.63 Punkte

๐Ÿ“Œ ASP.NET Core updates in .NET Core 3.1 Preview 1


๐Ÿ“ˆ 35.63 Punkte











matomo