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

Segmentation fault during building on Mac M1 devices #159

Closed
TiiFuchs opened this issue Jun 15, 2021 · 35 comments · Fixed by #177
Closed

Segmentation fault during building on Mac M1 devices #159

TiiFuchs opened this issue Jun 15, 2021 · 35 comments · Fixed by #177
Labels

Comments

@TiiFuchs
Copy link

  • Sail Version: 1.8.1
  • Laravel Version: 8.46.0
  • PHP Version: 8.0.6
  • OS: macOS 11.4 (Apple Silicon)

Description:

While building the laravel.test container with sail, it currently is not able to finish and resolves in an Segmentation fault during building...

#7 33.87 ## Populating apt-get cache...
#7 33.87 
#7 33.87 + apt-get update
#7 33.95 Hit:1 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease
#7 34.09 Hit:2 http://ports.ubuntu.com/ubuntu-ports focal InRelease
#7 34.19 Hit:3 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
#7 34.28 Hit:4 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
#7 34.38 Hit:5 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
#7 34.43 Reading package lists...
#7 34.80 
#7 34.80 ## Installing packages required for setup: lsb-release...
#7 34.80 
#7 34.80 + apt-get install -y lsb-release > /dev/null 2>&1
#7 35.89 
#7 35.89 ## Confirming "focal" is supported...
#7 35.89 
#7 35.89 + curl -sLf -o /dev/null 'https://deb.nodesource.com/node_16.x/dists/focal/Release'
#7 35.92 
#7 35.92 ## Adding the NodeSource signing key to your keyring...
#7 35.92 
#7 35.92 + curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
#7 35.95 
#7 35.95 ## Creating apt sources list file for the NodeSource Node.js 16.x repo...
#7 35.95 
#7 35.95 + echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x focal main' > /etc/apt/sources.list.d/nodesource.list
#7 35.95 + echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x focal main' >> /etc/apt/sources.list.d/nodesource.list
#7 35.95 
#7 35.95 ## Running `apt-get update` for you...
#7 35.95 
#7 35.95 + apt-get update
#7 36.03 Hit:1 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease
#7 36.08 Get:2 https://deb.nodesource.com/node_16.x focal InRelease [4583 B]
#7 36.11 Get:3 https://deb.nodesource.com/node_16.x focal/main arm64 Packages [767 B]
#7 36.18 Hit:4 http://ports.ubuntu.com/ubuntu-ports focal InRelease
#7 36.28 Hit:5 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
#7 36.37 Hit:6 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
#7 36.47 Hit:7 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
#7 36.52 Fetched 5350 B in 1s (9933 B/s)
#7 36.52 Reading package lists...
#7 36.88 
#7 36.88 ## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
#7 36.88 ## You may also need development tools to build native addons:
#7 36.88      sudo apt-get install gcc g++ make
#7 36.88 ## To install the Yarn package manager, run:
#7 36.88      curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
#7 36.88      echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
#7 36.88      sudo apt-get update && sudo apt-get install yarn
#7 36.88 
#7 36.88 
#7 36.91 Reading package lists...
#7 37.25 Building dependency tree...
#7 37.33 Reading state information...
#7 37.41 The following NEW packages will be installed:
#7 37.41   nodejs
#7 37.44 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
#7 37.44 Need to get 25.3 MB of archives.
#7 37.44 After this operation, 119 MB of additional disk space will be used.
#7 37.44 Get:1 https://deb.nodesource.com/node_16.x focal/main arm64 nodejs arm64 16.3.0-deb-1nodesource1 [25.3 MB]
#7 37.88 debconf: delaying package configuration, since apt-utils is not installed
#7 37.90 Fetched 25.3 MB in 0s (63.1 MB/s)
#7 37.92 Selecting previously unselected package nodejs.
(Reading database ... 21562 files and directories currently installed.)
#7 37.93 Preparing to unpack .../nodejs_16.3.0-deb-1nodesource1_arm64.deb ...
#7 37.93 Unpacking nodejs (16.3.0-deb-1nodesource1) ...
#7 39.47 Setting up nodejs (16.3.0-deb-1nodesource1) ...
#7 39.48 Processing triggers for man-db (2.9.1-1) ...
#7 39.54 Warning: apt-key output should not be parsed (stdout is not a terminal)
#7 39.56 gpg: no valid OpenPGP data found.
#7 39.56 Segmentation fault
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c apt-get update     && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2     && mkdir -p ~/.gnupg     && chmod 600 ~/.gnupg     && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf     && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C     && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C     && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list     && apt-get update     && apt-get install -y php8.0-cli php8.0-dev        php8.0-pgsql php8.0-sqlite3 php8.0-gd        php8.0-curl php8.0-memcached        php8.0-imap php8.0-mysql php8.0-mbstring        php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap        php8.0-intl php8.0-readline        php8.0-msgpack php8.0-igbinary php8.0-ldap        php8.0-redis     && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer     && curl -sL https://deb.nodesource.com/setup_16.x | bash -     && apt-get install -y nodejs     && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -     && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list     && apt-get update     && apt-get install -y yarn     && apt-get install -y mysql-client     && apt-get install -y postgresql-client     && apt-get -y autoremove     && apt-get clean     && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*]: exit code: 2

