Skip to content

Commit 97565a7

Browse files
jdputschadiJeff Putschsamruddhikhandale
authored
Add RHEL support to git feature (#782)
* Git feature passes all tests: existing + rhel-based base images: centos7, alma-{8,9}, alma-{8,9}-minimal * update per PR comments * Fix apt typo... * udpate per PR code review * revert README.md * update per samruddhikhandale's feedback. * Update src/git/install.sh Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com> * stop non-fatal error messages in RHEL tests. * remove tests for alma-[89]-minimal base images for now. * add install system git tests for RHEL base images * *_system_* tests install from system repositories, not latest version * fix broken install_git_from_system_mariner test * fix broken install_git_from_system_mariner test --------- Co-authored-by: Jeff Putsch <jputsch@analog.com> Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
1 parent 3e0c0ae commit 97565a7

25 files changed

Lines changed: 513 additions & 37 deletions

src/git/NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
## OS Support
44

5-
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
5+
This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the `apt`, `yum`, `dnf`, or `microdnf` package manager installed.
66

77
`bash` is required to execute the `install.sh` script.

src/git/devcontainer-feature.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "git",
3-
"version": "1.1.6",
3+
"version": "1.2.0",
44
"name": "Git (from source)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/git",
66
"description": "Install an up-to-date version of Git, built from source as needed. Useful for when you want the latest and greatest features. Auto-detects latest stable version and installs needed dependencies.",
@@ -17,10 +17,10 @@
1717
"ppa": {
1818
"type": "boolean",
1919
"default": true,
20-
"description": "Install from PPA if available"
20+
"description": "Install from PPA if available (only supported for Ubuntu distributions)"
2121
}
2222
},
2323
"installsAfter": [
2424
"ghcr.io/devcontainers/features/common-utils"
2525
]
26-
}
26+
}

src/git/install.sh

100755100644
Lines changed: 122 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,51 @@ keyserver hkp://keyserver.ubuntu.com:80
1616
keyserver hkps://keys.openpgp.org
1717
keyserver hkp://keyserver.pgp.com"
1818

