Pre-commit: Node environment fails to initialize on alpine based images

Created on 18 Jun 2019  路  3Comments  路  Source: pre-commit/pre-commit

We use alpine based images on our CI and we encountered the following issue when a developer tried to integrate the prettier pre-commit hooks. The error is encountered while initializing the environment (pre-commit install-hooks):

An unexpected error has occurred: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node': '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node'
Check the log at /root/.cache/pre-commit/pre-commit.log
The command '/bin/sh -c pre-commit try-repo . prettier --verbose --all-files' returned a non-zero code: 1

the contents of /root/.cache/pre-commit/pre-commit.log:

An unexpected error has occurred: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node': '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node'
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/pre_commit/error_handler.py", line 46, in error_handler
    yield
  File "/usr/lib/python3.6/site-packages/pre_commit/main.py", line 298, in main
    return try_repo(args)
  File "/usr/lib/python3.6/site-packages/pre_commit/commands/try_repo.py", line 80, in try_repo
    return run(config_filename, store, args)
  File "/usr/lib/python3.6/site-packages/pre_commit/commands/run.py", line 285, in run
    install_hook_envs(hooks, store)
  File "/usr/lib/python3.6/site-packages/pre_commit/repository.py", line 215, in install_hook_envs
    hook.install()
  File "/usr/lib/python3.6/site-packages/pre_commit/repository.py", line 93, in install
    self.prefix, self.language_version, self.additional_dependencies,
  File "/usr/lib/python3.6/site-packages/pre_commit/languages/node.py", line 70, in install_environment
    helpers.run_setup_cmd(prefix, ('npm', 'install'))
  File "/usr/lib/python3.6/site-packages/pre_commit/languages/helpers.py", line 18, in run_setup_cmd
    cmd_output(*cmd, cwd=prefix.prefix_dir, encoding=None)
  File "/usr/lib/python3.6/site-packages/pre_commit/util.py", line 143, in cmd_output
    proc = subprocess.Popen(cmd, **popen_kwargs)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node': '/tmp/tmph8j6p9ne/repodk2x4bmu/node_env-default/bin/node'

I've tested this on debian based images and it ran as expected with no errors. The issue can be reproduced with the following Dockerfile:

FROM alpine:latest

RUN apk --no-cache add py3-pip openssh-client git && \
    pip3 install pre-commit

WORKDIR /tmp/test

RUN git clone https://github.com/prettier/prettier.git .

RUN pre-commit try-repo . prettier --verbose --all-files
upstream-bug

Most helpful comment

the current node's prebuilt binaries target glibc, whereas alpine is built upon musl

the first link above includes a workaround using language_version: system which may be useful

All 3 comments

this is due to an upstream issue, I've tried to get the node folks to produce alpine binaries but haven't had much success

Here's the issues from last time:

I'd suggest pinging the latter two for forward movement

thanks for the issue! :tada:

Interesting. @asottile so the problem is specifically with node on alpine due to differences of libc ?

the current node's prebuilt binaries target glibc, whereas alpine is built upon musl

the first link above includes a workaround using language_version: system which may be useful

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fczuardi picture fczuardi  路  3Comments

Cielquan picture Cielquan  路  3Comments

geekobi picture geekobi  路  3Comments

DaveParr picture DaveParr  路  4Comments

jeunii picture jeunii  路  3Comments