Unverified Commit 97565a7e authored by Jeff Putsch's avatar Jeff Putsch Committed by GitHub

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: 's avatarSamruddhi 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: 's avatarJeff Putsch <jputsch@analog.com>
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>
parent 3e0c0ae1
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
## OS Support ## OS Support
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. 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.
`bash` is required to execute the `install.sh` script. `bash` is required to execute the `install.sh` script.
{ {
"id": "git", "id": "git",
"version": "1.1.6", "version": "1.2.0",
"name": "Git (from source)", "name": "Git (from source)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/git", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/git",
"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.", "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,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"ppa": { "ppa": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Install from PPA if available" "description": "Install from PPA if available (only supported for Ubuntu distributions)"
} }
}, },
"installsAfter": [ "installsAfter": [
......
...@@ -16,16 +16,51 @@ keyserver hkp://keyserver.ubuntu.com:80 ...@@ -16,16 +16,51 @@ keyserver hkp://keyserver.ubuntu.com:80
keyserver hkps://keys.openpgp.org keyserver hkps://keys.openpgp.org
keyserver hkp://keyserver.pgp.com" keyserver hkp://keyserver.pgp.com"
set -e
# Clean up
rm -rf /var/lib/apt/lists/*
if [ "$(id -u)" -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1 exit 1
fi fi
# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
. /etc/os-release
# Get an adjusted ID independent of distro variants
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
ADJUSTED_ID="debian"
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
ADJUSTED_ID="rhel"
VERSION_CODENAME="${ID}{$VERSION_ID}"
else
echo "Linux distro ${ID} not supported."
exit 1
fi
if type apt-get > /dev/null 2>&1; then
INSTALL_CMD=apt-get
elif type microdnf > /dev/null 2>&1; then
INSTALL_CMD=microdnf
elif type dnf > /dev/null 2>&1; then
INSTALL_CMD=dnf
elif type yum > /dev/null 2>&1; then
INSTALL_CMD=yum
else
echo "(Error) Unable to find a supported package manager."
exit 1
fi
# Clean up
clean_up() {
case $ADJUSTED_ID in
debian)
rm -rf /var/lib/apt/lists/*
;;
rhel)
rm -rf /var/cache/dnf/*
rm -rf /var/cache/yum/*
;;
esac
}
clean_up
# Import the specified key in a variable name passed in as # Import the specified key in a variable name passed in as
receive_gpg_keys() { receive_gpg_keys() {
local keys=${!1} local keys=${!1}
...@@ -61,40 +96,73 @@ receive_gpg_keys() { ...@@ -61,40 +96,73 @@ receive_gpg_keys() {
fi fi
} }
apt_get_update() pkg_mgr_update() {
{ if [ ${INSTALL_CMD} = "apt-get" ]; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..." echo "Running apt-get update..."
apt-get update -y ${INSTALL_CMD} update -y
fi
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
if [ "$(find /var/cache/${INSTALL_CMD}/* | wc -l)" = "0" ]; then
echo "Running ${INSTALL_CMD} check-update ..."
${INSTALL_CMD} check-update
fi
fi fi
} }
# Checks if packages are installed and installs them if not # Checks if packages are installed and installs them if not
check_packages() { check_packages() {
if [ ${INSTALL_CMD} = "apt-get" ]; then
if ! dpkg -s "$@" > /dev/null 2>&1; then if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update pkg_mgr_update
apt-get -y install --no-install-recommends "$@" ${INSTALL_CMD} -y install --no-install-recommends "$@"
fi
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
_num_pkgs=$(echo "$@" | tr ' ' \\012 | wc -l)
_num_installed=$(${INSTALL_CMD} -C list installed "$@" | sed '1,/^Installed/d' | wc -l)
if [ ${_num_pkgs} != ${_num_installed} ]; then
pkg_mgr_update
${INSTALL_CMD} -y install "$@"
fi
elif [ ${INSTALL_CMD} = "microdnf" ]; then
${INSTALL_CMD} -y install \
--refresh \
--best \
--nodocs \
--noplugins \
--setopt=install_weak_deps=0 \
"$@"
else
echo "Linux distro ${ID} not supported."
exit 1
fi fi
} }
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
# Source /etc/os-release to get OS info # Debian / Ubuntu packages
. /etc/os-release
# If the os provided version is "good enough", just install that. # If the os provided version is "good enough", just install that.
if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then
if type git > /dev/null 2>&1; then if type git > /dev/null 2>&1; then
echo "Detected existing system install: $(git version)" echo "Detected existing system install: $(git version)"
# Clean up # Clean up
rm -rf /var/lib/apt/lists/* clean_up
exit 0 exit 0
fi fi
if [ "$INSTALL_CMD" = "apt-get" ]; then
echo "Installing git from OS apt repository" echo "Installing git from OS apt repository"
else
echo "Installing git from OS yum/dnf repository"
fi
if [ $ID = "mariner" ]; then
check_packages ca-certificates
fi
check_packages git check_packages git
# Clean up # Clean up
rm -rf /var/lib/apt/lists/* clean_up
exit 0 exit 0
fi fi
...@@ -104,15 +172,47 @@ if ([ "${GIT_VERSION}" = "latest" ] || [ "${GIT_VERSION}" = "lts" ] || [ "${GIT_ ...@@ -104,15 +172,47 @@ if ([ "${GIT_VERSION}" = "latest" ] || [ "${GIT_VERSION}" = "lts" ] || [ "${GIT_
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
receive_gpg_keys GIT_CORE_PPA_ARCHIVE_GPG_KEY /usr/share/keyrings/gitcoreppa-archive-keyring.gpg receive_gpg_keys GIT_CORE_PPA_ARCHIVE_GPG_KEY /usr/share/keyrings/gitcoreppa-archive-keyring.gpg
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 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
apt-get update ${INSTALL_CMD} update
apt-get -y install --no-install-recommends git ${INSTALL_CMD} -y install --no-install-recommends git
rm -rf "/tmp/tmp-gnupg" rm -rf "/tmp/tmp-gnupg"
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
exit 0 exit 0
fi fi
# Install required packages to build if missing # Install required packages to build if missing
check_packages build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libcurl?-openssl-dev libexpat1-dev if [ "${ADJUSTED_ID}" = "debian" ]; then
check_packages build-essential curl ca-certificates tar gettext libssl-dev zlib1g-dev libcurl?-openssl-dev libexpat1-dev
check_packages libpcre2-dev
if [ "${VERSION_CODENAME}" = "focal" ] || [ "${VERSION_CODENAME}" = "bullseye" ]; then
check_packages libpcre2-posix2
elif [ "${VERSION_CODENAME}" = "bionic" ] || [ "${VERSION_CODENAME}" = "buster" ]; then
check_packages libpcre2-posix0
else
check_packages libpcre2-posix3
fi
elif [ "${ADJUSTED_ID}" = "rhel" ]; then
if [ $VERSION_CODENAME = "centos7" ]; then
check_packages centos-release-scl
check_packages devtoolset-11
source /opt/rh/devtoolset-11/enable
else
check_packages gcc
fi
check_packages libcurl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel cmake pcre2-devel tar gzip ca-certificates
if ! type curl > /dev/null 2>&1; then
check_packages curl
fi
if [ $ID = "mariner" ]; then
check_packages glibc-devel kernel-headers binutils
fi
fi
# Partial version matching # Partial version matching
if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then
...@@ -131,21 +231,11 @@ if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then ...@@ -131,21 +231,11 @@ if [ "$(echo "${GIT_VERSION}" | grep -o '\.' | wc -l)" != "2" ]; then
fi fi
fi fi
check_packages libpcre2-dev
if [ "${VERSION_CODENAME}" = "focal" ] || [ "${VERSION_CODENAME}" = "bullseye" ]; then
check_packages libpcre2-posix2
elif [ "${VERSION_CODENAME}" = "bionic" ] || [ "${VERSION_CODENAME}" = "buster" ]; then
check_packages libpcre2-posix0
else
check_packages libpcre2-posix3
fi
echo "Downloading source for ${GIT_VERSION}..." echo "Downloading source for ${GIT_VERSION}..."
curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1 curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1
echo "Building..." echo "Building..."
cd /tmp/git-${GIT_VERSION} cd /tmp/git-${GIT_VERSION}
make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc all && make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc install 2>&1 make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc all && make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc install 2>&1
rm -rf /tmp/git-${GIT_VERSION} rm -rf /tmp/git-${GIT_VERSION}
rm -rf /var/lib/apt/lists/* clean_up
echo "Done!" echo "Done!"
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
. /etc/os-release
check "non-root user" test "$(whoami)" = "devcontainer"
check "distro" test "${PLATFORM_ID}" = "platform:el9"
check "curl" curl --version
check "jq" jq --version
# Report result
reportResults
\ No newline at end of file
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
. /etc/os-release
check "non-root user" test "$(whoami)" = "devcontainer"
check "distro" test "${PLATFORM_ID}" = "platform:el9"
check "curl" curl --version
check "jq" jq --version
# Report result
reportResults
\ No newline at end of file
...@@ -5,6 +5,7 @@ set -e ...@@ -5,6 +5,7 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
# Definition specific tests
check "version" git --version check "version" git --version
check "gettext" dpkg-query -l gettext check "gettext" dpkg-query -l gettext
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
...@@ -5,6 +5,7 @@ set -e ...@@ -5,6 +5,7 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
# Definition specific tests
check "version" git --version check "version" git --version
check "gettext" dpkg-query -l gettext check "gettext" dpkg-query -l gettext
......
...@@ -5,6 +5,7 @@ set -e ...@@ -5,6 +5,7 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
# Definition specific tests
check "version" git --version check "version" git --version
check "gettext" dpkg-query -l gettext check "gettext" dpkg-query -l gettext
......
...@@ -5,6 +5,7 @@ set -e ...@@ -5,6 +5,7 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
# Definition specific tests
check "version" git --version check "version" git --version
check "gettext" dpkg-query -l gettext check "gettext" dpkg-query -l gettext
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
...@@ -5,6 +5,7 @@ set -e ...@@ -5,6 +5,7 @@ set -e
# Optional: Import test library # Optional: Import test library
source dev-container-features-test-lib source dev-container-features-test-lib
# Definition specific tests
check "version" git --version check "version" git --version
check "gettext" dpkg-query -l gettext check "gettext" dpkg-query -l gettext
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
# Ensure git clone works, i.e. ca-certificates are installed.
check "git clone" bash -c "cd /tmp && git clone https://github.com/devcontainers/feature-starter.git"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" git --version
cd /tmp && git clone https://github.com/devcontainers/feature-starter.git
cd feature-starter
check "perl" bash -c "git -c grep.patternType=perl grep -q 'a.+b'"
# Report result
reportResults
...@@ -43,5 +43,131 @@ ...@@ -43,5 +43,131 @@
"ppa": "false" "ppa": "false"
} }
} }
},
"install_git_from_src_centos-7": {
"image": "centos:centos7",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_alma-8": {
"image": "almalinux:8",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_alma-9": {
"image": "almalinux:9",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_rocky-8": {
"image": "rockylinux:8",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_rocky-9": {
"image": "rockylinux:9",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_fedora": {
"image": "fedora",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_src_mariner": {
"image": "mcr.microsoft.com/cbl-mariner/base/core:2.0",
"features": {
"git": {
"version": "latest",
"ppa": "false"
}
}
},
"install_git_from_system_centos-7": {
"image": "centos:centos7",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_alma-8": {
"image": "almalinux:8",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_alma-9": {
"image": "almalinux:9",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_rocky-8": {
"image": "rockylinux:8",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_rocky-9": {
"image": "rockylinux:9",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_fedora": {
"image": "fedora",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
},
"install_git_from_system_mariner": {
"image": "mcr.microsoft.com/cbl-mariner/base/core:2.0",
"features": {
"git": {
"version": "system",
"ppa": "true"
}
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment