@@ -169,6 +169,51 @@ public function pushImage(string $name): void
169169 $ this ->passthruCommand ('push ' , $ name );
170170 }
171171
172+ private function getArchDocker (): string
173+ {
174+ $ json = $ this ->executeCommand ('version ' , '--format={{ json .Server.Arch }} ' );
175+
176+ if (!isset ($ json [0 ])) {
177+ throw new Exception ('No data received. ' );
178+ }
179+
180+ return json_decode ($ json [0 ], true , JSON_THROW_ON_ERROR );
181+ }
182+
183+ private function getArchPodman (): string
184+ {
185+ $ json = $ this ->executeCommand ('version ' , '--format={{ json .OsArch }} ' );
186+
187+ if (!isset ($ json [0 ])) {
188+ throw new Exception ('No data received. ' );
189+ }
190+
191+ $ osArch = json_decode ($ json [0 ], true , JSON_THROW_ON_ERROR );
192+ $ osArchSplit = explode ('/ ' , $ osArch );
193+ return end ($ osArchSplit );
194+ }
195+
196+ public function getArch (): string
197+ {
198+ if (stripos ($ this ->containerEngine , 'docker ' ) !== false ) {
199+ return $ this ->getArchDocker ();
200+ }
201+ if (stripos ($ this ->containerEngine , 'podman ' ) !== false ) {
202+ return $ this ->getArchPodman ();
203+ }
204+
205+ try {
206+ return $ this ->getArchDocker ();
207+ } catch (Exception ) {
208+ }
209+ try {
210+ return $ this ->getArchPodman ();
211+ } catch (Exception ) {
212+ }
213+
214+ throw new Exception ('Unable to determine CPU architecture of container engine. ' );
215+ }
216+
172217 public static function detectContainerEngine (): ?string
173218 {
174219 if (isset ($ _SERVER ['CONTAINER_ENGINE ' ])) {
0 commit comments