Skip to content

Commit 64f9ce0

Browse files
author
Chris Maunder
committed
2 parents 4b3f15d + 79fd70a commit 64f9ce0

File tree

9 files changed

+44
-16
lines changed

9 files changed

+44
-16
lines changed

devops/build/create_packages.bat

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ set rootDirPath=%cd%
6262
popd
6363
set sdkPath=%rootDirPath%\%srcDir%\%sdkDir%
6464
set utilsScriptsDirPath=%rootDirPath%\%srcDir%\scripts
65-
set utilsScript=!utilsScriptsDirPath!\utils.bat
65+
set utilsScript=%utilsScriptsDirPath%\utils.bat
6666

6767
:: Override some values via parameters ::::::::::::::::::::::::::::::::::::::::
6868

@@ -105,7 +105,6 @@ set modulesDirPath=!rootDirPath!\!modulesDir!
105105
set externalModulesDirPath=!rootDirPath!\..\!externalModulesDir!
106106
set packageDirPath=!rootDirPath!\!packageDir!
107107

108-
if [ ! -d "${packageDirPath}" ]; then mkdir -p "${packageDirPath}"; fi
109108
if not exist "!packageDirPath!" mkdir "!packageDirPath!"
110109

111110

src/SDK/NET/Modules/ModuleBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ public static bool IsCompatible(this ModuleBase module, string? currentServerVer
327327
available = platformOK;
328328
}
329329

330-
// Final check: is the module specifically excluded from the current platform?
331330
return available;
332331
}
333332
}

