Skip to content

Commit f90cb26

Browse files
Common-utils: Fixes "No package jq available" errors for CentOS (devcontainers#644)
* add checks for "jq" * install epel-release if necessary * clean up epel-release post installation of "jq"
1 parent 8b6f088 commit f90cb26

7 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",

src/common-utils/main.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ install_redhat_packages() {
175175
man-db \
176176
strace"
177177

178+
local install_cmd=dnf
179+
if ! type dnf > /dev/null 2>&1; then
180+
install_cmd=yum
181+
fi
182+
178183
# rockylinux:9 installs 'curl-minimal' which clashes with 'curl'
179184
# Install 'curl' for every OS except this rockylinux:9
180185
if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then
@@ -201,16 +206,23 @@ install_redhat_packages() {
201206
package_list="${package_list} zsh"
202207
fi
203208

204-
local install_cmd=dnf
205-
if ! type dnf > /dev/null 2>&1; then
206-
install_cmd=yum
209+
# Install EPEL repository if needed (required to install 'jq' for CentOS)
210+
local remove_epel="false"
211+
if ! ${install_cmd} -q list jq >/dev/null 2>&1; then
212+
${install_cmd} -y install epel-release
213+
remove_epel="true"
207214
fi
215+
208216
${install_cmd} -y install ${package_list}
209217

210218
# Get to latest versions of all packages
211219
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
212220
${install_cmd} upgrade -y
213221
fi
222+
223+
if [[ "${remove_epel}" = "true" ]]; then
224+
${install_cmd} -y remove epel-release
225+
fi
214226
}
215227

216228
# Alpine Linux packages

test/common-utils/centos-7.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source dev-container-features-test-lib
99
. /etc/os-release
1010
check "non-root user" test "$(whoami)" = "devcontainer"
1111
check "distro" test "${VERSION_ID}" = "7"
12+
check "jq" jq --version
1213

1314
# Report result
1415
reportResults

test/common-utils/fedora.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source dev-container-features-test-lib
99
. /etc/os-release
1010
check "non-root user" test "$(whoami)" = "devcontainer"
1111
check "distro" test "${ID}" = "fedora"
12+
check "jq" jq --version
1213

1314
# Report result
1415
reportResults

test/common-utils/mariner.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source dev-container-features-test-lib
99
. /etc/os-release
1010
check "non-root user" test "$(whoami)" = "devcontainer"
1111
check "distro" test "${ID}" = "mariner"
12+
check "jq" jq --version
1213

1314
# Report result
1415
reportResults

test/common-utils/rocky-8.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ source dev-container-features-test-lib
1010
check "non-root user" test "$(whoami)" = "devcontainer"
1111
check "distro" test "${PLATFORM_ID}" = "platform:el8"
1212
check "curl" curl --version
13+
check "jq" jq --version
1314

1415
# Report result
1516
reportResults

test/common-utils/rocky-9.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ source dev-container-features-test-lib
1010
check "non-root user" test "$(whoami)" = "devcontainer"
1111
check "distro" test "${PLATFORM_ID}" = "platform:el9"
1212
check "curl" curl --version
13+
check "jq" jq --version
1314

1415
# Report result
1516
reportResults

0 commit comments

Comments
 (0)