Skip to content

Commit

Permalink
Merge Dev into Master (#116)
Browse files Browse the repository at this point in the history
* Add a silent try catch while printing previous log tail (#87)

* Added console event generator for kudu (#85)

* Fixed the bug where symlinks couldn't be created for zip extraction + (#84)

added recursive permissions change for zip deploy/zip controller

* ANT84 Linux Consumption Remote Build Patch (#88)

* ANT84 Linux Consumption Server Side Build Patch

* Add logger for dependencies

* Remove zip context validation

* Fix error message when doing zip deploy with WEBSITE_RUN_FROM_PACKAGE

* Add ability to grab the FRAMEWORK_VERSION for function apps (#91)

* Kudu Fixes (#90)

* Using Log4Net to generate kudu event logs

* Added lts support for Oryx on NODE. Made compressing python packages default. Fixed minor bugs with kudu event logs

* Changed the log path in Log4Net config

* Added Express Build support for NETCore. Added a filter to avoid excessive logging for certain paths.

* Modified python compress arguments

* Added debug arguments for oryx build

* Added a fix for NETCore express build scenario + Removing Oryx Manifest file for Zip Deploy

* Minor change

* Fix python 3.7 path in Oryx Build (#92)

* Fix python 3.7 path

* Fix syntax

* Fix missing Docker logs (#96)

* Fix missing Docker logs

* Retrieve logs for the last seven days from the latest timestamp

* Added KuduConsole Log4Net logger + Some Bug Fixes (#97)

* Added log4net support for KuduConsole

* Fix FileNotFound exception for LogStream Service

* Fix Oryx Build command not picking up the version

* ANT86 add zipdeploy endpoint support for ARM call (#94)

* Add zipdeploy endpoint for ANT86

* Remove ZipDeployController

* ANT86 Patch on Linux Consumption Remote Build (#95)

* Warm up linux conusmption function app after remote build

* Also take SCM_RUN_FROM_PACKAGE from app setting

* Trigger a recycle after wardeploy (#98)

* Trigger a recycle after wardeploy

- This is a port of this PR - projectkudu/kudu#3050 - from the Kudu repo.
- Current implementation of /wardeploy triggers a recycle of container, only on Xenon and Linux. This recycle is performed using the restartTrigger.txt file.
- This commit adds support to /wardeploy for triggering a recycle of classic Windows web apps in addition to just Xenon and Linux, if the app setting WEBSITE_RECYCLE_PREVIEW_ENABLED is defined. Besides, the recyle will be performed using the /api/app/restart API.
- The new behavior is hidden behind a WEBSITE_RECYCLE_PREVIEW_ENABLED flag, which is added only temporarily. This flag will eventually be removed and the new behavior will become the default.

* Incorporated CR comment

* Kudu Fixes + Enhancements - Oct (#101)

* Adding some trace to zip formation

* Added Artifacts support as a flag

* Fix broken Deployments for Node 12.9 and remove Oryx Symlink Files on Zip Deploy (#102)

* Fixing node_modules symlink deletion +

* Add support to remove the symlink file using rm

* Fix Node 10.16/12.9 broken deployments

* Add Intermediate directory support for PHP (#103)

* Update function app language version regex to take account lengthy function version (#108)

* Add SyncTriggers query param for zipdeploy in Linux Consumption (#106)

* Update deeplink to Linux troubleshoot page

Same change as projectkudu/kudu#3139

* Added NoOpBuilder for static site stack (#115)

* Added NoOpBuilder

* Use FRAMEWORK env variable to choose NoOpBuilder

* Check for NoOpBuilder before check for Oryx builder

Co-authored-by: Hanzhang Zeng (Roger) <48038149+Hazhzeng@users.noreply.github.com>
Co-authored-by: Ankit Kumar <ankikuma@microsoft.com>
Co-authored-by: michimune <michimune@outlook.com>
Co-authored-by: Shrirang Shirodkar <shrishrirang@users.noreply.github.com>
Co-authored-by: purva-vasudeo <61296267+purva-vasudeo@users.noreply.github.com>
  • Loading branch information
6 people authored Apr 20, 2020
1 parent f2d8346 commit 0a5e658
Show file tree
Hide file tree
Showing 61 changed files with 1,788 additions and 657 deletions.
5 changes: 4 additions & 1 deletion Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public static TimeSpan MaxAllowedExecutionTime
public const string LogicAppJson = "logicapp.json";
public const string LogicAppUrlKey = "LOGICAPP_URL";

public const string RestartApiPath = "/api/app/restart";

public const string SiteExtensionProvisioningStateCreated = "Created";
public const string SiteExtensionProvisioningStateAccepted = "Accepted";
public const string SiteExtensionProvisioningStateSucceeded = "Succeeded";
Expand All @@ -118,6 +120,7 @@ public static TimeSpan MaxAllowedExecutionTime
public const string SiteRestrictedToken = "x-ms-site-restricted-token";
public const string SiteAuthEncryptionKey = "WEBSITE_AUTH_ENCRYPTION_KEY";
public const string HttpHost = "HTTP_HOST";
public const string HttpAuthority = "HTTP_AUTHORITY";
public const string WebSiteSwapSlotName = "WEBSITE_SWAP_SLOTNAME";
public const string AzureWebsiteInstanceId = "WEBSITE_INSTANCE_ID";
public const string ContainerName = "CONTAINER_NAME";
Expand Down Expand Up @@ -145,7 +148,7 @@ public static TimeSpan MaxAllowedExecutionTime
public const string Extensions = "extensions";
public const string SitePackages = "SitePackages";
public const string PackageNameTxt = "packagename.txt";
public const string KuduBuild = "1.0.0.6";
public const string KuduBuild = "1.0.0.7";

public const string WebSSHReverseProxyPortEnvVar = "KUDU_WEBSSH_PORT";
public const string WebSSHReverseProxyDefaultPort = "3000";
Expand Down
5 changes: 5 additions & 0 deletions Kudu.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Kudu.Core.Tracing;
using System.Reflection;
using XmlSettings;
using log4net;
using log4net.Config;

namespace Kudu.Console
{
Expand All @@ -30,6 +32,9 @@ internal class Program

private static int Main(string[] args)
{
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

// Turn flag on in app.config to wait for debugger on launch
if (ConfigurationManager.AppSettings["WaitForDebuggerOnStart"] == "true")
{
Expand Down
19 changes: 19 additions & 0 deletions Kudu.Console/log4net.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<file type="log4net.Util.PatternString" value="/var/log/kudulogs/%utcdate{yyyy-MM-dd}_%env{COMPUTERNAME}_scm_console_docker.log" />
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<appendToFile value="true" />
<maxSizeRollBackups value="10"/>
<maximumFileSize value="5MB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy-MM-dd-HH:mm:ss.fff} %message%n" />
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
</log4net>
8 changes: 8 additions & 0 deletions Kudu.Contracts/Deployment/DeploymentInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Kudu.Core.SourceControl;
using Kudu.Contracts.Tracing;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;

namespace Kudu.Core.Deployment
{
Expand All @@ -28,6 +30,8 @@ protected DeploymentInfoBase()
public FetchDelegate Fetch { get; set; }
public bool AllowDeploymentWhileScmDisabled { get; set; }

public IDictionary<string, string> repositorySymlinks { get; set; }

// Optional.
// Path of the directory to be deployed to. The path should be relative to the wwwroot directory.
// Example: "webapps/ROOT"
Expand Down Expand Up @@ -68,5 +72,9 @@ public bool IsValid()
// won't update until after a process restart. Therefore, we copy the needed
// files into a separate folders and run sync triggers from there.
public string SyncFunctionsTriggersPath { get; set; } = null;

// If DoSyncTriggers is set to true, the after Linux Consumption function app deployment,
// will initiate a POST request to http://appname.azurewebsites.net/admin/host/synctriggers
public bool DoSyncTriggers { get; set; }
}
}
24 changes: 16 additions & 8 deletions Kudu.Contracts/Settings/DeploymentSettingsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,22 @@ public static bool IsDockerCiEnabled(this IDeploymentSettingsManager settings)
return StringUtils.IsTrueLike(value);
}

public static bool RestartAppContainerOnGitDeploy(this IDeploymentSettingsManager settings)
{
string value = settings.GetValue(SettingsKeys.LinuxRestartAppContainerAfterDeployment);

// Default is true
return value == null || StringUtils.IsTrueLike(value);
}

public static bool RestartAppOnGitDeploy(this IDeploymentSettingsManager settings)
{
string value = settings.GetValue(SettingsKeys.RestartAppAfterDeployment);

// Default is true
return value == null || StringUtils.IsTrueLike(value);
}

public static bool RecylePreviewEnabled(this IDeploymentSettingsManager settings)
{
string value = settings.GetValue(SettingsKeys.RecyclePreviewEnabled);

// Default value, if setting is not explicitly defined, is false
return StringUtils.IsTrueLike(value);
}

public static bool DoBuildDuringDeployment(this IDeploymentSettingsManager settings)
{
string value = settings.GetValue(SettingsKeys.DoBuildDuringDeployment);
Expand Down
14 changes: 11 additions & 3 deletions Kudu.Contracts/Settings/SettingsKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ public static class SettingsKeys
public const string DisableDeploymentOnPush = "SCM_DISABLE_DEPLOY_ON_PUSH";
public const string TouchWebConfigAfterDeployment = "SCM_TOUCH_WEBCONFIG_AFTER_DEPLOYMENT";
public const string MaxRandomDelayInSec = "SCM_MAX_RANDOM_START_DELAY";
public const string DockerCiEnabled = "DOCKER_ENABLE_CI";
public const string LinuxRestartAppContainerAfterDeployment = "SCM_RESTART_APP_CONTAINER_AFTER_DEPLOYMENT";
public const string DockerCiEnabled = "DOCKER_ENABLE_CI";

// This app-setting works for all kinds of apps, including classic Windows apps (not just container-based apps).
// To make it work for Windows apps, the app-setting WEBSITE_RECYCLE_PREVIEW_ENABLED=1 needs to be defined.
public const string RestartAppAfterDeployment = "SCM_RESTART_APP_CONTAINER_AFTER_DEPLOYMENT";

public const string DoBuildDuringDeployment = "SCM_DO_BUILD_DURING_DEPLOYMENT";
public const string RunFromZipOld = "WEBSITE_RUN_FROM_ZIP"; // Old name, will eventually go away
public const string RunFromZip = "WEBSITE_RUN_FROM_PACKAGE";
public const string RunFromZip = "WEBSITE_RUN_FROM_PACKAGE";

// Temporary flag intended only for testing purposes. Will not be supported for too long.
public const string RecyclePreviewEnabled = "WEBSITE_RECYCLE_PREVIEW_ENABLED";

public const string MaxZipPackageCount = "SCM_MAX_ZIP_PACKAGE_COUNT";
// Antares container specific settings
public const string PlaceholderMode = "WEBSITE_PLACEHOLDER_MODE";
Expand Down
27 changes: 26 additions & 1 deletion Kudu.Core/Deployment/DeploymentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using Kudu.Contracts.Tracing;
using Kudu.Core.Deployment.Generator;
using Kudu.Core.Deployment.Oryx;
using Kudu.Core.Infrastructure;
using Kudu.Core.SourceControl;
Expand Down Expand Up @@ -52,7 +53,31 @@ public static bool IsDefaultWebRootContent(string webroot)

return false;
}


public static void PurgeOldDeploymentsIfNecessary(string deploymentsPath, ITracer tracer, int totalAllowedDeployments)
{
IEnumerable<string> deploymentNames = FileSystemHelpers.GetDirectories(deploymentsPath);
if (deploymentNames.Count() > totalAllowedDeployments)
{
// Order the files in descending order of the modified date and remove the last (N - allowed zip files).
var deploymentsToDelete = deploymentNames.OrderByDescending(fileName => FileSystemHelpers.GetLastWriteTimeUtc(fileName)).Skip(totalAllowedDeployments);
foreach (var deploymentName in deploymentsToDelete)
{
using (tracer.Step("Purging old deployment {0}", deploymentName))
{
try
{
FileSystemHelpers.DeleteDirectorySafe(deploymentName);
}
catch (Exception ex)
{
tracer.TraceError(ex, "Unable to delete deployment {0}", deploymentName);
}
}
}
}
}

public static void PurgeBuildArtifactsIfNecessary(string sitePackagesPath, BuildArtifactType fileExtension, ITracer tracer, int totalAllowedFiles)
{
string extension = fileExtension.ToString().ToLowerInvariant();
Expand Down
51 changes: 41 additions & 10 deletions Kudu.Core/Deployment/DeploymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Kudu.Contracts.Infrastructure;
using Kudu.Contracts.Settings;
Expand Down Expand Up @@ -248,14 +249,6 @@ public async Task DeployAsync(

// Perform the build deployment of this changeset
await Build(changeSet, tracer, deployStep, repository, deploymentInfo, deploymentAnalytics, fullBuildByDefault);

if (!(OSDetector.IsOnWindows() &&
!EnvironmentHelper.IsWindowsContainers()) &&
_settings.RestartAppContainerOnGitDeploy())
{
logger.Log(Resources.Log_TriggeringContainerRestart);
DockerContainerRestartTrigger.RequestContainerRestart(_environment, RestartTriggerReason);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -298,8 +291,32 @@ public async Task DeployAsync(
}

}
}

}

public async Task RestartMainSiteIfNeeded(ITracer tracer, ILogger logger)
{
// If post-deployment restart is disabled, do nothing.
if (!_settings.RestartAppOnGitDeploy())
{
return;
}

if (_settings.RecylePreviewEnabled())
{
logger.Log("Triggering recycle (preview mode enabled).");
tracer.Trace("Triggering recycle (preview mode enabled).");

await PostDeploymentHelper.RestartMainSiteAsync(_environment.RequestId, new PostDeploymentTraceListener(tracer, logger));
}
else
{
logger.Log("Triggering recycle (preview mode disabled).");
tracer.Trace("Triggering recycle (preview mode disabled).");

DockerContainerRestartTrigger.RequestContainerRestart(_environment, RestartTriggerReason, tracer);
}
}

public IDisposable CreateTemporaryDeployment(string statusText, out ChangeSet tempChangeSet, ChangeSet changeSet = null, string deployedBy = null)
{
var tracer = _traceFactory.GetTracer();
Expand Down Expand Up @@ -364,6 +381,9 @@ private void MarkStatusComplete(IDeploymentStatusFile status, bool success)
{
if (success)
{
// Mitigation when status file is busy,
// and update fails
Thread.Sleep(200);
status.MarkSuccess();
}
else
Expand Down Expand Up @@ -684,6 +704,17 @@ private async Task Build(
await builder.Build(context);
builder.PostBuild(context);

await RestartMainSiteIfNeeded(tracer, logger);

if (FunctionAppHelper.LooksLikeFunctionApp() && _environment.IsOnLinuxConsumption)
{
// A Linux consumption function app deployment requires (no matter whether it is oryx build or basic deployment)
// 1. packaging the output folder
// 2. upload the artifact to user's storage account
// 3. reset the container workers after deployment
await LinuxConsumptionDeploymentHelper.SetupLinuxConsumptionFunctionAppDeployment(_environment, _settings, context, deploymentInfo.DoSyncTriggers);
}

await PostDeploymentHelper.SyncFunctionsTriggers(
_environment.RequestId,
new PostDeploymentTraceListener(tracer, logger),
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Core/Deployment/FetchDeploymentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Abstractions;
using System.Threading.Tasks;
using Kudu.Contracts.Infrastructure;
using Kudu.Contracts.Settings;
Expand Down Expand Up @@ -125,7 +126,6 @@ public async Task<FetchDeploymentRequestResult> FetchDeploy(
}

await PerformDeployment(deployInfo);
Console.WriteLine("\n\n\n\n Perform deployment Over\n\n\n");
return FetchDeploymentRequestResult.RanSynchronously;
}, "Performing continuous deployment", TimeSpan.Zero);
}
Expand Down
17 changes: 17 additions & 0 deletions Kudu.Core/Deployment/Generator/NoOpBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Kudu.Contracts.Settings;

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

public override string ProjectType
{
get { return "NoOp"; }
}
}
}
Loading

0 comments on commit 0a5e658

Please sign in to comment.