nanos / FediFetcher

FediFetcher is a tool for Mastodon that automatically fetches missing replies and posts from other fediverse instances, and adds them to your own Mastodon instance.
https://blog.thms.uk/fedifetcher?utm_source=github
MIT License
309 stars 230 forks source link

Docker container won't run: Bad git executable #70

Closed MarcelWaldvogel closed 1 year ago

MarcelWaldvogel commented 1 year ago

I upgraded to v7.0.0 docker image today and the docker-compose run fedifetcher command now fails. Forcing the image version to v6.0.0 fixes this.

I would guess this is part of the code that tries to get the version number from git, but that git is not installed in the new image. (Haven't looked into to the code to check.)

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/git/__init__.py", line 89, in <module>
    refresh()
  File "/usr/local/lib/python3.11/site-packages/git/__init__.py", line 76, in refresh
    if not Git.refresh(path=path):
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/git/cmd.py", line 392, in refresh
    raise ImportError(err)
ImportError: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/find_posts.py", line 15, in <module>
    import git
  File "/usr/local/lib/python3.11/site-packages/git/__init__.py", line 91, in <module>
    raise ImportError("Failed to initialize: {0}".format(exc)) from exc
ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet
Jasdemi commented 1 year ago

Same here. v6.0.0 still works fine.

nanos commented 1 year ago

Yes. This was discussed here as well, where you can also read about the rationale behind this:

https://pfalz.social/@maschinenraum/110836182954523189

I appreciate that this isn’t best practice, so I’m keen to discuss alternative ideas. What are everyone’s suggestions?

YoannMa commented 1 year ago

In the container, you wouldn't have your .git folder as well, so even if you would add the git executable, you couldn't get the info you want.

A way to avoid all of that would be to set up a build argument adding the version/commit id in an environment variable and using those instead of git.

Example :

Dockerfile

ARG VERSION
ENV VERSION=$VERSION

GitHub action

 - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v4
        with:
          push: true
          build-args: |
            VERSION=${{ github.ref_name }}
nanos commented 1 year ago

I have completely reverted this now in v7.0.1. I might revisit this later, but at this time I think that the ability to run FediFetcher from the container, outweighs the benefit from printing the version string during start up.