-
Notifications
You must be signed in to change notification settings - Fork 100
Description
Problem Description
The recent change in scripts/buildinputs/dockerfile.go
(PR #1320) replaced hardcoded "amd64" with runtime.GOARCH
to support multi-architecture builds. While this works for native arm64 builds, it fails for qemu-user s390x builds because runtime.GOARCH
returns the host architecture rather than the target architecture.
Current Implementation
// Current code in dockerfile.go
platform: "linux/" + runtime.GOARCH,
BuildPlatforms: []ocispecs.Platform{{OS: "linux", Architecture: runtime.GOARCH}},
Impact Analysis
- Native builds: Works correctly (amd64 → amd64, arm64 → arm64)
- QEMU user emulation: Fails for s390x builds (host amd64/arm64 → incorrectly detects as amd64/arm64 instead of s390x)
- Cross-compilation scenarios: May not detect target architecture correctly
Root Cause
When using qemu-user emulation for s390x builds:
- The build runs on a host machine (typically amd64 or arm64)
runtime.GOARCH
returns the host architecture- The tool incorrectly configures the platform as "linux/amd64" or "linux/arm64" instead of "linux/s390x"
- This leads to incorrect dependency resolution and build configuration
Solution Options
Option 1: Environment Variable Detection
Detect target architecture from environment variables commonly used in cross-compilation:
TARGETARCH
(Docker BuildKit)GOARCH
(Go cross-compilation)BUILD_ARCH
(custom CI variables)
Option 2: Configuration Parameter
Add a command-line parameter or configuration option to explicitly specify the target architecture:
--target-arch s390x
Option 3: Platform Detection Logic
Implement intelligent platform detection that considers:
- BuildKit platform specifications
- Docker build context
- QEMU emulation indicators
Option 4: Hybrid Approach
Combine multiple detection methods with fallback logic:
- Check for explicit target architecture parameters
- Detect from environment variables
- Fall back to
runtime.GOARCH
for native builds
Acceptance Criteria
- s390x builds using qemu-user emulation correctly detect target architecture as "linux/s390x"
- Native amd64 and arm64 builds continue to work correctly
- Cross-compilation scenarios are properly handled
- Solution is backwards compatible with existing workflows
- Architecture detection is configurable when needed
- Clear error messages when architecture cannot be determined
Implementation Guidance
- Phase 1: Add environment variable detection for common cross-compilation variables
- Phase 2: Implement configuration parameter support
- Phase 3: Add intelligent platform detection logic
- Phase 4: Comprehensive testing across all supported architectures
Related Files
scripts/buildinputs/dockerfile.go
- Main implementation- CI configuration files that use buildinputs tool
- Documentation for cross-architecture builds
References
- PR RHOAIENG-28654: allow using CUDA rpm repos for amd64 and arm64 #1320: Allow using CUDA rpm repos for amd64 and arm64
- Comment: RHOAIENG-28654: allow using CUDA rpm repos for amd64 and arm64 #1320 (comment)
- Related architecture handling patterns in the codebase
Context
This issue was identified during the review of PR #1320 where multi-architecture CUDA support was added. The current solution works for native arm64 builds but needs enhancement for qemu-user s390x builds.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status