Steps To Reproduce:

  • Create a new laravel application,
  • Install sail with mariadb
  • Execute sail up -d

=> The build fails.

@TiiFuchs
Copy link
Author

TiiFuchs commented Jun 15, 2021

The problem seems to be with one of those two lines:

    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \

@rik-legger
Copy link

rik-legger commented Jun 15, 2021

Had the same issue, working when changing https to http:

curl -sS http://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

@mludi
Copy link

mludi commented Jun 16, 2021

The issue is described here

https://docs.docker.com/docker-for-mac/release-notes/#known-issues

On Apple Silicon in native arm64 containers, older versions of libssl in debian:buster, ubuntu:20.04 and centos:8 will segfault when connected to some TLS servers, for example curl https://dl.yarnpkg.com. The bug is fixed in newer versions of libssl in debian:bullseye, ubuntu:21.04 and fedora:35.

@driesvints
Copy link
Member

Seems like this is a Docker issue and we can't resolve this in Sail.

@mludi
Copy link

mludi commented Jun 17, 2021

Seems like this is a Docker issue and we can't resolve this in Sail.

For sure you could ;-) Use a newer Ubuntu Version will do the trick.

@driesvints
Copy link
Member

@mludi I don't think we're ready yet to move to the newer Ubuntu. Forge still provisions Ubuntu 20.04 and we want to stick to the same version.

@mludi
Copy link

mludi commented Jun 17, 2021

@driesvints ok, I hadn't this information :-) Thx!

@claudiodekker
Copy link

claudiodekker commented Jun 17, 2021

Hey everyone,

I just tried to replicate this on my M1 machine to see if we could find a different solution to this, but unfortunately I wasn't able to replicate this. Here's a log of the build for those interested into what a functional build would look like.

Here's what I'm running:

  • MacOS 11.4 (M1 Mini)
  • PHP Version: 8.0.6
  • Laravel v8.5.20
  • Sail 18.1
  • Docker 20.10.6, build 370c289
  • Rosetta 2 compatibility package installed (although this shouldn't affect this issue / Docker)

Furthermore, in my Docker settings, I'm using the following settings:

  • General -> Use gRPC FUSE for file sharing ENABLED
  • Experimental Features -> Use new virtualization framework DISABLED

Can you confirm that you're using the same Docker settings? Thanks!

@mludi
Copy link

mludi commented Jun 17, 2021

@claudiodekker I have this issue only on one of my M1 Macs, the other one works fine. I use the same settings you provided.

@claudiodekker
Copy link

claudiodekker commented Jun 17, 2021

@mludi Alright, and what do you see when running docker inspect ubuntu:20.04 | grep "ubuntu@sha256"?

If you're running the (currently) latest version, the output should be "ubuntu@sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d".

If it's not that, I recommend running docker pull ubuntu:20.04 to update to the latest version of the image first, as perhaps that could solve this issue.

@TiiFuchs
Copy link
Author

I retried everything with these versions:

  • Sail Version: 1.8.1
  • Laravel Version: 8.47.0
  • PHP Version: 8.0.7
  • OS: macOS 11.4 (Apple Silicon)
  • Docker 20.10.7 build f0df350

Executing your command results in Error: No such object: ubuntu:20.04. I guess it didn't get tagged from the docker build?!
When I pull it first, I get the exact same hash that you posted.

But no matter how, I get the Segmentation fault.

@mludi
Copy link

mludi commented Jun 17, 2021

But no matter how, I get the Segmentation fault.

Same here.

@claudiodekker
Copy link

claudiodekker commented Jun 17, 2021

Interesting.. I just updated my Docker to 20.10.7, build f0df350 (latest), and now I'm also getting a Segfault at the Node step.

For everyone that's having this issue, I recommend to downgrade Docker to 20.10.6, build 370c289 or to stay on that version if you're already on it (for now), as it appears that the newer version is actively causing this problem. This older build works.

Do note that downgrading Docker does mean you WILL lose your existing images/containers, as a 'Factory Reset' will be necessary. So be sure to make a backup / export of those images/containers first!

@TiiFuchs
Copy link
Author

That explains, why I could build the image in the past on the same machine.
It seems to be a problem with the newest Docker version then...

@TiiFuchs
Copy link
Author

I can confirm that Downgrading helps. :)

