@@ -57,6 +57,7 @@ type Worker struct {
5757 activeTasks map [string ]context.CancelFunc
5858 tasksMutex sync.Mutex
5959 dockerClient * client.Client
60+ platform string // Docker daemon platform (e.g., "linux/amd64" or "linux/arm64")
6061}
6162
6263func New (ctx context.Context , config Config ) (* Worker , error ) {
@@ -80,7 +81,28 @@ func New(ctx context.Context, config Config) (*Worker, error) {
8081 return nil , fmt .Errorf ("failed to reach Docker daemon: %w" , err )
8182 }
8283
83- log .Debugf (ctx , "Docker daemon is reachable" )
84+ // Get the Docker daemon version to determine its platform.
85+ versionInfo , err := dockerClient .ServerVersion (ctx )
86+ if err != nil {
87+ if closeErr := dockerClient .Close (); closeErr != nil {
88+ log .Warnf (ctx , "Failed to close Docker client: %v" , closeErr )
89+ }
90+ cancel ()
91+ return nil , fmt .Errorf ("failed to get Docker version: %w" , err )
92+ }
93+
94+ // Determine the platform. The sidecar only supports linux/amd64 and linux/arm64,
95+ // so we enforce that all images are pulled for one of these platforms.
96+ platform := fmt .Sprintf ("%s/%s" , versionInfo .Os , versionInfo .Arch )
97+ if platform != "linux/amd64" && platform != "linux/arm64" {
98+ if closeErr := dockerClient .Close (); closeErr != nil {
99+ log .Warnf (ctx , "Failed to close Docker client: %v" , closeErr )
100+ }
101+ cancel ()
102+ return nil , fmt .Errorf ("unsupported Docker platform %s (only linux/amd64 and linux/arm64 are supported)" , platform )
103+ }
104+
105+ log .Debugf (ctx , "Docker daemon is reachable, platform: %s" , platform )
84106
85107 return & Worker {
86108 config : config ,
@@ -90,6 +112,7 @@ func New(ctx context.Context, config Config) (*Worker, error) {
90112 sendChan : make (chan []byte , 256 ),
91113 activeTasks : make (map [string ]context.CancelFunc ),
92114 dockerClient : dockerClient ,
115+ platform : platform ,
93116 }, nil
94117}
95118
@@ -341,7 +364,7 @@ func (w *Worker) executeTask(ctx context.Context, assignment *types.TaskAssignme
341364func (w * Worker ) pullImage (ctx context.Context , imageName string , authStr string ) error {
342365 log .Infof (ctx , "Pulling image: %s" , imageName )
343366 pullOptions := image.PullOptions {
344- Platform : "linux/amd64" ,
367+ Platform : w . platform ,
345368 RegistryAuth : authStr ,
346369 }
347370 reader , err := w .dockerClient .ImagePull (ctx , imageName , pullOptions )
0 commit comments