Skip to content
Merged
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
27 changes: 25 additions & 2 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Worker struct {
activeTasks map[string]context.CancelFunc
tasksMutex sync.Mutex
dockerClient *client.Client
platform string // Docker daemon platform (e.g., "linux/amd64" or "linux/arm64")
}

func New(ctx context.Context, config Config) (*Worker, error) {
Expand All @@ -80,7 +81,28 @@ func New(ctx context.Context, config Config) (*Worker, error) {
return nil, fmt.Errorf("failed to reach Docker daemon: %w", err)
}

log.Debugf(ctx, "Docker daemon is reachable")
// Get the Docker daemon version to determine its platform.
versionInfo, err := dockerClient.ServerVersion(ctx)
if err != nil {
if closeErr := dockerClient.Close(); closeErr != nil {
log.Warnf(ctx, "Failed to close Docker client: %v", closeErr)
}
cancel()
return nil, fmt.Errorf("failed to get Docker version: %w", err)
}

// Determine the platform. The sidecar only supports linux/amd64 and linux/arm64,
// so we enforce that all images are pulled for one of these platforms.
platform := fmt.Sprintf("%s/%s", versionInfo.Os, versionInfo.Arch)
if platform != "linux/amd64" && platform != "linux/arm64" {
if closeErr := dockerClient.Close(); closeErr != nil {
log.Warnf(ctx, "Failed to close Docker client: %v", closeErr)
}
cancel()
return nil, fmt.Errorf("unsupported Docker platform %s (only linux/amd64 and linux/arm64 are supported)", platform)
}

log.Debugf(ctx, "Docker daemon is reachable, platform: %s", platform)

return &Worker{
config: config,
Expand All @@ -90,6 +112,7 @@ func New(ctx context.Context, config Config) (*Worker, error) {
sendChan: make(chan []byte, 256),
activeTasks: make(map[string]context.CancelFunc),
dockerClient: dockerClient,
platform: platform,
}, nil
}

Expand Down Expand Up @@ -341,7 +364,7 @@ func (w *Worker) executeTask(ctx context.Context, assignment *types.TaskAssignme
func (w *Worker) pullImage(ctx context.Context, imageName string, authStr string) error {
log.Infof(ctx, "Pulling image: %s", imageName)
pullOptions := image.PullOptions{
Platform: "linux/amd64",
Platform: w.platform,
RegistryAuth: authStr,
}
reader, err := w.dockerClient.ImagePull(ctx, imageName, pullOptions)
Expand Down