Skip to content

Commit

Permalink
add template for msbuild functionApp
Browse files Browse the repository at this point in the history
  • Loading branch information
watashiSHUN committed Jun 3, 2017
1 parent 5ab5fbc commit fb9a9a6
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 128 deletions.
41 changes: 10 additions & 31 deletions Kudu.Core/Deployment/Generator/AspNetCoreBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,32 @@

namespace Kudu.Core.Deployment.Generator
{
class AspNetCoreBuilder : GeneratorSiteBuilder
class AspNetCoreBuilder : MicrosoftSiteBuilder
{
private readonly string _projectPath;
private readonly string _solutionPath;
private readonly string _version;

public AspNetCoreBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectPath, string solutionPath = null)
: base(environment, settings, propertyProvider, sourcePath)
public AspNetCoreBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectFilePath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath, projectFilePath, solutionPath, "--aspNetCore")
{
_projectPath = projectPath; // either xproj, csproj or project.json
_solutionPath = solutionPath;
if (_projectPath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
if (projectFilePath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
{
_version = "csproj";
_version = "CSPROJ";
}
else if (_projectPath.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase))
else if (projectFilePath.EndsWith(".xproj", StringComparison.OrdinalIgnoreCase))
{
// if it's xproj, throw invalidOperationException
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
Resources.Error_ProjectNotDeployable,
projectPath));
throw new InvalidOperationException(@"Building Asp.Net Core .xproj is no longer supported in Azure, please move to .csproj
For more information, please visit https://go.microsoft.com/fwlink/?linkid=850964");
}
else
{
_version = "project.json";
}
}

protected override string ScriptGeneratorCommandArguments
{
get
{

if (string.IsNullOrEmpty(_solutionPath))
{
return $"--aspNetCore \"{_projectPath}\"";
}
else
{
return $"--aspNetCore \"{_projectPath}\" --solutionFile \"{_solutionPath}\"";
}
_version = "PROJECT.JSON";
}
}

public override string ProjectType
{
get { return $"ASP.NET Core {_version}"; }
get { return $"ASP.NET CORE {_version}"; }
}
}
}
31 changes: 3 additions & 28 deletions Kudu.Core/Deployment/Generator/DotNetConsoleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,11 @@ namespace Kudu.Core.Deployment.Generator
/// <summary>
/// Console worker consisting a .net console application project which is built and the artifact executable will run as the worker
/// </summary>
public class DotNetConsoleBuilder : GeneratorSiteBuilder
public class DotNetConsoleBuilder : MicrosoftSiteBuilder
{
private readonly string _projectPath;
private readonly string _solutionPath;

public DotNetConsoleBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectPath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath)
{
_projectPath = projectPath;
_solutionPath = solutionPath;
}

protected override string ScriptGeneratorCommandArguments
public DotNetConsoleBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectFilePath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath, projectFilePath, solutionPath, "--dotNetConsole")
{
get
{
var commandArguments = new StringBuilder();
commandArguments.AppendFormat("--dotNetConsole \"{0}\"", _projectPath);

if (!String.IsNullOrEmpty(_solutionPath))
{
commandArguments.AppendFormat(" --solutionFile \"{0}\"", _solutionPath);
}
else
{
commandArguments.AppendFormat(" --no-solution");
}

return commandArguments.ToString();
}
}

public override string ProjectType
Expand Down
20 changes: 0 additions & 20 deletions Kudu.Core/Deployment/Generator/FunctionAppBuilder.cs

This file was deleted.

20 changes: 20 additions & 0 deletions Kudu.Core/Deployment/Generator/FunctionBasicBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Kudu.Contracts.Settings;

namespace Kudu.Core.Deployment.Generator
{
class FunctionBasicBuilder : BaseBasicBuilder
{
public FunctionBasicBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string repositoryPath, string projectPath)
: base(environment, settings, propertyProvider, repositoryPath, projectPath, "--functionApp")
{
}

public override string ProjectType
{
get
{
return "BASIC FUNCTIONAPP";
}
}
}
}
20 changes: 20 additions & 0 deletions Kudu.Core/Deployment/Generator/FunctionMsbuildBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Kudu.Contracts.Settings;

namespace Kudu.Core.Deployment.Generator
{
class FunctionMsbuildBuilder : MicrosoftSiteBuilder
{
public FunctionMsbuildBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectFilePath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath, projectFilePath, solutionPath, "--functionApp")
{
}

public override string ProjectType
{
get
{
return "MSBUILD FUNCTIONAPP";
}
}
}
}
45 changes: 45 additions & 0 deletions Kudu.Core/Deployment/Generator/MicrosoftSiteBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Kudu.Contracts.Settings;
using System;
using System.Text;

namespace Kudu.Core.Deployment.Generator
{

public abstract class MicrosoftSiteBuilder : GeneratorSiteBuilder
{
protected string SolutionPath { get; private set; }

protected string CommandArgument { get; private set; }

protected string ProjectFilePath { get; private set; }


protected MicrosoftSiteBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectFilePath, string solutionPath, string commandArgument)
: base(environment, settings, propertyProvider, sourcePath)
{
ProjectFilePath = CleanPath(projectFilePath);
SolutionPath = CleanPath(solutionPath);
CommandArgument = commandArgument;
}

protected override string ScriptGeneratorCommandArguments
{
get
{
var commandArguments = new StringBuilder();
commandArguments.AppendFormat("{0} \"{1}\"", CommandArgument, ProjectFilePath);

if (!String.IsNullOrEmpty(SolutionPath))
{
commandArguments.AppendFormat(" --solutionFile \"{0}\"", SolutionPath);
}
else
{
commandArguments.AppendFormat(" --no-solution");
}

return commandArguments.ToString();
}
}
}
}
46 changes: 31 additions & 15 deletions Kudu.Core/Deployment/Generator/SiteBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSet
// figure out with some heuristic, which one to deploy.

