首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cake (of http://cakebuild.net) )可用于部署Azure WebApps吗?

Cake (of http://cakebuild.net) )可用于部署Azure WebApps吗?
EN

Stack Overflow用户
提问于 2017-07-21 02:39:41
回答 1查看 922关注 0票数 2

一直在查看Cake (在http://cakebuild.net),我想知道它是否可以用于部署and应用程序和/或通过发布包部署访问虚拟服务器。

我喜欢把蛋糕作为C#中的一个部署框架的想法,所以使用相同的语言来进行核心开发。

有什么我可以访问的天蓝色部署的例子吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-21 14:49:14

有几种方法可以使用Cake部署Azure,或者通过使用一些CI服务(如VSTS/AppVeyor )构建预构建站点,然后使用web部署、git或ftp发布构件(有几个Cake加载项可以帮助使用Cake.WebDeployCake.GitCake.FTP,或者使用Azure内置的部署引擎Kudu和使用Cake的自定义部署脚本。

为了帮助Kudu部署/构建环境,可以使用Cake.Kudu加载项。

第一步是告诉Kudu,您已经获得了一个自定义部署脚本,为此您可以将一个".deployment“文件添加到存储库的根目录中,其内容为

代码语言:javascript
复制
[config]
command = deploy.cmd

安装和启动蛋糕时,deploy.cmd可能看起来像这样

代码语言:javascript
复制
@echo off

IF NOT EXIST "Tools" (md "Tools")

IF NOT EXIST "Tools\Addins" (MD "Tools\Addins")

nuget install Cake -ExcludeVersion -OutputDirectory "Tools" -Source https://www.nuget.org/api/v2/

Tools\Cake\Cake.exe deploy.cake -verbosity=Verbose

deploy.cake看起来可能是这样的:

代码语言:javascript
复制
#tool "nuget:https://www.nuget.org/api/v2/?package=xunit.runner.console"

#tool "nuget:https://www.nuget.org/api/v2/?package=KuduSync.NET"

#addin "nuget:https://www.nuget.org/api/v2/?package=Cake.Kudu"

///////////////////////////////////////////////////////////////////////////////

// ARGUMENTS

///////////////////////////////////////////////////////////////////////////////


var target = Argument<string>("target", "Default");

var configuration = Argument<string>("configuration", "Release");

///////////////////////////////////////////////////////////////////////////////

// GLOBAL VARIABLES

///////////////////////////////////////////////////////////////////////////////

var webRole = (EnvironmentVariable("web_role") ?? string.Empty).ToLower();

var solutionPath = MakeAbsolute(File("./src/MultipleWebSites.sln"));

string outputPath = MakeAbsolute(Directory("./output")).ToString();

string testsOutputPath = MakeAbsolute(Directory("./testsOutputPath")).ToString();


DirectoryPath websitePath,

                websitePublishPath,

                testsPath;


FilePath projectPath,

            testsProjectPath;

switch(webRole)

{

    case "api":

        {

            websitePath = MakeAbsolute(Directory("./src/Api"));

            projectPath = MakeAbsolute(File("./src/Api/Api.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Api.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Api.Tests/Api.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Api"));

            break;

        }

    case "frontend":

        {

            websitePath = MakeAbsolute(Directory("./src/Frontend"));

            projectPath = MakeAbsolute(File("./src/Frontend/Frontend.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Frontend.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Frontend.Tests/Frontend.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Frontend"));

            break;

        }

    case "backoffice":

        {

            websitePath = MakeAbsolute(Directory("./src/Backoffice"));

            projectPath = MakeAbsolute(File("./src/Backoffice/Backoffice.csproj"));

            testsPath = MakeAbsolute(Directory("./src/Backoffice.Tests"));

            testsProjectPath = MakeAbsolute(File("./src/Backoffice.Tests/Backoffice.Tests.csproj"));

            websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Backoffice"));

            break;

        }

    default:

        {

            throw new Exception(

            string.Format(

                    "Unknown web role {0}!",

                    webRole

                )

            );

        }

}


if (!Kudu.IsRunningOnKudu)

{

    throw new Exception("Not running on Kudu");

}


var deploymentPath = Kudu.Deployment.Target;

if (!DirectoryExists(deploymentPath))

{

    throw new DirectoryNotFoundException(

        string.Format(

            "Deployment target directory not found {0}",

            deploymentPath

            )

        );

}


///////////////////////////////////////////////////////////////////////////////

// SETUP / TEARDOWN

///////////////////////////////////////////////////////////////////////////////


Setup(() =>

{

    // Executed BEFORE the first task.

    Information("Running tasks...");

});


Teardown(() =>

{

    // Executed AFTER the last task.

    Information("Finished running tasks.");

});


///////////////////////////////////////////////////////////////////////////////

// TASK DEFINITIONS

///////////////////////////////////////////////////////////////////////////////


Task("Clean")

    .Does(() =>

{

    //Clean up any binaries

    Information("Cleaning {0}", outputPath);

    CleanDirectories(outputPath);


    Information("Cleaning {0}", testsOutputPath);

    CleanDirectories(testsOutputPath);


    var cleanWebGlobber = websitePath + "/**/" + configuration + "/bin";

    Information("Cleaning {0}", cleanWebGlobber);

    CleanDirectories(cleanWebGlobber);


    var cleanTestsGlobber = testsPath + "/**/" + configuration + "/bin";

    Information("Cleaning {0}", cleanTestsGlobber);

    CleanDirectories(cleanTestsGlobber);

});


Task("Restore")

    .Does(() =>

{

    // Restore all NuGet packages.

    Information("Restoring {0}...", solutionPath);

    NuGetRestore(solutionPath);

});


Task("Build")

    .IsDependentOn("Clean")

    .IsDependentOn("Restore")

    .Does(() =>

{

    // Build target web & tests.

    Information("Building web {0}", projectPath);

    MSBuild(projectPath, settings =>

        settings.SetPlatformTarget(PlatformTarget.MSIL)

            .WithProperty("TreatWarningsAsErrors","true")

            .WithProperty("OutputPath", outputPath)

            .WithTarget("Build")

            .SetConfiguration(configuration));


    Information("Building tests {0}", testsProjectPath);

    MSBuild(testsProjectPath, settings =>

        settings.SetPlatformTarget(PlatformTarget.MSIL)

            .WithProperty("TreatWarningsAsErrors","true")

            .WithProperty("ReferencePath", outputPath)

            .WithProperty("OutputPath", testsOutputPath)

            .WithTarget("Build")

            .SetConfiguration(configuration));

});


Task("Run-Unit-Tests")

    .IsDependentOn("Build")

    .Does(() =>

{

    XUnit2(testsOutputPath + "/**/*.Tests.dll", new XUnit2Settings {

        NoAppDomain = true

        });

});


Task("Publish")

    .IsDependentOn("Run-Unit-Tests")

    .Does(() =>

{

    Information("Deploying web from {0} to {1}", websitePublishPath, deploymentPath);

    Kudu.Sync(websitePublishPath);

});



Task("Default")

    .IsDependentOn("Publish");



///////////////////////////////////////////////////////////////////////////////

// EXECUTION

///////////////////////////////////////////////////////////////////////////////


RunTarget(target);

在上面的场景中,它支持一个包含3个不同网站的解决方案,并且发布的解决方案是基于一个附录。

对于.NET核心web应用程序,流程类似,基本上如下所示:

  1. DotNetCoreRestore
  2. DotNetCoreBuild
  3. DotNetCorePublish
  4. Kudu.Sync

有几篇关于部署到Azure和Cake的很好的博客文章:

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45228119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档