Eric 13d453d5ed
chore: Docker updates to support release tests in logos-storage-nim, and remove Codex references (#124)
* ci(docker): build dist-tests images

* Update to .net 10, kubernetes client 18.0.13

Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table.

* Updates to support Kubernetes upgrade

* bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image

* bump doc to .net 10

* bump docker to .net 10

* Build image with latest tag always

Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master

* docker image tag as "latest" only when pushing to master

* Update docker image to install doctl

* Remove doctl install

kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr

* Rename and remove all instances of Codex

* Further remove CodexNetDeployer as it is no longer needed

---------

Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
2026-04-17 15:03:22 +10:00

86 lines
3.2 KiB
C#

using System.Security.Cryptography;
using System.Text;
using Utils;
public static class Program
{
private const string Search = "<INSERT-OPENAPI-YAML-HASH>";
private const string StoragePluginFolderName = "StoragePlugin";
private const string ProjectPluginsFolderName = "ProjectPlugins";
public static void Main(string[] args)
{
Console.WriteLine("Injecting hash of 'openapi.yaml'...");
var pluginRoot = FindStoragePluginFolder();
var clientRoot = FindLogosStorageClientFolder();
Console.WriteLine("Located StoragePlugin: " + pluginRoot);
var openApiFile = Path.Combine(clientRoot, "openapi.yaml");
var clientFile = Path.Combine(clientRoot, "obj", "openapiClient.cs");
var targetFile = Path.Combine(pluginRoot, "ApiChecker.cs");
// Force client rebuild by deleting previous artifact.
File.Delete(clientFile);
var hash = CreateHash(openApiFile);
// This hash is used to verify that the Codex docker image being used is compatible
// with the openapi.yaml being used by the Codex plugin.
// If the openapi.yaml files don't match, an exception is thrown.
SearchAndInject(hash, targetFile);
// This program runs as the pre-build trigger for "StoragePlugin".
// You might be wondering why this work isn't done by a shell script.
// This is because this project is being run on many different platforms.
// (Mac, Unix, Win, but also desktop/cloud containers.)
// In order to not go insane trying to make a shell script that works in all possible cases,
// instead we use the one tool that's definitely installed in all platforms and locations
// when you're trying to run this plugin.
Console.WriteLine("Done!");
}
private static string FindStoragePluginFolder()
{
var folder = Path.Combine(PluginPathUtils.ProjectPluginsDir, "StoragePlugin");
if (!Directory.Exists(folder)) throw new Exception("StoragePlugin folder not found. Expected: " + folder);
return folder;
}
private static string FindLogosStorageClientFolder()
{
var folder = Path.Combine(PluginPathUtils.ProjectPluginsDir, "LogosStorageClient");
if (!Directory.Exists(folder)) throw new Exception("LogosStorageClient folder not found. Expected: " + folder);
return folder;
}
private static string CreateHash(string openApiFile)
{
var file = File.ReadAllText(openApiFile);
var fileBytes = Encoding.ASCII.GetBytes(file
.Replace(Environment.NewLine, ""));
var sha = SHA256.Create();
var hash = sha.ComputeHash(fileBytes);
return BitConverter.ToString(hash);
}
private static void SearchAndInject(string hash, string targetFile)
{
var lines = File.ReadAllLines(targetFile);
Inject(lines, hash);
File.WriteAllLines(targetFile, lines);
}
private static void Inject(string[] lines, string hash)
{
for (var i = 0; i < lines.Length; i++)
{
if (lines[i].Contains(Search))
{
lines[i + 1] = $" private const string OpenApiYamlHash = \"{hash}\";";
return;
}
}
}
}