Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Heroku-24 Git cannot find sub-programs at run-time #137

Open
edmorley opened this issue Jul 29, 2024 · 2 comments
Open

On Heroku-24 Git cannot find sub-programs at run-time #137

edmorley opened this issue Jul 29, 2024 · 2 comments

Comments

@edmorley
Copy link
Member

On Heroku-24, Git only exists in the build image and not the run image. As such, if Git is needed at runtime it has to be installed using the APT buildpack. This install succeeds, and a git --version works at run-time, however, when attempting to actually clone a repository Git gives an error message:

$ mkdir testcase-git && cd $_
$ echo git > Aptfile
$ git init && git add -A && git commit -m '.'
$ h create --stack heroku-24 --buildpack heroku-community/apt
$ git push heroku main
...
remote: -----> Building on the Heroku-24 stack
remote: -----> Using buildpack: heroku-community/apt
remote: -----> Apt app detected
remote: -----> Detected Aptfile or Stack changes, flushing cache
remote: -----> Updating APT package index
...
remote: -----> Fetching .debs for git
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 12 not upgraded.
remote:        Need to get 3,679 kB of archives.
remote:        After this operation, 0 B of additional disk space will be used.
remote:        Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 git amd64 1:2.43.0-1ubuntu7.1 [3,679 kB]
remote:        Fetched 3,679 kB in 1s (4,106 kB/s)
remote:        Download complete and in download only mode
remote: -----> Installing git_1%3a2.43.0-1ubuntu7.1_amd64.deb
remote: -----> Writing profile script
remote: -----> Rewrite package-config files
remote: -----> Discovering process types
...
$ h run bash
~ $ git --version
git version 2.43.0
~ $ git clone https://github.com/heroku/12factor.git
Cloning into '12factor'...
warning: templates not found in /usr/share/git-core/templates
git: 'remote-https' is not a git command. See 'git --help'.

This is because Git internally uses a number of sub-commands that must be found on PATH, and Git cannot find the git-remote-https command, which is installed by this buildpack to /app/.apt/usr/lib/git-core, since Git is still looking at the normal system location (set when Git was compiled):

~ $ git --exec-path
/app/.apt/usr/lib/git-core

However, Git allows for this location to be changed via the GIT_EXEC_PATH env var:
https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

So if that is set, cloning then works:

~ $ export GIT_EXEC_PATH=/app/.apt/usr/lib/git-core
~ $ git --exec-path
/app/.apt/usr/lib/git-core
~ $ git clone https://github.com/heroku/12factor
Cloning into '12factor'...
warning: templates not found in /usr/share/git-core/templates
remote: Enumerating objects: 4745, done.
remote: Counting objects: 100% (880/880), done.
remote: Compressing objects: 100% (482/482), done.
remote: Total 4745 (delta 425), reused 781 (delta 383), pack-reused 3865
Receiving objects: 100% (4745/4745), 1.98 MiB | 31.23 MiB/s, done.
Resolving deltas: 100% (2846/2846), done.

To save users from having to set the config var GIT_EXEC_PATH=/app/.apt/usr/lib/git-core on their Heroku app, the APT buildpack could set this env var automatically iff the /app/.apt/usr/lib/git-core directory exists (ie if a userland install of Git was performed).

@edmorley
Copy link
Member Author

edmorley commented Oct 2, 2024

@colincasey I don't suppose this is something you would have time to take a look at? The env var would only need to be set at run time, and only when the git package was installed.

@edmorley
Copy link
Member Author

edmorley commented Oct 2, 2024

In the meantime, I've documented the workaround at:
https://devcenter.heroku.com/articles/heroku-24-stack#changes-to-git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant