Skip to content

Git: Use sysconfdir=/etc for git built from source - #395

Merged
Samruddhi Khandale (samruddhikhandale) merged 2 commits into
mainfrom
samruddhikhandale/add-symlink-git
Jan 11, 2023
Merged

Samruddhi Khandale (samruddhikhandale) merged 2 commits into
mainfrom
samruddhikhandale/add-symlink-git

Conversation

@samruddhikhandale

@samruddhikhandale Samruddhi Khandale (samruddhikhandale) commented Jan 10, 2023 •

Copy link
Copy Markdown
Member

Generally, libraries/tools expects the gitconfig to be located at /etc/gitconfig. However, when 'git' is built from source, it uses the /usr/local prefix & creates a gitconfig file at ${prefix}/etc/config ie /usr/local/etc/config .

Building with sysconfdir=/etc to fix this issue.

@jkeech John Keech (jkeech) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a symlink for the git config, I think it would be much better to build git from source with the correct prefix set to target a global installation. if we set prefix to be /usr, the system config path will automatically be derived correctly, which will also set up system-level gitattributes and other files properly.

@samruddhikhandale

Copy link
Copy Markdown
Member Author

Instead of adding a symlink for the git config, I think it would be much better to build git from source with the correct prefix set to target a global installation. if we set prefix to be /usr, the system config path will automatically be derived correctly, which will also set up system-level gitattributes and other files properly.

John Keech (@jkeech) As git is part of the distro. Shouldn't we always install tools which are not managed by OS in /usr/local/* ? Also, isn't that the reason /usr/local/bin always exist in PATH ?
Hence, the correct location of gitconfig will be /usr/local/etc 🤔

That's the reason I avoided changing the prefix to /usr.

@jkeech

Copy link
Copy Markdown
Contributor

John Keech (@jkeech) As git is part of the distro. Shouldn't we always install tools which are not managed by OS in /usr/local/* ? Also, isn't that the reason /usr/local/bin always exist in PATH ?
Hence, the correct location of gitconfig will be /usr/local/etc

I thought the point of this PR is to make building git from source behave the same as installing from apt (and in fact to replace a potentially previously-installed version of git from apt). If so, we'll want to build git with the /usr prefix and make sure it's installed into /usr.

From https://www.pathname.com/fhs/pub/fhs-2.3.html#USRLOCALLOCALHIERARCHY:

Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr. [27]

If we really don't want to modify prefix, then git does allow you to directly set sysconfdir to /etc which would be a more robust solution than symlinking the system config file after git is built/installed.

@Chuxel

Chuck Lantz (Chuxel) commented Jan 11, 2023 •

Copy link
Copy Markdown
Member

John Keech (@jkeech) As git is part of the distro. Shouldn't we always install tools which are not managed by OS in /usr/local/* ? Also, isn't that the reason /usr/local/bin always exist in PATH ?
Hence, the correct location of gitconfig will be /usr/local/etc

I thought the point of this PR is to make building git from source behave the same as installing from apt (and in fact to replace a potentially previously-installed version of git from apt). If so, we'll want to build git with the /usr prefix and make sure it's installed into /usr.

From https://www.pathname.com/fhs/pub/fhs-2.3.html#USRLOCALLOCALHIERARCHY:

Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr. [27]

If we really don't want to modify prefix, then git does allow you to directly set sysconfdir to /etc which would be a more robust solution than symlinking the system config file after git is built/installed.

John Keech (@jkeech) Yeah, installing under / or /usr will have very unpredictable behaviors and should not be done. This is why /usr/local exists to begin with. If it doesn't fully break apt, it can result in strange behaviors like apt-get update && apt-get upgrade actually downgrading git. / is only for things managed by the distro. Even if git is not installed initially, it is part of the OS, much like Python, and therefore can be chained in by other packages that need it. This again will either bomb the apt install entirely or downgrade git.

It's one thing if this were the final image... but in this case, end users can extend the image or add software by hand within the Dev Container at runtime.

@Chuxel

Chuck Lantz (Chuxel) commented Jan 11, 2023 •

Copy link
Copy Markdown
Member

One possible way to handle this would be to generate a deb and let apt manage the install, but that's quite a more work.

@jkeech

Copy link
Copy Markdown
Contributor

