Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerfile build failed in MacOSX, M1 Chip #49071

Closed
siddontang opened this issue Nov 30, 2023 · 5 comments · Fixed by #49559
Closed

dockerfile build failed in MacOSX, M1 Chip #49071

siddontang opened this issue Nov 30, 2023 · 5 comments · Fixed by #49559
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.

Comments

@siddontang
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

# enter TiDB root path
docker build -name pingcap/tidb .

2. What did you expect to see? (Required)

Build successfully

3. What did you see instead (Required)

 => ERROR [builder 4/4] RUN export GOPROXY=${GOPROXY} && cd /tidb && make server                                                 265.5s
------
 > [builder 4/4] RUN export GOPROXY=${GOPROXY} && cd /tidb && make server:
#0 0.256 fatal: not a git repository (or any of the parent directories): .git
#0 0.260 fatal: not a git repository (or any of the parent directories): .git
#0 0.262 fatal: not a git repository (or any of the parent directories): .git
#0 0.362 fatal: not a git repository (or any of the parent directories): .git
#0 0.365 fatal: not a git repository (or any of the parent directories): .git
#0 0.367 fatal: not a git repository (or any of the parent directories): .git
#0 0.435 fatal: not a git repository (or any of the parent directories): .git
#0 0.438 fatal: not a git repository (or any of the parent directories): .git
#0 0.439 fatal: not a git repository (or any of the parent directories): .git
#0 0.440 CGO_ENABLED=1  GO111MODULE=on go build -tags codes  -ldflags '-X "github.com/pingcap/tidb/pkg/parser/mysql.TiDBReleaseVersion=" -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBBuildTS=2023-11-30 17:34:35" -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitHash=" -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBGitBranch=" -X "github.com/pingcap/tidb/pkg/util/versioninfo.TiDBEdition=Community" ' -o bin/tidb-server ./cmd/tidb-server
#0 0.606 go: downloading github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22
# ....... many go: downloading
#0 77.73 go: downloading github.com/go-logr/logr v1.3.0
#0 106.3 # runtime/cgo
#0 106.3 gcc: error: unrecognized command-line option '-m64'
#0 265.2 make: *** [Makefile:161: server] Error 1
------
Dockerfile:31
--------------------
  29 |     COPY . /tidb
  30 |     ARG GOPROXY
  31 | >>> RUN export GOPROXY=${GOPROXY} && cd /tidb && make server
  32 |
  33 |     FROM rockylinux:9-minimal
--------------------
ERROR: failed to solve: process "/bin/sh -c export GOPROXY=${GOPROXY} && cd /tidb && make server" did not complete successfully: exit code: 2
➜  tidb git:(master) ✗

4. What is your TiDB version? (Required)

newest master

@siddontang siddontang added the type/bug This issue is a bug. label Nov 30, 2023
@hawkingrei
Copy link
Member

I think it is related with it.

image

@bb7133
Copy link
Member

bb7133 commented Dec 5, 2023

Hi @siddontang

What is Linux VM do u use, is it Colima or Docker Desktop? This seems to be a known issue for the qeum & Go toolchain on ARM64 env: docker/buildx#2028 and it is said that 'the latest Docker Desktop' gets this fixed.

@yoshikipom
Copy link
Contributor

FYI: I can build the docker image with Apple silicon chip (M2). You can try --platform linux/amd64 option.
Example

$ arch
arm64

$ docker build -t pingcap/tidb --platform linux/amd64 .
[+] Building 170.6s (12/12) FINISHED                                    docker:desktop-linux

# built image is for x86_64
$ docker run -it -p 4000:4000 --entrypoint "arch" pingcap/tidb 
x86_64

I'm using latest docker desktop. Without platform option, I got same error. A more detailed error is this.

# runtime/cgo
gcc: error: unrecognized command-line option '-m64'
make: *** [Makefile:162: server] Error 1

I also think this is because of golang for amd64. docker build without platform option on Apple silicon means --platform=linux/arm64. In this case, arm rockylinux will be used as the base image.

@yoshikipom
Copy link
Contributor

yoshikipom commented Dec 15, 2023

I think we can improve Docker file for ARM. How about applying option 1 or option 2? If okay, I can raise a pull request.

Option 1: fix CPU architecture of base image

Currently, the Dockerfile can handle only --platform=linux/amd64 because of ENV ARCH amd64. (ARG can be changed from command line option, but ENV can't be )
To avoid build command on other architecture, we can specify amd64 in the Dockerfile.

  • As-Is: FROM rockylinux:9 as builder FROM rockylinux:9-minimal
  • To-Be: FROM --platform=linux/amd64 rockylinux:9 as builder FROM --platform=linux/amd64 rockylinux:9-minimal

ref: https://docs.docker.com/engine/reference/builder/#from

Pros: ARM user (including M1 chip) can run docker build simply without platform option.

Option 2: Make ARCH build arg

If ENV ARCH amd64 is ARG ARCH amd64, you can change the value of ARCH with --build-arg option.
Build command for ARM will be like docker build --build-arg "ARCH=arm64" -t pingcap/tidb/arm .. As a result, golang for ARM will be downloaded.

Pros: You can choose amd64 or arm64 during docker build. (I tested ARM option locally and it works)

@wuhuizuo
Copy link
Contributor

It will be fixed in #49559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants