in src/common/details/commands/command.cs [91:186]
private static void ZipCommand(ICommandValues values, string zipAsFile, string tempDirectory, bool verbose)
{
if (File.Exists(zipAsFile)) ZipFile.ExtractToDirectory(zipAsFile, tempDirectory);
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
var zipTarget = values.GetOrEmpty("x.command.zip.target");
var targetWebJob = zipTarget.ToLower() == "webjob";
// run.cmd or run.sh
var runScript = isWindows ? "run.cmd" : "run.sh";
if (verbose) Console.WriteLine($" Saving {runScript}... ");
var command = values.GetCommand();
var commandJob = "./" + command + ".job";
var runScriptPath = PathHelpers.Combine(tempDirectory, runScript)!;
if (targetWebJob)
{
var prefix = $"{Program.Name.ToUpper()}_X";
var setOutputPath = isWindows
? $"set {prefix}_OUTPUT_PATH=\nif not '%WEBJOBS_DATA_PATH%'=='' set {prefix}_OUTPUT_PATH=%WEBJOBS_DATA_PATH%\\%WEBJOBS_RUN_ID%"
: $"{prefix}_OUTPUT_PATH=; if [ ! -z \"$WEBJOBS_DATA_PATH\" ]; then {prefix}_OUTPUT_PATH=$(WEBJOBS_DATA_PATH)/$(WEBJOBS_RUN_ID); fi;";
FileHelpers.WriteAllText(runScriptPath, setOutputPath + Environment.NewLine, Encoding.Default);
}
var app = isWindows ? Program.Name : $"./{Program.Name}";
FileHelpers.AppendAllText(runScriptPath, $"{app} {command} --nodefaults @{commandJob}" + Environment.NewLine, Encoding.Default);
// settings.job
if (targetWebJob)
{
var settingsPath = "settings.job";
if (verbose) Console.WriteLine($" Saving {settingsPath}... ");
var settingsJson = "{ \"is_in_place\": true }";
settingsPath = PathHelpers.Combine(tempDirectory, "settings.job")!;
FileHelpers.WriteAllText(settingsPath, settingsJson, Encoding.Default);
}
// ./{command}.job and related files
var files = values.SaveAs(commandJob).Split(';');
foreach (var file in files)
{
FileHelpers.TryCopyFile(".", file, tempDirectory, null, verbose);
File.Delete(file);
}
// binaries
var sourcePath = AppContext.BaseDirectory;
var programExe = OperatingSystem.IsWindows() ? Program.Exe : Program.Exe.Replace(".exe", "");
FileHelpers.TryCopyFile(sourcePath, programExe, tempDirectory, null, verbose);
#if NETCOREAPP
FileHelpers.TryCopyFile(sourcePath, Program.Name, tempDirectory, null, verbose);
FileHelpers.TryCopyFile(sourcePath, Program.Dll, tempDirectory, null, verbose);
FileHelpers.TryCopyFile(sourcePath, "runtimeconfig.json", tempDirectory, null, verbose);
FileHelpers.TryCopyFile(sourcePath, $"{Program.Name}.runtimeconfig.json", tempDirectory, null, verbose);
#endif
var bindingAssembly = FileHelpers.GetAssemblyFileInfo(Program.BindingAssemblySdkType);
sourcePath = bindingAssembly.DirectoryName!;
FileHelpers.TryCopyFile(sourcePath, bindingAssembly.Name, tempDirectory, null, verbose);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string[] locations = { "", "runtimes/win-x64/native/", "../runtimes/win-x64/native/" };
FileHelpers.TryCopyFiles(PathHelpers.Combine(sourcePath, locations), Program.ZipIncludes, tempDirectory, null, null, verbose);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string[] locations = { "", "runtimes/linux-x64/native/", "../../runtimes/linux-x64/native/" };
FileHelpers.TryCopyFiles(PathHelpers.Combine(sourcePath, locations), Program.ZipIncludes, tempDirectory, "lib", ".so", verbose);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
string[] locations = { "", "runtimes/osx-x64/native/", "../../runtimes/osx-x64/native/" };
FileHelpers.TryCopyFiles(PathHelpers.Combine(sourcePath, locations), Program.ZipIncludes, tempDirectory, "lib", ".dylib", verbose);
}
// Dependent type assemblies (Linq Async, System.Interactive.Async and JMESPath)
// These assemblies are embedded in spx.exe when PublishAsSingleFile is set (Dependency package)
Type[] types = { typeof(System.Linq.AsyncEnumerable), typeof(System.Linq.AsyncEnumerableEx), typeof(DevLab.JmesPath.Parser), typeof(DevLab.JmesPath.JmesPath)};
foreach (var t in types)
{
var fi = FileHelpers.GetAssemblyFileInfo(t);
FileHelpers.TryCopyFile(fi.DirectoryName!, fi.Name, tempDirectory, null, verbose);
}
File.Delete(zipAsFile);
ZipFile.CreateFromDirectory(tempDirectory, zipAsFile);
Directory.Delete(tempDirectory, true);
}