右键单击具有VS Code扩展和zipdeploy的快速发布到Azure App Services

本文介绍了如何使用Visual Studio Code、.NET Core和Azure App Service扩展,快速免费部署ASP.NET Core网站到Azure。通过配置zipdeploy,可以实现一键部署,简化发布流程,甚至支持在VS Code中实时查看应用服务的日志输出。
摘要由CSDN通过智能技术生成

I wanted to see what was the fastest way to get an ASP.NET Core web site up (for free) on Azure. First, I could use Visual Studio Community (which is free), and just right click Publish, sign into Azure, and make a free Web App and I'm cool. But I also wanted to see what it was like on Visual Studio Code (which would work on Linux, etc)

我想看看在Azure上免费(免费)建立ASP.NET Core网站的最快方法是什么。 首先,我可以使用Visual Studio Community(免费),然后右键单击“发布”,登录到Azure,然后制作一个免费的Web App,我很酷。 但是我也想看看在Visual Studio Code上是什么样子(可以在Linux等上运行)

I downloaded these things. This is 10-15 min tops for download AND install. Likely less on a fast connection.

我下载了这些东西。 这是10-15分钟的顶部,用于下载和安装。 在快速连接上可能更少。

This also assumes you have a free Azure account https://azure.microsoft.com/free/

这也假设您有一个免费的Azure帐户https://azure.microsoft.com/free/

I made a new ASP.NET web site with "dotnet new razor" at the command line. The Azure App Service extension makes a new Azure icon appear on the left of VS Code. I can see my subscription(s) and any sites I've made before. I can right-click the top of the tree or just click the + plus sign.

我在命令行上使用“ dotnet new razor ”创建了一个新的ASP.NET网站。 Azure App Service扩展使新的Azure图标出现在VS Code的左侧。 我可以看到我的订阅以及以前创建的任何网站。 我可以右键单击树的顶部,或仅单击+加号。

image

TRICK: The default mode of the Azure App Service extension is "basic" mode. This is fine for messing around, but it will assume a bunch of things. You don't have control over the location (it'll pick a nearby one) or really anything. Again, it's fine. However, if you DO want explicit prompts for name, location, OS, runtime, etc you can turn on "appService.advanced" in File | Preferences | Settings (or Ctrl+,). Don't feel you need to, but know it's possible.

技巧:Azure App Service扩展的默认模式为“基本”模式。 这对于弄乱是很好的,但是会假设很多事情。 您无法控制位置(它将选择附近的位置)或其他任何控制权。 再次,很好。 但是,如果您确实需要名称,位置,操作系统,运行时等的明确提示,则可以在“文件” |“打开”中打开“ appService.advanced”。 首选项| 设置(或Ctrl +,)。 不需要,但知道有可能。

appService.advanced

Now, in my opinion, deploying apps (.NET Core, Node, or otherwise) directly from source can be a little confusing, and it doesn't really scale for anything other than proofs of concept. There's usually a "build" step, and ideally you'll have a CI/CD (Continuous Integration/Continuous Deployment) pipeline for anything of any real size. It's easier than you think - you can likely get a basic DevOps pipeline up in a hour or so. I commit to GitHub and it just deploys to Azure.

现在,以我的观点,直接从源代码部署应用程序(.NET Core,Node或其他方式)可能会有些混乱,并且除了概念证明之外,它实际上并不能扩展。 通常有一个“构建”步骤,理想情况下,您将具有一个CI / CD(连续集成/连续部署)管道来处理任何实际大小的对象。 它比您想象的要容易-您可以在一个小时左右的时间内建立基本的DevOps管道。 我承诺使用GitHub,并将其部署到Azure。

That said, a quickie deploy has value so I wanted to do it. You can do a "git deploy" to Azure where Azure is a git remote and you just "git push azure master" but...you're pushing source and Azure "builds" it in Azure App Service using a thing called Kudu. That means it'll run npm install, dotnet restore, etc, it'll take some time. You could deploy a container to Azure and just push it to a Container Registry, then spin up the container.

就是说,快速部署具有价值,所以我想做到这一点。 您可以在Azure是git远程站点的Azure进行“ git部署”,而您只是“ git push azure主对象”,但是...您在Azure App Service中使用称为Kudu的东西推送源代码,Azure“构建”它。 这意味着它将运行npm install,dotnet restore等,这需要一些时间。 您可以将容器部署到Azure ,然后将其推送到容器注册表,然后启动容器。