Chuck Lantz (@Chuxel), that's where the sysconfdir build variable comes into play when building git from source. It can be modified independently of prefix if we want to keep the prefix as /usr/local. I'm just not sure if there are other things we are missing if we only modify the sysconfdir. We got reports about the system level gitconfig file path changing and breaking tools when the feature builds from source, so we know that's one specific problem, but there might be other subtle differences beyond that. The closer we can get to the same behavior as the git build that's installed by apt, the better IMO.

If we really don't want to modify prefix, then git does allow you to directly set sysconfdir to /etc which would be a more robust solution than symlinking the system config file after git is built/installed.

@samruddhikhandale Samruddhi Khandale (samruddhikhandale) changed the title Git: Adds a new 'addGitConfigSymlink' option Git: Use sysconfdir=/etc for git built from source Jan 11, 2023
@samruddhikhandale
Samruddhi Khandale (samruddhikhandale) deleted the samruddhikhandale/add-symlink-git branch January 11, 2023 19:02
Jonathan Backhaus (jonbackhaus) added a commit to jonbackhaus/devcontainer-features that referenced this pull request Jun 27, 2024
Jonathan Backhaus (jonbackhaus) added a commit to jonbackhaus/devcontainer-features that referenced this pull request Jun 27, 2024
Samruddhi Khandale (samruddhikhandale) added a commit that referenced this pull request Jun 27, 2024
* feat: add basic scaffolding for alpine, based on debian implementation

* feat: add baseline packages from <https://github.com/alpinelinux/aports/blob/master/main/git/APKBUILD>

* fix: add `curl` package (needed for version lookup)

* feat: use `jq`-based version matching implementation for alpine

the alpine version of `grep` doesn't support PCRE

* fix: forgot to strip the leading "v" from the version number

* fix: need `make` package to build from source

* feat: parameterize make options to easily inject Alpine-specific option

* fix: wip: latest baseline (still breaking due to musl)

* feat: add basic scaffolding for alpine, based on debian implementation

note: this won't install from source (due to build issues with musl) but will install using the `apk` package manager

* chore: chmod +x

* chore: bump semver (proposed)

* docs: add Alpine/apk to notes

* test: add test for `alpine:3` to install system package

note: feature does not currently implement building from source on Alpine

* fix: working build from source!

still need to tweak the package dependencies and make config

* perf: remove OBE `gettext-dev` package from dependencies

no longer required with "NO_GETTEXT=YesPlease" make config

* perf: remove OBE `libintl` package from dependencies

no longer required with "NO_GETTEXT=YesPlease" make config (?)

* feat: add remaining make options from apk package source reference

* docs: add refs. for alpine build from source

* test(git): add test case for building git from src on alpine:3

* fix: lint: SC2068: Double quote array expansions to avoid re-splitting elements

* fix: use Devcontainer Alpine image as base (because it has `bash` installed); refactor test script names to remove major version suffix (since it isn't specified in the associated image tag)

* perf: consolidate to a single, jq-based implementation

using `jq` avoids the need for PCRE `grep` expression (not supported in Alpine)

* fix: set `sysconfdir` option for alpine build as well

see [#395](#395)

* test: fix: alpine doesn't include perl support; leverage test cases from `install_git_from_src.sh` script

* style: remove unused options

* fix: set `prefix` option for alpine build to be consistent with other builds

see [#395](#395)

* refactor: move common arguments out of distro-specific logic

* perf: minimum set of make options for building git from source in Alpine

* chore: remove OBE code (unused make options for Git)

* style: whitespace

* test: fix: remove `gettext` check (since this package isn't installed in Alpine)

* feat: update implementation based on local Git feature in `base-alpine` image

* feat: remove `libsecret-dev` package

not present in local Git feature in `base-alpine` image `install.sh` script

* feat: switch `glib-dev` to `g++` and `gcc` packages, based on local Git feature in `base-alpine` image

* chore: remove `alpine-sdk` package, based on local Git feature in `base-alpine` image

no longer needed, based on initial testing

* revert: switch back to `grep`-based PCRE implementation,  based on local Git feature in `base-alpine` image

`jq` package no longer needed

* test: revert: remove test cases (covered by generic `install_git_from_src.sh`)

* test: fix: remove perl check for system package in Alpine (because the system package is not built with PCRE support)

---------

Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com>
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

Successfully merging this pull request may close these issues.

3 participants