19-
set -e
20-
21-
# Clean up
22-
rm -rf /var/lib/apt/lists/*
23-
2419
if [ "$(id -u)" -ne 0 ]; then
2520
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
2621
exit 1
2722
fi
2823

24+
# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
25+
. /etc/os-release
26+
# Get an adjusted ID independent of distro variants
27+
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
28+
ADJUSTED_ID="debian"
29+
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
30+
ADJUSTED_ID="rhel"
31+
VERSION_CODENAME="${ID}{$VERSION_ID}"
32+
else
33+
echo "Linux distro ${ID} not supported."
34+
exit 1
35+
fi
36+
37+
if type apt-get > /dev/null 2>&1; then
38+
INSTALL_CMD=apt-get
39+
elif type microdnf > /dev/null 2>&1; then
40+
INSTALL_CMD=microdnf
41+
elif type dnf > /dev/null 2>&1; then
42+
INSTALL_CMD=dnf
43+
elif type yum > /dev/null 2>&1; then
44+
INSTALL_CMD=yum
45+
else
46+
echo "(Error) Unable to find a supported package manager."
47+
exit 1
48+
fi
49+
50+
# Clean up
51+
clean_up() {
52+
case $ADJUSTED_ID in
53+
debian)
54+
rm -rf /var/lib/apt/lists/*
55+
;;
56+
rhel)
57+
rm -rf /var/cache/dnf/*
58+
rm -rf /var/cache/yum/*
59+
;;
60+
esac
61+
}
62+
clean_up
63+
2964
# Import the specified key in a variable name passed in as
3065
receive_gpg_keys() {
3166
local keys=${!1}
@@ -61,40 +96,73 @@ receive_gpg_keys() {
6196
fi
6297
}
6398

64-
apt_get_update()
65-
{
66-
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
67-
echo "Running apt-get update..."
68-
apt-get update -y
99+
pkg_mgr_update() {
100+
if [ ${INSTALL_CMD} = "apt-get" ]; then
101+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
102+
echo "Running apt-get update..."
103+
${INSTALL_CMD} update -y
104+
fi
105+
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
106+
if [ "$(find /var/cache/${INSTALL_CMD}/* | wc -l)" = "0" ]; then
107+
echo "Running ${INSTALL_CMD} check-update ..."
108+
${INSTALL_CMD} check-update
109+
fi
69110
fi
70111
}
71112

113+
72114
# Checks if packages are installed and installs them if not
73115
check_packages() {
74-
if ! dpkg -s "$@" > /dev/null 2>&1; then
75-
apt_get_update
76-
apt-get -y install --no-install-recommends "$@"
116+
if [ ${INSTALL_CMD} = "apt-get" ]; then
117+
if ! dpkg -s "$@" > /dev/null 2>&1; then
118+
pkg_mgr_update
119+
${INSTALL_CMD} -y install --no-install-recommends "$@"
120+
fi
121+
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
122+
_num_pkgs=$(echo "$@" | tr ' ' \\012 | wc -l)
123+
_num_installed=$(${INSTALL_CMD} -C list installed "$@" | sed '1,/^Installed/d' | wc -l)
124+
if [ ${_num_pkgs} != ${_num_installed} ]; then
125+
pkg_mgr_update
126+
${INSTALL_CMD} -y install "$@"
127+
fi
128+
elif [ ${INSTALL_CMD} = "microdnf" ]; then
129+
${INSTALL_CMD} -y install \
130+
--refresh \
131+
--best \
132+
--nodocs \
133+
--noplugins \
134+
--setopt=install_weak_deps=0 \
135+
"$@"
136+
else
137+
echo "Linux distro ${ID} not supported."
138+
exit 1
77139
fi
78140
}
79141

80142
export DEBIAN_FRONTEND=noninteractive
81143

82-
# Source /etc/os-release to get OS info
83-
. /etc/os-release
144+
# Debian / Ubuntu packages
84145

85146
# If the os provided version is "good enough", just install that.
86147
if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then
87148
if type git > /dev/null 2>&1; then
88149
echo "Detected existing system install: $(git version)"
89150
# Clean up
90-
rm -rf /var/lib/apt/lists/*
151+
clean_up
91152
exit 0
92153
fi
93154

94-
echo "Installing git from OS apt repository"
155+
if [ "$INSTALL_CMD" = "apt-get" ]; then
156+
echo "Installing git from OS apt repository"
157+
else
158+
echo "Installing git from OS yum/dnf repository"
159+
fi
160+
if [ $ID = "mariner" ]; then
161+
check_packages ca-certificates
162+
fi
95163
check_packages git
96164
# Clean up
97-
rm -rf /var/lib/apt/lists/*
165+
clean_up
98166
exit 0
99167
fi
100168

@@ -104,15 +172,47 @@ if ([ "${GIT_VERSION}" = "latest" ] || [ "${GIT_VERSION}" = "lts" ] || [ "${GIT_
104172
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
105173
receive_gpg_keys GIT_CORE_PPA_ARCHIVE_GPG_KEY /usr/share/keyrings/gitcoreppa-archive-keyring.gpg
106174
echo -e "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gitcoreppa-archive-keyring.gpg] http://ppa.launchpad.net/git-core/ppa/ubuntu ${VERSION_CODENAME} main\ndeb-src [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gitcoreppa-archive-keyring.gpg] http://ppa.launchpad.net/git-core/ppa/ubuntu ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/git-core-ppa.list
107-
apt-get update
108-
apt-get -y install --no-install-recommends git
175+
${INSTALL_CMD} update
176+
${INSTALL_CMD} -y install --no-install-recommends git
109177
rm -rf "/tmp/tmp-gnupg"
110178
rm -rf /var/lib/apt/lists/*
111179
exit 0
112180
fi
113181

114182
# Install required packages to build if missing
115-
check_packages build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libcurl?-openssl-dev libexpat1-dev
183+
if [ "${ADJUSTED_ID}" = "debian" ]; then
184+
185+
check_packages build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libcurl?-openssl-dev libexpat1-dev
186+
187+
check_packages libpcre2-dev
188+
189+
if [ "${VERSION_CODENAME}" = "focal" ] || [ "${VERSION_CODENAME}" = "bullseye" ]; then
190+
check_packages libpcre2-posix2
191+
elif [ "${VERSION_CODENAME}" = "bionic" ] || [ "${VERSION_CODENAME}" = "buster" ]; then
192+
check_packages libpcre2-posix0
193+
else
194+
check_packages libpcre2-posix3
195+
fi
196+
197+
elif [ "${ADJUSTED_ID}" = "rhel" ]; then
198+
199+
if [ $VERSION_CODENAME = "centos7" ]; then
200+
check_packages centos-release-scl
201+
check_packages devtoolset-11
202+
source /opt/rh/devtoolset-11/enable
203+
else
204+
check_packages gcc
205+
fi
206+
207+
208+
check_packages libcurl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel cmake pcre2-devel tar gzip ca-certificates
209+
if ! type curl > /dev/null 2>&1; then
210+
check_packages curl
211+
fi
212+
if [ $ID = "mariner" ]; then
213+
check_packages glibc-devel kernel-headers binutils
214+
fi
215+
fi
116216

117217
# Partial version matching
118218
if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then
@@ -131,21 +231,11 @@ if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then
131231
fi
132232
fi
133233

134-
check_packages libpcre2-dev
135-
136-
if [ "${VERSION_CODENAME}" = "focal" ] || [ "${VERSION_CODENAME}" = "bullseye" ]; then
137-
check_packages libpcre2-posix2
138-
elif [ "${VERSION_CODENAME}" = "bionic" ] || [ "${VERSION_CODENAME}" = "buster" ]; then
139-
check_packages libpcre2-posix0
140-
else
141-
check_packages libpcre2-posix3
142-
fi
143-
144234
echo "Downloading source for ${GIT_VERSION}..."
145235
curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1
146236
echo "Building..."
147237
cd /tmp/git-${GIT_VERSION}
148238
make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc all && make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc install 2>&1
149239
rm -rf /tmp/git-${GIT_VERSION}
150-
rm -rf /var/lib/apt/lists/*
240+
clean_up
151241
echo "Done!"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
. /etc/os-release
10+
check "non-root user" test "$(whoami)" = "devcontainer"
11+
check "distro" test "${PLATFORM_ID}" = "platform:el9"
12+
check "curl" curl --version
13+
check "jq" jq --version
14+
15+
# Report result
16+
reportResults
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
. /etc/os-release
10+
check "non-root user" test "$(whoami)" = "devcontainer"
11+
check "distro" test "${PLATFORM_ID}" = "platform:el9"
12+
check "curl" curl --version
13+
check "jq" jq --version
14+
15+
# Report result
16+
reportResults

test/git/install_git_from_src.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Definition specific tests
89
check "version" git --version
910
check "gettext" dpkg-query -l gettext
1011

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "version" git --version
10+
11+
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
12+
cd feature-starter
13+
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
14+
15+
# Report result
16+
reportResults
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "version" git --version
10+
11+
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
12+
cd feature-starter
13+
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
14+
15+
# Report result
16+
reportResults

test/git/install_git_from_src_bionic.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Definition specific tests
89
check "version" git --version
910
check "gettext" dpkg-query -l gettext
1011

test/git/install_git_from_src_bullseye.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8+
# Definition specific tests
89
check "version" git --version
910
check "gettext" dpkg-query -l gettext
1011

0 commit comments

Comments
 (0)