Merge pull request #1436 from sbwalker/dev

separated updater from main solution
This commit is contained in:
Shaun Walker 2021-06-03 08:34:02 -04:00 committed by GitHub
commit ae2caacc81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 81 additions and 63 deletions

View File

@ -51,7 +51,7 @@
List<Package> packages = await PackageService.GetPackagesAsync("framework"); List<Package> packages = await PackageService.GetPackagesAsync("framework");
if (packages != null) if (packages != null)
{ {
_package = packages.FirstOrDefault(); _package = packages.Where(item => item.PackageId.StartsWith(Constants.PackageId)).FirstOrDefault();
if (_package != null) if (_package != null)
{ {
_upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0); _upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0);
@ -89,7 +89,7 @@
try try
{ {
await PackageService.DownloadPackageAsync(packageid, version, "Packages"); await PackageService.DownloadPackageAsync(packageid, version, "Packages");
await PackageService.DownloadPackageAsync("Oqtane.Upgrade", version, "Packages"); await PackageService.DownloadPackageAsync(Constants.UpdaterPackageId, version, "Packages");
AddModuleMessage(Localizer["Framework Downloaded Successfully... Please Select Upgrade To Complete the Process"], MessageType.Success); AddModuleMessage(Localizer["Framework Downloaded Successfully... Please Select Upgrade To Complete the Process"], MessageType.Success);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>Oqtane.Upgrade</id> <id>Oqtane.Updater</id>
<version>2.1.0</version> <version>2.1.0</version>
<authors>Shaun Walker</authors> <authors>Shaun Walker</authors>
<owners>.NET Foundation</owners> <owners>.NET Foundation</owners>
@ -14,10 +14,10 @@
<projectUrl>https://github.com/oqtane/oqtane.framework</projectUrl> <projectUrl>https://github.com/oqtane/oqtane.framework</projectUrl>
<releaseNotes>https://github.com/oqtane/oqtane.framework/releases/tag/v2.1.0</releaseNotes> <releaseNotes>https://github.com/oqtane/oqtane.framework/releases/tag/v2.1.0</releaseNotes>
<icon>icon.png</icon> <icon>icon.png</icon>
<tags>oqtane upgrade</tags> <tags>oqtane</tags>
</metadata> </metadata>
<files> <files>
<file src="..\Oqtane.Server\bin\Release\net5.0\Oqtane.Upgrade.*" target="lib\net5.0" /> <file src="..\Oqtane.Updater\bin\Release\net5.0\publish\*.*" target="lib\net5.0" />
<file src="icon.png" target="" /> <file src="icon.png" target="" />
</files> </files>
</package> </package>

View File

@ -5,7 +5,6 @@ copy /Y/B/V "..\Oqtane.Server\bin\Release\net5.0\System.Drawing.Common.dll" "..\
nuget.exe pack Oqtane.Client.nuspec nuget.exe pack Oqtane.Client.nuspec
nuget.exe pack Oqtane.Server.nuspec nuget.exe pack Oqtane.Server.nuspec
nuget.exe pack Oqtane.Shared.nuspec nuget.exe pack Oqtane.Shared.nuspec
nuget.exe pack Oqtane.Upgrade.nuspec
nuget.exe pack Oqtane.Framework.nuspec nuget.exe pack Oqtane.Framework.nuspec
del /F/Q/S "..\Oqtane.Server\bin\Release\net5.0\publish" > NUL del /F/Q/S "..\Oqtane.Server\bin\Release\net5.0\publish" > NUL
rmdir /Q/S "..\Oqtane.Server\bin\Release\net5.0\publish" rmdir /Q/S "..\Oqtane.Server\bin\Release\net5.0\publish"
@ -14,7 +13,10 @@ del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
ren "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.release.json" "appsettings.json" ren "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.release.json" "appsettings.json"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\install.ps1" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\install.ps1"
del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json" del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
del "..\Oqtane.Server\bin\Release\net5.0\publish\Oqtane.Upgrade.*"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\upgrade.ps1" C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\upgrade.ps1"
dotnet clean -c Release ..\Oqtane.Updater.sln
dotnet build -c Release ..\Oqtane.Updater.sln
dotnet publish ..\Oqtane.Updater\Oqtane.Updater.csproj /p:Configuration=Release
nuget.exe pack Oqtane.Updater.nuspec
pause pause

View File

@ -264,34 +264,38 @@ namespace Oqtane.Infrastructure
// ensure package version is greater than or equal to current framework version // ensure package version is greater than or equal to current framework version
if (packageversion != "" && Version.Parse(Constants.Version).CompareTo(Version.Parse(packageversion)) <= 0 && packageurl != "") if (packageversion != "" && Version.Parse(Constants.Version).CompareTo(Version.Parse(packageversion)) <= 0 && packageurl != "")
{ {
// install upgrade nuget package // install Oqtane.Framework and Oqtane.Updater nuget packages
InstallPackages(); InstallPackages();
// download upgrade zip package // download upgrade zip package
var client = new WebClient(); var client = new WebClient();
Uri uri = new Uri(packageurl); Uri uri = new Uri(packageurl);
client.DownloadFile(packageurl, Path.Combine(folder, uri.Segments[uri.Segments.Length - 1])); string upgradepackage = Path.Combine(folder, uri.Segments[uri.Segments.Length - 1]);
// install upgrade zip package client.DownloadFile(packageurl, upgradepackage);
// install Oqtane.Upgrade zip package
if (File.Exists(upgradepackage))
{
FinishUpgrade(); FinishUpgrade();
} }
} }
} }
} }
}
private void FinishUpgrade() private void FinishUpgrade()
{ {
// check if upgrade application exists // check if updater application exists
string Upgrader = "Oqtane.Upgrade.dll"; string Updater = Constants.UpdaterPackageId + ".dll";
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
if (folder == null || !File.Exists(Path.Combine(folder, Upgrader))) return; if (folder == null || !File.Exists(Path.Combine(folder, Updater))) return;
// run upgrade application // run updater application
using (var process = new Process()) using (var process = new Process())
{ {
process.StartInfo = new ProcessStartInfo process.StartInfo = new ProcessStartInfo
{ {
WorkingDirectory = folder, WorkingDirectory = folder,
FileName = "dotnet", FileName = "dotnet",
Arguments = Path.Combine(folder, Upgrader) + " \"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"", Arguments = Path.Combine(folder, Updater) + " \"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"",
UseShellExecute = false, UseShellExecute = false,
ErrorDialog = false, ErrorDialog = false,
CreateNoWindow = true, CreateNoWindow = true,

View File

@ -48,18 +48,12 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Oqtane.Client\Oqtane.Client.csproj" /> <ProjectReference Include="..\Oqtane.Client\Oqtane.Client.csproj" />
<ProjectReference Include="..\Oqtane.Shared\Oqtane.Shared.csproj" /> <ProjectReference Include="..\Oqtane.Shared\Oqtane.Shared.csproj" />
<ProjectReference Include="..\Oqtane.Upgrade\Oqtane.Upgrade.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.deps.json" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.dll" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.pdb" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.runtimeconfig.json" />
<ModuleTemplateFiles Include="$(ProjectDir)wwwroot\Modules\Templates\**\*.*" /> <ModuleTemplateFiles Include="$(ProjectDir)wwwroot\Modules\Templates\**\*.*" />
<ThemeTemplateFiles Include="$(ProjectDir)wwwroot\Themes\Templates\**\*.*" /> <ThemeTemplateFiles Include="$(ProjectDir)wwwroot\Themes\Templates\**\*.*" />
</ItemGroup> </ItemGroup>
<Target Name="AddPayloadsFolder" AfterTargets="Publish"> <Target Name="AddPayloadsFolder" AfterTargets="Publish">
<Copy SourceFiles="@(UpgradeFiles)" DestinationFiles="@(UpgradeFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
<Copy SourceFiles="@(ModuleTemplateFiles)" DestinationFiles="@(ModuleTemplateFiles->'$(PublishDir)wwwroot\Modules\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" /> <Copy SourceFiles="@(ModuleTemplateFiles)" DestinationFiles="@(ModuleTemplateFiles->'$(PublishDir)wwwroot\Modules\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
<Copy SourceFiles="@(ThemeTemplateFiles)" DestinationFiles="@(ThemeTemplateFiles->'$(PublishDir)wwwroot\Themes\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" /> <Copy SourceFiles="@(ThemeTemplateFiles)" DestinationFiles="@(ThemeTemplateFiles->'$(PublishDir)wwwroot\Themes\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
</Target></Project> </Target></Project>

View File

@ -3,9 +3,10 @@ using System;
namespace Oqtane.Shared { namespace Oqtane.Shared {
public class Constants { public class Constants {
public const string PackageId = "Oqtane.Framework";
public static readonly string Version = "2.1.0"; public static readonly string Version = "2.1.0";
public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0"; public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0";
public const string PackageId = "Oqtane.Framework";
public const string UpdaterPackageId = "Oqtane.Updater";
public const string DefaultDBType = "Oqtane.Database.SqlServer.SqlServerDatabase, Oqtane.Database.SqlServer"; public const string DefaultDBType = "Oqtane.Database.SqlServer.SqlServerDatabase, Oqtane.Database.SqlServer";

32
Oqtane.Updater.sln Normal file
View File

@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28822.285
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77EECA8C-B58E-469E-B8C5-D543AFC9A654}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Updater", "Oqtane.Updater\Oqtane.Updater.csproj", "{2E8C6889-37CF-4C8D-88B1-505547F25098}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1FB11796-35DE-4AED-9A52-17733557FCC4}
EndGlobalSection
EndGlobal

View File

@ -18,11 +18,4 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\Oqtane.Server\bin\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Oqtane.Server\bin\Debug\</OutputPath>
</PropertyGroup>
</Project> </Project>

View File

@ -4,10 +4,14 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Threading; using System.Threading;
namespace Oqtane.Upgrade namespace Oqtane.Updater
{ {
class Program class Program
{ {
/// <summary>
/// This console application is responsible for extracting the contents of a previously downloaded Oqtane Upgrade package
/// </summary>
/// <param name="args"></param>
static void Main(string[] args) static void Main(string[] args)
{ {
// requires 2 arguments - the ContentRootPath and the WebRootPath of the site // requires 2 arguments - the ContentRootPath and the WebRootPath of the site
@ -22,11 +26,12 @@ namespace Oqtane.Upgrade
string contentrootfolder = args[0]; string contentrootfolder = args[0];
string webrootfolder = args[1]; string webrootfolder = args[1];
string deployfolder = Path.Combine(contentrootfolder, "Packages"); string deployfolder = Path.Combine(contentrootfolder, "Packages");
string backupfolder = Path.Combine(contentrootfolder, "Backup");
if (Directory.Exists(deployfolder)) if (Directory.Exists(deployfolder))
{ {
string packagename = ""; string packagename = "";
string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Framework.*.nupkg"); string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Upgrade.*.zip");
if (packages.Length > 0) if (packages.Length > 0)
{ {
packagename = packages[packages.Length - 1]; // use highest version packagename = packages[packages.Length - 1]; // use highest version
@ -40,7 +45,7 @@ namespace Oqtane.Upgrade
File.Copy(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm"), true); File.Copy(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm"), true);
} }
// get list of files in package // get list of files in package with local paths
List<string> files = new List<string>(); List<string> files = new List<string>();
using (ZipArchive archive = ZipFile.OpenRead(packagename)) using (ZipArchive archive = ZipFile.OpenRead(packagename))
{ {
@ -55,18 +60,22 @@ namespace Oqtane.Upgrade
{ {
try try
{ {
// create backup //clear out backup folder
if (Directory.Exists(backupfolder))
{
Directory.Delete(backupfolder, true);
}
Directory.CreateDirectory(backupfolder);
// backup files
foreach (string file in files) foreach (string file in files)
{ {
if (File.Exists(file)) string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder, ""));
if (!Directory.Exists(Path.GetDirectoryName(filename)))
{ {
// remove previous backup if it exists Directory.CreateDirectory(Path.GetDirectoryName(filename));
if (File.Exists(file + ".bak"))
{
File.Delete(file + ".bak");
}
File.Move(file, file + ".bak");
} }
File.Copy(file, filename);
} }
// extract files // extract files
@ -96,14 +105,7 @@ namespace Oqtane.Upgrade
if (success) if (success)
{ {
// clean up backup // clean up backup
foreach (string file in files) Directory.Delete(backupfolder, true);
{
if (File.Exists(file + ".bak"))
{
File.Delete(file + ".bak");
}
}
// delete package // delete package
File.Delete(packagename); File.Delete(packagename);
} }
@ -112,15 +114,11 @@ namespace Oqtane.Upgrade
// restore on failure // restore on failure
foreach (string file in files) foreach (string file in files)
{ {
if (File.Exists(file)) string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder, ""));
{ File.Copy(filename, file);
File.Delete(file);
}
if (File.Exists(file + ".bak"))
{
File.Move(file + ".bak", file);
}
} }
// clean up backup
Directory.Delete(backupfolder, true);
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Client", "Oqtane.Cli
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Shared", "Oqtane.Shared\Oqtane.Shared.csproj", "{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Shared", "Oqtane.Shared\Oqtane.Shared.csproj", "{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Upgrade", "Oqtane.Upgrade\Oqtane.Upgrade.csproj", "{2E8C6889-37CF-4C8D-88B1-505547F25098}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Test", "Oqtane.Test\Oqtane.Test.csproj", "{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Test", "Oqtane.Test\Oqtane.Test.csproj", "{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77EECA8C-B58E-469E-B8C5-D543AFC9A654}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77EECA8C-B58E-469E-B8C5-D543AFC9A654}"
@ -38,10 +36,6 @@ Global
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.Build.0 = Release|Any CPU {19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.Build.0 = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.Build.0 = Release|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.Build.0 = Debug|Any CPU {823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.Build.0 = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Release|Any CPU.ActiveCfg = Release|Any CPU {823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Release|Any CPU.ActiveCfg = Release|Any CPU