@TiiFuchs
Copy link
Author

Huge thanks! :)

@driesvints driesvints pinned this issue Jun 24, 2021
@driesvints driesvints changed the title Build of laravel.test fails currently Segmentation fault during building on Mac M1 devices Jun 24, 2021
@driesvints driesvints reopened this Jul 1, 2021
@driesvints
Copy link
Member

Gonna re-open this until we've found a solution. We tried updating to 21.04 in the end but there were some PECL issues. I'll try to look into resolving those.

@driesvints driesvints unpinned this issue Jul 1, 2021
@driesvints driesvints added the bug label Jul 1, 2021
@driesvints
Copy link
Member

I saw the latest release of Docker Desktop has separate M1 builds. Can anyone try that out to see if this issue is fixed with it?

https://docs.docker.com/docker-for-mac/release-notes/#docker-desktop-351

@mludi
Copy link

mludi commented Jul 1, 2021

@driesvints I am on the M1 latest build and the issue still exists.

@driesvints
Copy link
Member

Hey all. I got a new PR up that should also fix the PECL issues. Can you all please try it to see if you're unblocked that way? #177

@mludi
Copy link

mludi commented Jul 1, 2021

@driesvints that worked fine :-) Thx!

But I got

PHP Warning:  Module "swoole" is already loaded in Unknown on line 0

@driesvints
Copy link
Member

@mludi ah thanks. You sure you rebuilded from scratch?

@mludi
Copy link

mludi commented Jul 1, 2021

@driesvints yes, I removed all docker images and gave a fresh rebuild.

@TiiFuchs
Copy link
Author

TiiFuchs commented Jul 1, 2021

Hmm I'll get this error that I can't quite explain currently:

CleanShot 2021-07-01 at 15 36 13@2x

@mludi
Copy link

mludi commented Jul 1, 2021

@TiiFuchs I had the same with

docker compose build

but

./vendor/sail/build

or

./vendor/sail/up -d did it

@TiiFuchs
Copy link
Author

TiiFuchs commented Jul 1, 2021

Oh interesting. What does sail differently for the build in comparison to docker-compose build

With sail up -d I get this at the end:
CleanShot 2021-07-01 at 15 50 04@2x

@mludi
Copy link

mludi commented Jul 1, 2021

Oh interesting. What does sail differently for the build in comparison to docker-compose build

It will set some environment variables which are needed.

Yes, this is the expected error until you change this

#177

@TiiFuchs
Copy link
Author

TiiFuchs commented Jul 1, 2021

@mludi Until I change what? I switched the laravel/sail package to the fix-m1-issues branch and the Dockerfile used contains all changes. Also this is not the initial Segmentation fault, it's a different error.

@driesvints
Copy link
Member

@mludi got that extension thing fixed. Can you try again?

@TiiFuchs I can't reproduce your error

@mludi
Copy link

mludi commented Jul 1, 2021

@driesvints perfect, that's working now :-)

@ibarrajo
Copy link
Contributor

ibarrajo commented Jul 1, 2021

Hmm I'll get this error that I can't quite explain currently:

CleanShot 2021-07-01 at 15 36 13@2x

that's because it's missing the $WWWGROUP value, in the docker file it's running:

RUN groupadd --force -g $WWWGROUP sail

you can try running: WWWGROUP="$(id -g)" sail up --build --no-cache

@TiiFuchs
Copy link
Author

TiiFuchs commented Jul 2, 2021

I can confirm too, that it works now.
The previous error seems to have been a temporary network problem. It fixed itself in my case.

@mludi
Copy link

mludi commented Jul 2, 2021

you can try running: WWWGROUP="$(id -g)" sail up --build --no-cache

That's not necessary, sail does that already.

@driesvints
Copy link
Member

Cool, I'll mark it as ready for review. Thanks all.

@Muaath5
Copy link

Muaath5 commented Feb 1, 2023

Still have the same issue.
Changing the version of runtime of sail from 8.2 to 8.1 fixed the problem for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants