Skip to content

Commit

Permalink
Embed GO
Browse files Browse the repository at this point in the history
  • Loading branch information
flin-8 committed Mar 15, 2024
1 parent c211a35 commit 41a76d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/Octopus.Tentacle/Kubernetes/Scripts/RunningKubernetesPod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public class RunningKubernetesPod : IRunningScript
using var reader = new StreamReader(stream!, Encoding.UTF8);
return await reader.ReadToEndAsync();
});

static readonly AsyncLazy<byte[]> BootstrapRunnerExe = new(async () =>
{
using var stream = typeof(RunningKubernetesPod).Assembly.GetManifestResourceStream("Octopus.Tentacle.Kubernetes.bootstrap");
var mem = new MemoryStream();
await stream!.CopyToAsync(mem);
return mem.ToArray();
});

readonly IScriptWorkspace workspace;
readonly ScriptTicket scriptTicket;
Expand Down Expand Up @@ -313,6 +321,7 @@ async Task CreatePod(IScriptLogWriter writer, string? imagePullSecretName, Cance

//write the bootstrap runner script to the workspace
workspace.WriteFile("bootstrapRunner.sh", await BootstrapRunnerScript.Task);
workspace.WriteAllBytes("bootstrap", await BootstrapRunnerExe.Task);

var scriptName = Path.GetFileName(workspace.BootstrapScriptFilePath);

Expand Down Expand Up @@ -342,8 +351,8 @@ async Task CreatePod(IScriptLogWriter writer, string? imagePullSecretName, Cance
Command = new List<string> { "bash" },
Args = new List<string>
{
$"/octopus/Work/{scriptTicket.TaskId}/bootstrapRunner.sh",
$"/octopus/Work/{scriptTicket.TaskId}",
$"/octopus/Work/{scriptTicket.TaskId}/bootstrap",
//$"/octopus/Work/{scriptTicket.TaskId}",
$"/octopus/Work/{scriptTicket.TaskId}/{scriptName}"
}.Concat(workspace.ScriptArguments ?? Array.Empty<string>())
.ToList(),
Expand Down
Binary file added source/Octopus.Tentacle/Kubernetes/bootstrap
Binary file not shown.
4 changes: 4 additions & 0 deletions source/Octopus.Tentacle/Octopus.Tentacle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,9 @@
<EmbeddedResource Include="Kubernetes\bootstrapRunner.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Kubernetes\bootstrap" />
<EmbeddedResource Include="Kubernetes\bootstrap">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions source/Octopus.Tentacle/Scripts/IScriptWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public interface IScriptWorkspace
string LogFilePath { get; }
void WriteFile(string filename, string contents);
Stream OpenFileStreamForReading(string filename);
void WriteAllBytes(string filename, byte[] contents);
}
}
1 change: 1 addition & 0 deletions source/Octopus.Tentacle/Scripts/ScriptWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ScriptWorkspace : IScriptWorkspace
const string LogFileName = "Output.log";
public string LogFilePath => GetLogFilePath(WorkingDirectory);
public void WriteFile(string filename, string contents) => FileSystem.OverwriteFile(ResolvePath(filename), contents);
public void WriteAllBytes(string filename, byte[] contents) => FileSystem.WriteAllBytes(ResolvePath(filename), contents);

public Stream OpenFileStreamForReading(string filename) => FileSystem.OpenFile(ResolvePath(filename), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

Expand Down

0 comments on commit 41a76d9

Please sign in to comment.