src/SDK/NET/Modules/ModuleDescription.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ public static class ModuleDescriptionExtensions
169169
/// <param name="module">This module that requires initialisation</param>
170170
/// <param name="currentServerVersion">The current version of the server</param>
171171
/// <param name="moduleDirPath">The path to the folder containing this module</param>
172+
/// <param name="moduleStorageUrl">The base URL for downloading module install packages</param>
172173
/// <param name="moduleLocation">The location of this module</param>
173174
/// <returns>True on success; false otherwise</returns>
174175
public static void Initialise(this ModuleDescription module, string currentServerVersion,
175-
string moduleDirPath, ModuleLocation moduleLocation)
176+
string moduleDirPath, string moduleStorageUrl,
177+
ModuleLocation moduleLocation)
176178
{
177179
module.ModuleDirPath = moduleDirPath;
178180
module.WorkingDirectory = module.ModuleDirPath; // This once was allowed to be different to moduleDirPath
@@ -181,6 +183,14 @@ public static void Initialise(this ModuleDescription module, string currentServe
181183
module.CheckVersionAgainstModuleReleases();
182184
SetLatestCompatibleVersion(module, currentServerVersion);
183185

186+
// When we downloaded this list from CodeProject the download URL was set. When we get
187+
// this list from a modules.json file (eg off github) then the download Url isn't set
188+
if (string.IsNullOrWhiteSpace(module.DownloadUrl))
189+
{
190+
// TODO: Generalise this in a utility method
191+
module.DownloadUrl = $"{moduleStorageUrl}{module.ModuleId}-{module.Version}.zip";
192+
}
193+
184194
// Set the status of all entries based on availability on this platform
185195
module.Status = module.IsCompatible(currentServerVersion)
186196
? ModuleStatusType.Available : ModuleStatusType.NotAvailable;

src/server/Config/ModuleOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public class ModuleOptions
2323
/// </summary>
2424
public string? AssetStorageUrl { get; set; }
2525

26+
/// <summary>
27+
/// The URL of the location of the module installation packages that can be downloaded.
28+
/// </summary>
29+
public string? ModuleStorageUrl { get; set; }
30+
2631
/// <summary>
2732
/// Gets or sets the timeout for installing a module
2833
/// </summary>

src/server/Controllers/ModuleController.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ public async Task<ServerResponse> ListInstalledModules()
130130
string currentServerVersion = _versionConfig.VersionInfo!.Version;
131131

132132
var modules = _installedModules?.Values?
133-
.Select(module => ModuleInstaller.ModuleDescriptionFromModuleConfig(module, true,
134-
currentServerVersion))
133+
.Select(module => ModuleInstaller.ModuleDescriptionFromModuleConfig(module,
134+
_moduleOptions.ModuleStorageUrl!,
135+
true, currentServerVersion))
135136
.ToList() ?? new List<ModuleDescription>();
136137

137138
// Mark those modules that can't be downloaded
@@ -241,7 +242,9 @@ public async Task<ServerResponse> ListAllModules()
241242

242243
if (installedModuleDesc is null)
243244
{
244-
var description = ModuleInstaller.ModuleDescriptionFromModuleConfig(module, true,
245+
var description = ModuleInstaller.ModuleDescriptionFromModuleConfig(module,
246+
_moduleOptions.ModuleStorageUrl!,
247+
true,
245248
currentServerVersion);
246249
description.IsDownloadable = false;
247250
installableModules.Add(description);

src/server/Modules/ModuleInstaller.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,14 @@ public static void RefreshDownloadableModuleList()
220220
/// from the ModuleConfig.
221221
/// </summary>
222222
/// <param name="module">A ModuleConfig object</param>
223+
/// <param name="moduleStorageUrl">The location of the module download
224+
/// packages</param>
223225
/// <param name="isInstalled">Is this module currently installed?</param>
224226
/// <param name="serverVersion">The version of the current server, or null to ignore
225227
/// version checks</param>
226228
/// <returns>A ModuleDescription object</returns>
227229
public static ModuleDescription ModuleDescriptionFromModuleConfig(ModuleConfig module,
230+
string moduleStorageUrl,
228231
bool isInstalled,
229232
string serverVersion)
230233
{
@@ -240,7 +243,8 @@ public static ModuleDescription ModuleDescriptionFromModuleConfig(ModuleConfig m
240243

241244
// Set initial properties. Most importantly it sets the status.
242245
moduleDescription.Initialise(serverVersion, module.ModuleDirPath,
243-
module.InstallOptions!.ModuleLocation);
246+
moduleStorageUrl,
247+
module.InstallOptions!.ModuleLocation);
244248

245249
// if a module is installed then that beats any other status
246250
if (isInstalled)
@@ -323,6 +327,7 @@ public async Task<List<ModuleDescription>> GetInstallableModulesAsync()
323327
+ Path.DirectorySeparatorChar
324328
+ downloadableModule.ModuleId;
325329
downloadableModule.Initialise(currentServerVersion, moduleDirPath,
330+
_moduleOptions.ModuleStorageUrl!,
326331
ModuleLocation.Internal);
327332
}
328333

@@ -467,6 +472,7 @@ public async Task<List<ModuleDescription>> GetInstallableModulesAsync()
467472
// "module.InstallOptions?.PreInstalled" is the setting for the currently installed
468473
// module, not the module that can be downloaded.
469474
// GIVEN ALL THAT: who cares. We can totally uninstall / reinstall something pre-installed.
475+
470476
// if (module is not null && module.InstallOptions?.PreInstalled == true)
471477
// return (false, $"Module description for '{moduleId}' is invalid. A 'pre-installed' module can't be downloaded");
472478

@@ -484,6 +490,7 @@ public async Task<List<ModuleDescription>> GetInstallableModulesAsync()
484490
// Download and unpack the module's installation package FOR THE REQUESTED VERSION
485491
// string moduleDirName = _moduleSettings.GetModuleDirPath(moduleDownload);
486492
// string moduleDirName = moduleDownload.ModuleDirPath;
493+
// TODO: Generalise this in a utility method
487494
string downloadDirPath = _moduleSettings.DownloadedModulePackagesDirPath
488495
+ Path.DirectorySeparatorChar + moduleId + "-" + version + ".zip";
489496

@@ -843,7 +850,9 @@ await logWriter.WriteLineAsync($"Unable to install Module '{moduleId}' ({e.Messa
843850
// to the download list so at least we can provide updates on it disappearing.
844851
if (moduleDownload is null)
845852
{
846-
moduleDownload = ModuleDescriptionFromModuleConfig(module, true,
853+
moduleDownload = ModuleDescriptionFromModuleConfig(module,
854+
_moduleOptions.ModuleStorageUrl!,
855+
true,
847856
_versionConfig.VersionInfo!.Version);
848857
moduleDownload.IsDownloadable = false;
849858
}

src/server/Modules/ModuleSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ private void ExpandMacros()
295295
_moduleOptions.ModuleListUrl = ExpandOption(_moduleOptions.ModuleListUrl);
296296
_moduleOptions.ModelListUrl = ExpandOption(_moduleOptions.ModelListUrl);
297297
_moduleOptions.AssetStorageUrl = ExpandOption(_moduleOptions.AssetStorageUrl);
298+
_moduleOptions.ModuleStorageUrl = ExpandOption(_moduleOptions.ModuleStorageUrl);
298299
_moduleOptions.PythonRelativeInterpreterPath = ExpandOption(_moduleOptions.PythonRelativeInterpreterPath);
299300

300301
// Correct the slashes

src/server/Version/ServerVersionService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ public ServerVersionService(IOptions<VersionConfig> versionOptions,
8282

8383
// Handy to allow the checkee to return emergency info if the current installed
8484
// version has issues. IMPORTANT: no personal information can be sent here. This
85-
// is purely things like OS / GPU.
85+
// is purely information such as server version, current OS / GPU.
8686
string currentVersion = VersionConfig.VersionInfo?.Version ?? string.Empty;
87-
_client.DefaultRequestHeaders.Add("X-CPAI-Server-Version", currentVersion);
88-
87+
_client.DefaultRequestHeaders.Add("X-CPAI-Server-Version", currentVersion);
8988
var sysProperties = SystemInfo.Summary;
9089
var systemInfoJson = JsonSerializer.Serialize(sysProperties);
9190
_client.DefaultRequestHeaders.Add("X-CPAI-Server-SystemInfo", systemInfoJson);

src/server/appsettings.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,22 @@
9696
"ModuleInstallTimeout": "00:20:00",
9797

9898
// URLs and Endpoints on CodeProject.com
99-
// "ModuleListUrl": "https://www.codeproject.com/ai/modules/list", // Location of the JSON list of modules that can be downloaded
100-
// "ModelListUrl": "https://www.codeproject.com/ai/models/list", // Location of the JSON list of models that can be downloaded
101-
// "AssetStorageUrl": "https://www.codeproject.com/ai/download/server/assets/", // Location of downloadable models
99+
// "ModuleListUrl": "https://www.codeproject.com/ai/modules/list", // Location of the JSON list of modules that can be downloaded
100+
// "ModelListUrl": "https://www.codeproject.com/ai/models/list", // Location of the JSON list of models that can be downloaded
101+
// "AssetStorageUrl": "https://www.codeproject.com/ai/download/server/assets/", // Location of downloadable models
102+
// "ModuleStorageUrl": "https://www.codeproject.com/kb/Articles/5348853/", // Location of downloadable module install packages
102103

103104
// URLs on Bunny.net
104-
"AssetStorageUrl": "https://codeproject-ai-bunny.b-cdn.net/server/assets/",
105105
// "ModuleListUrl": "https://codeproject-ai-bunny.b-cdn.net/modules/modules.json",
106106
// "ModelListUrl": "https://codeproject-ai-bunny.b-cdn.net/models/models.json",
107+
"AssetStorageUrl": "https://codeproject-ai-bunny.b-cdn.net/server/assets/",
108+
"ModuleStorageUrl": "https://codeproject-ai-bunny.b-cdn.net/modules/",
107109

108110
// URLs on github.io
109111
// "AssetStorageUrl": "https://codeproject.github.io/codeproject.ai/assets/",
110112
"ModuleListUrl": "https://codeproject.github.io/codeproject.ai/config/modules.json",
111113
"ModelListUrl": "https://codeproject.github.io/codeproject.ai/config/modules.json",
114+
// "ModuleStorageUrl": "https://codeproject.github.io/codeproject.ai/modules/",
112115

113116
// The location of the AI modules (pre-installed and downloaded/side-loaded)
114117
"ModuleInstallerScriptsDirPath": "%ROOT_PATH%", // Where the installer scripts (setup.bat/.sh) live

0 commit comments

Comments
 (0)