Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docker/kubernetes-agent-tentacle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ FROM golang:1.22 as bootstrapRunnerBuilder
ARG TARGETARCH
ARG TARGETOS

ARG architectures="amd64 arm64 386 arm"

COPY docker/kubernetes-agent-tentacle/bootstrapRunner/* /bootstrapRunner/
WORKDIR /bootstrapRunner

# Note: the given ldflags remove debug symbols
RUN go build -ldflags "-s -w" -o "bin/bootstrapRunner"
# Create bin directory for multiple architectures
RUN mkdir -p bin

RUN for arch in $architectures; do \
GOOS=linux GOARCH=$arch go build -ldflags "-s -w" -o "bin/bootstrapRunner-linux-$arch"; \
done

FROM mcr.microsoft.com/dotnet/runtime-deps:$RuntimeDepsTag

Expand All @@ -31,9 +36,13 @@ RUN groupadd -g 999 octopus \
EXPOSE 10933

COPY docker/kubernetes-agent-tentacle/scripts/* /scripts/
COPY --from=bootstrapRunnerBuilder bootstrapRunner/bin/bootstrapRunner /bootstrapRunner
COPY --from=bootstrapRunnerBuilder bootstrapRunner/bin/* /bootstrapRunner/
RUN chmod +x /scripts/*.sh

# Copy the architecture detection script from source and make it executable
COPY docker/kubernetes-agent-tentacle/bootstrapRunner/execute-bootstrapRunner.sh /bootstrapRunner/
RUN chmod +x /bootstrapRunner/execute-bootstrapRunner.sh

WORKDIR /tmp

# Install Tentacle
Expand Down Expand Up @@ -67,7 +76,7 @@ RUN chgrp -R 0 /opt /usr /.dotnet && \
RUN chgrp 0 /etc /etc/ssl/certs && \
chmod g=u /etc /etc/ssl/certs

ENV BOOTSTRAPRUNNEREXECUTABLEPATH=/bootstrapRunner
ENV BOOTSTRAPRUNNEREXECUTABLEDIRECTORY=/bootstrapRunner/
ENV OCTOPUS_RUNNING_IN_CONTAINER=Y
ENV ACCEPT_EULA=N
ENV CustomPublicHostName=""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eu

# Architecture detection and bootstrap runner selection script
# This script automatically detects the runtime architecture and selects
# the appropriate bootstrapRunner binary for execution.

# Detect the current architecture
ARCH=$(uname -m)

# Map architecture names to Go architecture naming
case "$ARCH" in
x86_64)
GO_ARCH="amd64"
;;
aarch64|arm64)
GO_ARCH="arm64"
;;
i386|i686)
GO_ARCH="386"
;;
armv7l|armv6l)
GO_ARCH="arm"
;;
*)
echo "Error: Unsupported architecture: $ARCH" >&2
echo "Supported architectures: x86_64, aarch64, arm64, i386, i686, armv7l, armv6l" >&2
exit 1
;;
esac

# Construct binary name
BINARY_NAME="bootstrapRunner-linux-${GO_ARCH}"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# Execute the appropriate binary with all arguments passed through
exec "$SCRIPT_DIR/$BINARY_NAME" "$@"
18 changes: 14 additions & 4 deletions docker/kubernetes-agent-tentacle/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ FROM golang:1.22 as bootstrapRunnerBuilder
ARG TARGETARCH
ARG TARGETOS

ARG architectures="amd64 arm64 386 arm"

COPY docker/kubernetes-agent-tentacle/bootstrapRunner/* /bootstrapRunner/
WORKDIR /bootstrapRunner

# Note: the given ldflags remove debug symbols
RUN go build -ldflags "-s -w" -o "bin/bootstrapRunner"
# Create bin directory for multiple architectures
RUN mkdir -p bin

RUN for arch in $architectures; do \
GOOS=linux GOARCH=$arch go build -ldflags "-s -w" -o "bin/bootstrapRunner-linux-$arch"; \
done


FROM mcr.microsoft.com/dotnet/runtime-deps:$RuntimeDepsTag
Expand All @@ -28,9 +34,13 @@ EXPOSE 10933
EXPOSE 7777

COPY docker/kubernetes-agent-tentacle/scripts/* /scripts/
COPY --from=bootstrapRunnerBuilder bootstrapRunner/bin/bootstrapRunner /bootstrapRunner
COPY --from=bootstrapRunnerBuilder bootstrapRunner/bin/* /bootstrapRunner/
RUN chmod +x /scripts/*.sh

# Copy the architecture detection script from source and make it executable
COPY docker/kubernetes-agent-tentacle/bootstrapRunner/execute-bootstrapRunner.sh /bootstrapRunner/
RUN chmod +x /bootstrapRunner/execute-bootstrapRunner.sh

COPY docker/kubernetes-agent-tentacle/dev/scripts/* /dev-scripts/
RUN chmod +x /dev-scripts/*.sh

Expand All @@ -54,7 +64,7 @@ RUN \
# We know this won't reduce the image size at all. It's just to make the filesystem a little tidier.
RUN rm -rf /tmp/*

ENV BOOTSTRAPRUNNEREXECUTABLEPATH=/bootstrapRunner
ENV BOOTSTRAPRUNNEREXECUTABLEDIRECTORY=/bootstrapRunner/
ENV OCTOPUS_RUNNING_IN_CONTAINER=Y
ENV ACCEPT_EULA=N
ENV CustomPublicHostName=""
Expand Down
2 changes: 1 addition & 1 deletion source/Octopus.Tentacle/Kubernetes/KubernetesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class KubernetesConfig
public static string KubernetesMonitorEnabledVariableName => $"{EnvVarPrefix}__KUBERNETESMONITORENABLED";
public static string? KubernetesMonitorEnabled => Environment.GetEnvironmentVariable(KubernetesMonitorEnabledVariableName);

public static string BootstrapRunnerExecutablePath => GetRequiredEnvVar("BOOTSTRAPRUNNEREXECUTABLEPATH", "Unable to determine Bootstrap Runner Executable Path");
public static string BootstrapRunnerExecutableDirectory => GetRequiredEnvVar("BOOTSTRAPRUNNEREXECUTABLEDIRECTORY", "Unable to determine Bootstrap Runner Executable Directory");

public static string PersistentVolumeSizeVariableName => $"{EnvVarPrefix}__PERSISTENTVOLUMESIZE";
public static string PersistentVolumeSize => GetRequiredEnvVar(PersistentVolumeSizeVariableName, "Unable to determine Persistent Volume Size");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ async Task CreatePod(StartKubernetesScriptCommandV1 command, IScriptWorkspace wo

LogVerboseToBothLogs($"Creating Kubernetes Pod '{podName}'.", tentacleScriptLog);

workspace.CopyFile(KubernetesConfig.BootstrapRunnerExecutablePath, "bootstrapRunner", true);

foreach(var file in kubernetesPhysicalFileSystem.EnumerateFiles(KubernetesConfig.BootstrapRunnerExecutableDirectory))
{
var baseName = Path.GetFileName(file);
workspace.CopyFile(file, baseName, true);
}

var scriptName = Path.GetFileName(workspace.BootstrapScriptFilePath);
var workspacePath = Path.Combine("Work", workspace.ScriptTicket.TaskId);

Expand Down Expand Up @@ -297,10 +301,10 @@ void LogVerboseToBothLogs(string message, InMemoryTentacleScriptLog tentacleScri
protected async Task<V1Container> CreateScriptContainer(StartKubernetesScriptCommandV1 command, string podName, string scriptName, string homeDir, string workspacePath, string[]? scriptArguments, InMemoryTentacleScriptLog tentacleScriptLog, V1Container? containerSpec)
{
var spaceInformation = kubernetesPhysicalFileSystem.GetStorageInformation();

var commandString = string.Join(" ", new[]
{
$"{homeDir}/Work/{command.ScriptTicket.TaskId}/bootstrapRunner",
$"{homeDir}/Work/{command.ScriptTicket.TaskId}/execute-bootstrapRunner.sh",
Path.Combine(homeDir, workspacePath),
Path.Combine(homeDir, workspacePath, scriptName)
}.Concat(scriptArguments ?? Array.Empty<string>())
Expand Down