Run linux container with same architechture as host

As the development team uses both Intel and Apple Silicon Macs,
we have to get the host CPU architecture at compilation time instead of
harcoding it.
If the container has a different architecture, the guest has to be
emulated.
This commit is contained in:
T. R. Bernstein
2026-03-22 15:40:32 +01:00
committed by T. R. Bernstein
parent 4b28c293cb
commit ac1c86c431
3 changed files with 11 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
struct Docker {
static func getLinuxPlatformStringWithHostArchitecture() -> String {
#if arch(x86_64)
return "linux/amd64"
#else
return "linux/arm64"
#endif
}
}

View File

@@ -46,7 +46,7 @@ struct GenerateDocumentationCommand: Script {
try await docker(
"run", "--rm",
"-v", "\(tempDirectory.path):/code",
"--platform", "linux/arm64",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code",
"swift:latest",
"/bin/bash", "-c", script,

View File

@@ -26,7 +26,7 @@ struct TestCommand: Script {
"run",
"-v", "\(currentDirectory):/code",
"--security-opt", "systempaths=unconfined",
"--platform", "linux/arm64",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code", "swift:latest",
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
)