// TODO: Pick only 1 and throw if there's more than one
VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore).FirstOrDefault();
VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

if (project == null)
{
Expand Down Expand Up @@ -128,21 +128,31 @@ public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSet
solution.Path);
}

return new WebSiteBuilder(_environment,
if (project.IsWebSite)
{
return new WebSiteBuilder(_environment,
settings,
_propertyProvider,
repositoryRoot,
project.AbsolutePath,
solution.Path);
}

return new FunctionMsbuildBuilder(_environment,
settings,
_propertyProvider,
repositoryRoot,
project.AbsolutePath,
solution.Path);
}

private ISiteBuilder ResolveNonAspProject(string repositoryRoot, string projectPath, IDeploymentSettingsManager perDeploymentSettings)
{
string sourceProjectPath = projectPath ?? repositoryRoot;
// "FUNCTIONS_EXTENSION_VERSION" environment variable implies a functionApp
if (IsFunctionApp())
if (FunctionAppHelper.LooksLikeFunctionApp())
{
return new FunctionAppBuilder(_environment, perDeploymentSettings, _propertyProvider, repositoryRoot, projectPath);
return new FunctionBasicBuilder(_environment, perDeploymentSettings, _propertyProvider, repositoryRoot, projectPath);
}
else if (IsNodeSite(sourceProjectPath))
{
Expand Down Expand Up @@ -193,11 +203,6 @@ private static bool IsPHPSite(string projectPath)
return PHPSiteEnabler.LooksLikePHP(projectPath);
}

private static bool IsFunctionApp()
{
return FunctionAppEnabler.LooksLikeFunctionApp();
}

private ISiteBuilder ResolveProject(string repositoryRoot, IDeploymentSettingsManager perDeploymentSettings, IFileFinder fileFinder, bool tryWebSiteProject = false, SearchOption searchOption = SearchOption.AllDirectories)
{
return ResolveProject(repositoryRoot, repositoryRoot, perDeploymentSettings, fileFinder, tryWebSiteProject, searchOption, specificConfiguration: false);
Expand Down Expand Up @@ -241,7 +246,8 @@ private ISiteBuilder ResolveProject(string repositoryRoot, string targetPath, ID
perDeploymentSettings,
_propertyProvider,
repositoryRoot,
projectJson);
projectJson,
null);
}

if (tryWebSiteProject)
Expand Down Expand Up @@ -280,6 +286,7 @@ private ISiteBuilder ResolveProject(string repositoryRoot, string targetPath, ID
return ResolveNonAspProject(repositoryRoot, targetPath, perDeploymentSettings);
}

// used when we have a project file
private ISiteBuilder DetermineProject(string repositoryRoot, string targetPath, IDeploymentSettingsManager perDeploymentSettings, IFileFinder fileFinder)
{
var solution = VsHelper.FindContainingSolution(repositoryRoot, targetPath, fileFinder);
Expand All @@ -297,11 +304,11 @@ private ISiteBuilder DetermineProject(string repositoryRoot, string targetPath,
else if (AspNetCoreHelper.IsDotnetCoreFromProjectFile(targetPath, projectTypeGuids))
{
return new AspNetCoreBuilder(_environment,
perDeploymentSettings,
_propertyProvider,
repositoryRoot,
targetPath,
solutionPath);
perDeploymentSettings,
_propertyProvider,
repositoryRoot,
targetPath,
solutionPath);
}
else if (VsHelper.IsExecutableProject(targetPath))
{
Expand All @@ -313,6 +320,15 @@ private ISiteBuilder DetermineProject(string repositoryRoot, string targetPath,
targetPath,
solutionPath);
}
else if (FunctionAppHelper.LooksLikeFunctionApp())
{
return new FunctionMsbuildBuilder(_environment,
perDeploymentSettings,
_propertyProvider,
repositoryRoot,
targetPath,
solutionPath);
}

throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
Resources.Error_ProjectNotDeployable,
Expand Down
30 changes: 3 additions & 27 deletions Kudu.Core/Deployment/Generator/WapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,12 @@

namespace Kudu.Core.Deployment.Generator
{
public class WapBuilder : GeneratorSiteBuilder
public class WapBuilder : MicrosoftSiteBuilder
{
private readonly string _projectPath;
private readonly string _solutionPath;

public WapBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectPath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath)
public WapBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string sourcePath, string projectFilePath, string solutionPath)
: base(environment, settings, propertyProvider, sourcePath, projectFilePath, solutionPath, "--aspWAP")
{
_projectPath = projectPath;
_solutionPath = solutionPath;
}

protected override string ScriptGeneratorCommandArguments
{
get
{
var commandArguments = new StringBuilder();
commandArguments.AppendFormat("--aspWAP \"{0}\"", _projectPath);

if (!String.IsNullOrEmpty(_solutionPath))
{
commandArguments.AppendFormat(" --solutionFile \"{0}\"", _solutionPath);
}
else
{
commandArguments.AppendFormat(" --no-solution", _solutionPath);
}

return commandArguments.ToString();
}
}

public override string ProjectType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace Kudu.Core.Deployment.Generator
namespace Kudu.Core.Infrastructure
{
public static class FunctionAppEnabler
internal static class FunctionAppHelper
{

public static bool LooksLikeFunctionApp()
{
return !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable(Constants.FunctionRunTimeVersion));
}

}
}
Loading

0 comments on commit fb9a9a6

Please sign in to comment.