Skip to content

Commit

Permalink
Fix broken Deployments for Node 12.9 and remove Oryx Symlink Files on…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
sanchitmehta authored Nov 25, 2019
1 parent 734b984 commit 35e5598
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
16 changes: 11 additions & 5 deletions Kudu.Core/Deployment/Oryx/AppServiceOryxArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,18 @@ public string GenerateOryxBuildCommand(DeploymentContext context)
// 10-LTS, 12-LTS should use versions 10, 12 etc
// Oryx Builder uses lts for major versions
Version = Version.Replace("lts", "").Replace("-", "");
if (string.IsNullOrEmpty(Version))
{
// Active LTS
Version = "10";
}
}

if (string.IsNullOrEmpty(Version) || Version.Contains("10.16", StringComparison.OrdinalIgnoreCase))
{
// Active LTS
Version = "10";
}
else if(Version.Contains("12.9", StringComparison.OrdinalIgnoreCase))
{
Version = "12";
}

OryxArgumentsHelper.AddLanguageVersion(args, Version);
break;
case Framework.Python:
Expand Down
22 changes: 22 additions & 0 deletions Kudu.Core/Infrastructure/FileSystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,28 @@ public static void CreateRelativeSymlink(string source, string destination, Time
process.WaitForExit();
}

public static void RemoveUnixSymlink(string filePath, TimeSpan timeout)
{
string directory = FileSystemHelpers.GetDirectoryName(filePath);
string cmd = String.Format("cd {0}; timeout {1}s rm {2}", directory, timeout.TotalSeconds, filePath);
var escapedArgs = cmd.Replace("\"", "\\\"");

var process = new Process
{
StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\""
}
};
process.Start();
process.WaitForExit();
}

private static void DeleteFileSystemInfo(FileSystemInfoBase fileSystemInfo, bool ignoreErrors)
{
if (!fileSystemInfo.Exists)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(document).ready(function () {
jQuery(document).ready(function () {
$.ajax({
type: "GET",
url: '/instance/all',
Expand Down
31 changes: 24 additions & 7 deletions Kudu.Services/Deployment/PushDeploymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,37 @@ private async Task<IActionResult> PushDeployAsync(ZipDeploymentInfo deploymentIn
HttpContext context)
{

var oryxManifestFile = Path.Combine(_environment.WebRootPath, "oryx-manifest.toml");
if (FileSystemHelpers.FileExists(oryxManifestFile))
{
_tracer.Step("Removing previous build artifact's manifest file");
FileSystemHelpers.DeleteFileSafe(oryxManifestFile);
}

var zipFilePath = Path.Combine(_environment.ZipTempPath, Guid.NewGuid() + ".zip");
if (_settings.RunFromLocalZip())
{
await WriteSitePackageZip(deploymentInfo, _tracer);
}
else
{
var oryxManifestFile = Path.Combine(_environment.WebRootPath, "oryx-manifest.toml");
if (FileSystemHelpers.FileExists(oryxManifestFile))
{
_tracer.Step("Removing previous build artifact's manifest file");
FileSystemHelpers.DeleteFileSafe(oryxManifestFile);
}

try
{
var nodeModulesSymlinkFile = Path.Combine(_environment.WebRootPath, "node_modules");
Mono.Unix.UnixSymbolicLinkInfo i = new Mono.Unix.UnixSymbolicLinkInfo(nodeModulesSymlinkFile);
if (i.FileType == Mono.Unix.FileTypes.SymbolicLink)
{
_tracer.Step("Removing node_modules symlink");
// TODO: Add support to remove Unix Symlink File in DeleteFileSafe
// FileSystemHelpers.DeleteFileSafe(nodeModulesSymlinkFile);
FileSystemHelpers.RemoveUnixSymlink(nodeModulesSymlinkFile, TimeSpan.FromSeconds(5));
}
}
catch(Exception)
{
// best effort
}

using (_tracer.Step("Writing zip file to {0}", zipFilePath))
{
if (!string.IsNullOrEmpty(context.Request.ContentType) &&
Expand Down

0 comments on commit 35e5598

Please sign in to comment.