3

I have a step in my pipeline that runs our configured pre-commit on Bitbucket:

...
- step:
    name: Passing linters
    image: python:3.7-slim-stretch
    script:
      - pip3 install "pre-commit==2.17.0"
      - apt-get update && apt-get --assume-yes install git
      - pre-commit run --all-files

No changes were made but it suddenly stopped working.

The pipeline result:

+ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/psf/black:click==8.0.4.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/:tslint-react@4.1.0,tslint@5.20.1,typescript@4.0.2.
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/root/.cache/pre-commit/repo1234/node_env-default/bin/node', '/root/.cache/pre-commit/repo1234/node_env-default/bin/npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    /root/.cache/pre-commit/repo1234/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /root/.cache/pre-commit/repo1234/node_env-default/bin/node)
    
Check the log at /root/.cache/pre-commit/pre-commit.log
anthony sottile
  • 61,815
  • 15
  • 148
  • 207

1 Answers1

6

pre-commit utilizes nodeenv to bootstrap node environments

it does this by downloading a copy of node and provisioning an environment (when node is not available). a few days ago node 18.x was released and the prebuilt binaries require a relatively-recent version of glibc

there's a few ways you can work around this:

1. select a specific version of node using language_version / default_language_version

# using default_language_version
default_language_version:
    node: 16.14.2

# on the hook itself
repos:
-   repo: https://github.com/maximevast/pre-commit-tslint
    rev: ...
    hooks:
    -   id: tslint
        language_version: 16.14.2

2. use a newer base image

stretch is a bit old, perhaps try instead 3.7-slim-buster instead ?

this will get you a more modern version of glibc

    image: python:3.7-slim-buster

3. install node into your image

this will skip the "download node" step of pre-commit by default (specifically it'll default to language_version: system when a suitable node is detected)

this will vary based on your image setup


disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207