Skip to content

Commit

Permalink
Merge pull request #1496 from Azure/dev
Browse files Browse the repository at this point in the history
Merge dev into master for release
  • Loading branch information
ankitkumarr authored Aug 15, 2019
2 parents 491c131 + 78351d1 commit eff964a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public override ICommandLineParserResult ParseArgs(string[] args)
Parser
.Setup<BuildOption>('b', "build")
.SetDefault(BuildOption.Default)
.WithDescription("Perform build action when deploying to a Linux function app. (accepts: remote)")
.Callback(bo => PublishBuildOption = bo);
Parser
.Setup<bool>("no-bundler")
Expand Down Expand Up @@ -129,7 +130,7 @@ public override async Task RunAsync()
// before starting any of the publish activity.
var additionalAppSettings = await ValidateFunctionAppPublish(functionApp, workerRuntime);

if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild)
if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild && PublishBuildOption != BuildOption.Remote)
{
if (DotnetHelpers.CanDotnetBuild())
{
Expand Down Expand Up @@ -448,25 +449,23 @@ private async Task<bool> HandleLinuxConsumptionPublish(string functionAppRoot, S
Func<Task<Stream>> zipFileStreamTask = () => ZipHelper.GetAppZipFile(functionAppRoot, BuildNativeDeps, buildOption, NoBuild, ignoreParser, AdditionalPackages, ignoreDotNetCheck: true);

// Consumption Linux, try squashfs as a package format.
if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == WorkerRuntime.python && !NoBuild && (BuildNativeDeps || buildOption == BuildOption.Remote))
if (buildOption == BuildOption.Remote)
{
await RemoveFunctionAppAppSetting(functionApp,
"WEBSITE_RUN_FROM_PACKAGE",
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"WEBSITE_CONTENTSHARE");
Task<DeployStatus> pollConsumptionBuild(HttpClient client) => KuduLiteDeploymentHelpers.WaitForConsumptionServerSideBuild(client, functionApp, AccessToken, ManagementURL);
var deployStatus = await PerformServerSideBuild(functionApp, zipFileStreamTask, pollConsumptionBuild);
return deployStatus == DeployStatus.Success;
}
else if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == WorkerRuntime.python && !NoBuild && BuildNativeDeps)
{
if (BuildNativeDeps)
{
await PublishRunFromPackage(functionApp, await PythonHelpers.ZipToSquashfsStream(await zipFileStreamTask()), $"{fileNameNoExtension}.squashfs");
return true;
}

// Remote build don't need sync trigger, container will be deallocated once the build is finished
if (buildOption == BuildOption.Remote)
{
await RemoveFunctionAppAppSetting(functionApp,
"WEBSITE_RUN_FROM_PACKAGE",
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"WEBSITE_CONTENTSHARE");
Task<DeployStatus> pollConsumptionBuild(HttpClient client) => KuduLiteDeploymentHelpers.WaitForConsumptionServerSideBuild(client, functionApp, AccessToken, ManagementURL);
var deployStatus = await PerformServerSideBuild(functionApp, zipFileStreamTask, pollConsumptionBuild);
return deployStatus == DeployStatus.Success;
}
}
else
{
Expand Down Expand Up @@ -636,6 +635,12 @@ await RetryHelper.Retry(async () =>

public async Task<DeployStatus> PerformServerSideBuild(Site functionApp, Func<Task<Stream>> zipFileFactory, Func<HttpClient, Task<DeployStatus>> deploymentStatusPollTask, bool attachRestrictedToken = true)
{
if (string.IsNullOrEmpty(functionApp.ScmUri))
{
throw new CliException($"Your function app {functionApp.SiteName} does not support remote build. " +
"To enable remote build, please update your function app to the latest verison by recreating it.");
}

using (var handler = new ProgressMessageHandler(new HttpClientHandler()))
using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler))
using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri(
Expand Down
1 change: 1 addition & 0 deletions src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<PackageReference Include="Autofac" Version="4.6.2" />
<PackageReference Include="Colors.Net" Version="1.1.0" />
<PackageReference Include="AccentedCommandLineParser" Version="2.0.0" />
<PackageReference Include="DotNetZip" Version="1.13.3" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.DurableTask.AzureStorage.Internal" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.5.10246" />
Expand Down
1 change: 1 addition & 0 deletions src/Azure.Functions.Cli/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal static class Constants
public const string PythonDockerImageVersionSetting = "FUNCTIONS_PYTHON_DOCKER_IMAGE";
public const string PythonDockerImageSkipPull = "FUNCTIONS_PYTHON_DOCKER_SKIP_PULL";
public const string PythonDockerRunCommand = "FUNCTIONS_PYTHON_DOCKER_RUN_COMMAND";
public const string PythonFunctionsLibrary = "azure-functions";
public const string FunctionsCoreToolsEnvironment = "FUNCTIONS_CORETOOLS_ENVIRONMENT";

public static string CliVersion => typeof(Constants).GetTypeInfo().Assembly.GetName().Version.ToString(3);
Expand Down
9 changes: 7 additions & 2 deletions src/Azure.Functions.Cli/Common/FileSystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ public static void DeleteDirectorySafe(string path, bool ignoreErrors = true)
DeleteFileSystemInfo(Instance.DirectoryInfo.FromDirectoryName(path), ignoreErrors);
}

public static IEnumerable<string> GetLocalFiles(string path, GitIgnoreParser ignoreParser = null, bool returnIgnored = false)
public static IEnumerable<string> GetLocalFiles(string path, GitIgnoreParser ignoreParser = null, bool returnIgnored = false,
IEnumerable<string> additionalIgnoredDirectories = null)
{
var ignoredDirectories = new[] { ".git", ".vscode" };
List<string> ignoredDirectories = new List<string>{ ".git", ".vscode" };
if (additionalIgnoredDirectories != null)
{
ignoredDirectories.AddRange(additionalIgnoredDirectories);
}
var ignoredFiles = new[] { ".funcignore", ".gitignore", "local.settings.json", "project.lock.json" };

foreach (var file in FileSystemHelpers.GetFiles(path, ignoredDirectories, ignoredFiles))
Expand Down
30 changes: 0 additions & 30 deletions src/Azure.Functions.Cli/Extensions/ZipArchiveExtensions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Azure.Functions.Cli/Helpers/PythonHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void CreateRequirements()
{
if (!FileSystemHelpers.FileExists(Constants.RequirementsTxt))
{
FileSystemHelpers.CreateFile(Constants.RequirementsTxt);
FileSystemHelpers.WriteAllTextToFile(Constants.RequirementsTxt, Constants.PythonFunctionsLibrary);
}
else
{
Expand Down
25 changes: 17 additions & 8 deletions src/Azure.Functions.Cli/Helpers/ZipHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using Azure.Functions.Cli.Common;
using Azure.Functions.Cli.Extensions;
using Colors.Net;
using Ionic.Zip;
using static Colors.Net.StringStaticMethods;

namespace Azure.Functions.Cli.Helpers
Expand Down Expand Up @@ -34,27 +34,36 @@ public static async Task<Stream> GetAppZipFile(string functionAppRoot, bool buil
{
throw new CliException("Pack command doesn't work for dotnet functions");
}
else
else if (GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnet && buildOption == BuildOption.Remote)
{
return CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser), functionAppRoot);
// Remote build for dotnet does not require bin and obj folders. They will be generated during the oryx build
return CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser, false, new string[] { "bin", "obj" }), functionAppRoot);
} else
{
return CreateZip(FileSystemHelpers.GetLocalFiles(functionAppRoot, ignoreParser, false), functionAppRoot);
}
}

public static Stream CreateZip(IEnumerable<string> files, string rootPath)
{
const int defaultBufferSize = 4096;
var fileStream = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, defaultBufferSize, FileOptions.DeleteOnClose);

using (var zip = new ZipArchive(fileStream, ZipArchiveMode.Create, leaveOpen: true))
using (ZipFile zip = new ZipFile())
{
foreach (var fileName in files)
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;
foreach (var file in files)
{
zip.AddFile(fileName, fileName, rootPath);
zip.AddFile(file.FixFileNameForZip(rootPath));
}
zip.Save(fileStream);
}

fileStream.Seek(0, SeekOrigin.Begin);
return fileStream;
}

public static string FixFileNameForZip(this string value, string zipRoot)
{
return value.Substring(zipRoot.Length).TrimStart(new[] { '\\', '/' }).Replace('\\', '/');
}
}
}
3 changes: 1 addition & 2 deletions src/Azure.Functions.Cli/StaticResources/funcignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
.git*
.vscode
local.settings.json
test
tsconfig.json
test
2 changes: 1 addition & 1 deletion tools/python/packapp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def build_independent_wheel(name, version, args, dest):

def build_binary_wheel(name, version, args, dest):
die(f'cannot install {name}-{version} dependency: binary dependencies '
f'without wheels are not supported. Use the --build-native-deps option '
f'without wheels are not supported. Use the "--build remote" or "--build-native-deps" option '
f'to automatically build and configure the dependencies using a Docker container. '
f'More information at https://aka.ms/func-python-publish', ExitCode.native_deps_error)

Expand Down

0 comments on commit eff964a

Please sign in to comment.