However, Azure also has a little known but rather clever "zipdeploy" feature. Once you've configured your Azure App Service for zipdeployment as a source, you can just POST a new ZIP deployment with Curl!

但是,Azure还具有一个鲜为人知但相当聪明的“ zipdeploy ”功能。 将用于zipdeployment的Azure应用服务配置为源之后,就可以使用Curl发布新的ZIP部署!

curl -X POST -u <deployment_user> --data-binary @"<zip_file_path>" https://<app_name>.scm.azurewebsites.net/api/zipdeploy

You might find that weird, or you might find it elegant. If it's the latter, use it. If it's the former, don't. You can even do it with minimal or no downtime by deploying to a staging slot and use Auto Swap.

您可能会发现这很奇怪,也可能会发现它很优雅。 如果是后者,请使用它。 如果是前者,那就不要。 通过部署到临时插槽并使用“自动交换”,您甚至可以使停机时间最少或没有停机

I'm going to use the Azure App Service extension in VS Code and it's going to hide all of this and it'll just publish in one click.

我将在VS Code中使用Azure App Service扩展,它将隐藏所有这些扩展,只需单击一下即可发布。

Here's the important part if you want it to just work and work easily. You'll want to deploy from a folder that represents your published app. That means your app in a state that it's ready to go.

这是重要的部分,如果您希望它可以轻松工作。 您需要从代表已发布应用程序的文件夹中进行部署。 这意味着您的应用处于准备就绪的状态。

With .NET Core, the easiest way is to dotnet publish. Then I'm right clicking on that publish folder as seen in this screenshot. Given that the extension is zipping up the target folder and deploying it, I want publish the publish folder, not the root of my source folder.

使用.NET Core,最简单的方法是dotnet publish 。 然后,我右键单击该屏幕快照中所示的发布文件夹。 鉴于该扩展正在压缩目标文件夹并进行部署,我想发布发布文件夹,而不是源文件夹的根目录。

image

That will actually make a file .vscode/settings.json that will tell VS Code's Azure App Service extension what folder to deploy from in the future, thereby simplifying things.

这实际上将生成一个文件.vscode / settings.json,该文件将告诉VS Code的Azure应用服务扩展将来要从哪个文件夹中进行部署,从而简化了事情。

{
"appService.defaultWebAppToDeploy": "/subscriptions/GUID/resourceGroups/appsvc_rg_Windows_CentralUS/providers/Microsoft.Web/sites/fancyweb1",
"appService.deploySubpath": "bin\\Debug\\netcoreapp2.2\\publish"
}

Below you can see the dialog that pops up "Always deploy the workspace ___ to ___" if you click Yes that will create the setting above specific to your application.

如果单击“是”,则会在下面看到弹出对话框“始终将工作空间___部署到___”,该对话框将创建特定于您的应用程序的设置。

Always deploy the workspace web1 to fancyweb1

Now when I deploy, I can right click from anywhere and it will zipdeploy right to my site. Note the log below.

现在,当我进行部署时,我可以从任何地方右键单击,它将直接压缩到我的站点。 请注意下面的日志。

image

With this extension I can even right click and "Start Streaming Logs" and get output of the logs of your Azure App Service as it runs, right in the output pane of VS Code.

使用此扩展程序,我什至可以右键单击“启动流日志”,并在VS Code的输出窗格中直接获取Azure App Service运行时的日志输出。

Start Streaming Logs

This will make things pretty easy for my simplest sites and proofs of concept. Give it a try!

对于我最简单的网站和概念证明,这将使事情变得非常容易。 试一试!

Sponsor: Get the latest JetBrains Rider for remote debugging via SSH, SQL injections, a new Search Everywhere popup, and improved Unity support.

赞助商:获取最新的JetBrains Rider,以通过SSH,SQL注入,新的“搜索无处不在”弹出窗口以及改进的Unity支持进行远程调试。

翻译自: https://www.hanselman.com/blog/right-click-publish-quickly-to-azure-app-services-with-vs-code-extensions-and-zipdeploy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值