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

Fail to build repository image on Apple ARM-based chips (M1, M2) #103

Closed
acuarica opened this issue Dec 12, 2023 · 5 comments · Fixed by #104
Closed

Fail to build repository image on Apple ARM-based chips (M1, M2) #103

acuarica opened this issue Dec 12, 2023 · 5 comments · Fixed by #104

Comments

@acuarica
Copy link
Contributor

acuarica commented Dec 12, 2023

Following the instruction in the README you can build the repository image by running

docker-compose -f environments/build-repository.yaml build

However this fails when running from an Apple ARM-based host, essentially because python is not found

14.71 > [email protected] install /select-contract-form/node_modules/node-sass
14.71 > node scripts/install.js
14.71 
14.92 Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-83_binding.node
15.56 Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-83_binding.node": 
[...]
16.01 > [email protected] postinstall /select-contract-form/node_modules/node-sass
16.01 > node scripts/build.js
16.01 
16.08 Building: /usr/local/bin/node /select-contract-form/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
16.12 gyp info it worked if it ends with ok
[...]
16.13 gyp verb check python checking for Python executable "python2" in the PATH
16.13 gyp verb `which` failed Error: not found: python2
[...]
16.13 gyp ERR! configure error 
16.13 gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
[...]
16.13 gyp ERR! System Linux 6.4.16-linuxkit
16.13 gyp ERR! command "/usr/local/bin/node" "/select-contract-form/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
16.13 gyp ERR! cwd /select-contract-form/node_modules/node-sass
16.13 gyp ERR! node -v v14.21.3
16.13 gyp ERR! node-gyp -v v3.8.0
16.13 gyp ERR! not ok 
16.13 Build failed with error code: 1
[...]

But this Python error is raised because it cannot find a Node native module for the sass package. From the excerpt above

14.92 Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-83_binding.node
15.56 Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-83_binding.node": 

it then tries to compile it, failing because Python is not installed.

@acuarica
Copy link
Contributor Author

acuarica commented Dec 12, 2023

I tried to fix the issue by changing the platform in environments/build-repository.yaml. This avoids to compile the Node native module, given it can be found in their respective GitHub releases[1]

  repository:
    platform: linux/amd64

However, after this change it now gets stuck when running npm run build from the Dockerfile

 => [repository stage-0 11/11] RUN mkdir /redirects && cd select-contract-form && npm install && npm run build                                                 46.6s
 => => # > react-scripts build && cp -r build/* ../redirects                                                                                                        
 => => # Creating an optimized production build...                                                                                                                  
 => => # Browserslist: caniuse-lite is outdated. Please run:                                                                                                        
 => => # npx browserslist@latest --update-db                                                                                                                        
 => => # Why you should do it regularly:                                                                                                                            
 => => # https://github.com/browserslist/browserslist#browsers-data-updating                                                                                        

Not sure why this happens. react-scripts build seems to be quite opaque command, with no verbose option to see what's going on.


[1] https://github.com/sass/node-sass/releases/tag/v4.14.1

@acuarica
Copy link
Contributor Author

Another fail attempt to solve this issue was to try to actually install Python and compile the Node native module. Adding this to the beginning of the Dockerfile

RUN apk add python
# or
# RUN apk add python2

However Python 2 is not available FROM node:14-alpine

1.366 ERROR: unable to select packages:
1.385   python (no such package):
1.385     required by: world[python]

And installing Python 3 raises a syntax error

15.93 gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
15.93 gyp ERR! stack   File "<string>", line 1
15.93 gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
15.93 gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15.93 gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

@Nana-EC
Copy link
Collaborator

Nana-EC commented Dec 13, 2023

@acuarica node:14 seems a bit old.
Would updating the node version make the needed python version available? Maybe one of the node:18 version
Is the main sourcify branch hitting this issue also?

@acuarica
Copy link
Contributor Author

Would updating the node version make the needed python version available? Maybe one of the node:18 version
I believe it wouldn't, Python2 was removed from Alpine.

Is the main sourcify branch hitting this issue also?

It doesn't look like. I have checked both these repos https://github.com/ethereum/sourcify and https://github.com/sourcifyeth/h5ai-nginx and found nothing related.

@acuarica
Copy link
Contributor Author

This was solved in the submodule dependency sourcifyeth/h5ai-nginx@80938c4.

Essentially the key was to use node:14.14-alpine so that python2 make g++ can be installed to compile sass native module.

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

Successfully merging a pull request may close this issue.

2 participants