hashgraph / hedera-sourcify

Tools for verifying Hedera smart contracts using standard open source libraries.
Apache License 2.0
6 stars 7 forks source link

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

Closed acuarica closed 6 months ago

acuarica commented 6 months ago

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 > node-sass@4.14.1 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 > node-sass@4.14.1 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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

@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 commented 6 months ago

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 commented 6 months ago

This was solved in the submodule dependency https://github.com/sourcifyeth/h5ai-nginx/commit/80938c49df26994a4bf69e87c626f6d667333657.

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