mercedes-benz / sechub

SecHub provides a central API to test software with different security tools.
https://mercedes-benz.github.io/sechub/
MIT License
259 stars 58 forks source link

SecHub Docker images cannot be built on MacOS with ARM architecture (M1) when using BUILD_TYPE=build #1938

Open ddzikon opened 1 year ago

ddzikon commented 1 year ago

Situation

Building Docker images with use of startup scripts on Apple Mac with M1 processor with following options in .env:

causes build failure:

#15 153.6 > Task :sechub-cli:genGo
#15 153.6 generate 'constants_filepatterns_gen.go'
#15 153.6
#15 153.6 > Task :sechub-cli:buildGo FAILED
#15 153.6 Build Go: Building package 'mercedes-benz.com/sechub':
#15 153.6 >>GOPATH=/build/sechub/sechub-cli/src/mercedes-benz.com/sechub
#15 153.6 # Initialize go modules
#15 153.6 # Declare other submodules to satisfy dependencies when testing
#15 153.6 /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/cli /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/main /build/sechub/sechub-cli/src/mercedes-benz.com/sechub
#15 153.6 /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/testutil /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/main /build/sechub/sechub-cli/src/mercedes-benz.com/sechub
#15 153.6 /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/util /build/sechub/sechub-cli/src/mercedes-benz.com/sechub/main /build/sechub/sechub-cli/src/mercedes-benz.com/sechub
#15 153.6 >building:platform/linux-386
#15 153.6 Go build failed because of an error
#15 153.6 qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

Wanted

It is possible to build Docker images on platforms with ARM processor architecture.

Solution

Probable cause is the version of GO language set in .env file, when running a build on MacOS with ARM architecture.
Currently the version of GO is GO="go1.19.linux-amd64.tar.gz".
Building works when the version is changed to the one proper for ARM architecture: GO="go1.19.5.linux-arm64.tar.gz"

A solution would be picking the GO version according to platform's architecture, i.e. with use of apk --print-arch - example in official Golang Dockerfile.

Jeeppler commented 1 year ago

@ddzikon thanks for opening the issue.

What is the Apple M1 architecture in a Docker image on macOS? Is it aarch64?

ddzikon commented 1 year ago

What is the Apple M1 architecture in a Docker image on macOS? Is it aarch64?

Yes, it is aarch64

Jeeppler commented 1 year ago

@ddzikon there is now an Alpine Linux Dockerfile. The Go version of Alpine Linux is fairly new and therefore it is installed from the package sources. As a result, building the image using the Alpine Linux image should work on aarch64 (ARM 64-bit).

To start the solution use: sechub-solution/01-start-single-docker-compose-alpine.sh.