canonical / craft-parts

https://canonical-craft-parts.readthedocs-hosted.com
GNU Lesser General Public License v3.0
11 stars 37 forks source link

node plugin: dont crash when running on non-snap arm64 env #885

Open om26er opened 1 month ago

om26er commented 1 month ago

When building nodejs based snap in a docker container using snapcraft 8.4.3 the build fails with these logs

2024-10-19 13:36:25.195 Architecture "aarch64 ('64bit', '')" is not supported.                                                                                                 
2024-10-19 13:36:25.199 Traceback (most recent call last):                                                                                                                     
2024-10-19 13:36:25.199   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/plugins/npm_plugin.py", line 151, in _get_architecture                        
2024-10-19 13:36:25.199     node_arch = _NODE_ARCH_FROM_PLATFORM[machine_type][architecture_type[0]]                                                                           
2024-10-19 13:36:25.200 KeyError: 'aarch64'                                                                                                                                    
2024-10-19 13:36:25.200                                                                                                                                                        
2024-10-19 13:36:25.200 The above exception was the direct cause of the following exception:                                                                                   
2024-10-19 13:36:25.200 Traceback (most recent call last):                                                                                                                     
2024-10-19 13:36:25.200   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_application/services/lifecycle.py", line 270, in run                                
2024-10-19 13:36:25.201     aex.execute(action, stdout=stream, stderr=stream)                                                                                                  
2024-10-19 13:36:25.201   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 324, in execute                                   
2024-10-19 13:36:25.201     self._executor.execute(actions, stdout=stdout, stderr=stderr)                                                                                      
2024-10-19 13:36:25.201   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 136, in execute                                   
2024-10-19 13:36:25.201     self._run_action(act, stdout=stdout, stderr=stderr)                                                                                                
2024-10-19 13:36:25.201   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 211, in _run_action                               
2024-10-19 13:36:25.202     handler.run_action(action, stdout=stdout, stderr=stderr)                                                                                           
2024-10-19 13:36:25.202   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 171, in run_action                            
2024-10-19 13:36:25.202     state = handler(step_info, stdout=stdout, stderr=stderr)                                                                                           
2024-10-19 13:36:25.202   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 310, in _run_build                            
2024-10-19 13:36:25.202     self._run_step(                                                                                                                                    
2024-10-19 13:36:25.202   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 493, in _run_step                             
2024-10-19 13:36:25.203     return step_handler.run_builtin()                                                                                                                  
2024-10-19 13:36:25.203   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/step_handler.py", line 108, in run_builtin                           
2024-10-19 13:36:25.203     return handler()                                                                                                                                   
2024-10-19 13:36:25.203   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/executor/step_handler.py", line 138, in _builtin_build                        
2024-10-19 13:36:25.203     build_commands = self._plugin.get_build_commands()                                                                                                 
2024-10-19 13:36:25.204   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/plugins/npm_plugin.py", line 277, in get_build_commands                       
2024-10-19 13:36:25.204     arch = self._get_architecture()                                                                                                                    
2024-10-19 13:36:25.204   File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/plugins/npm_plugin.py", line 153, in _get_architecture                        
2024-10-19 13:36:25.204     raise InvalidArchitecture(                                                                                                                         
2024-10-19 13:36:25.204 craft_parts.errors.InvalidArchitecture: Architecture "aarch64 ('64bit', '')" is not supported.                                                         
2024-10-19 13:36:25.204 Make sure the architecture name is correct.                                                                                                            
2024-10-19 13:36:25.205 Recommended resolution: Make sure the architecture name is correct.
om26er commented 1 month ago

For now I do this in my docker container build to patch craft_parts. Obviously another "hack" would be to export SNAP_ARCH parameter in docker container as well and then a different codepath would execute.

RUN sed -i 's|_NODE_ARCH_FROM_PLATFORM = {"x86_64": {"32bit": "x86", "64bit": "x64"}}|_NODE_ARCH_FROM_PLATFORM = {"x86_64": {"32bit": "x86", "64bit": "x64"}, "aarch64": {"64bit": "arm64"}}|g' /snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/plugins/npm_plugin.py
om26er commented 1 month ago

cc @sergiusens -- this issue was encountered with snapcraft 8.4.3 running on docker so would be good to have fixed in a release