Skip to content

Commit 694906e

Browse files
Add support for Alpine to git feature (#1008)
* 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 <[email protected]>
1 parent 414d345 commit 694906e

File tree

6 files changed

+90
-3
lines changed

6 files changed

+90
-3
lines changed

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, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the `apt`, `yum`, `dnf`, or `microdnf` package manager installed.
5+
This Feature should work on recent versions of Alpine, Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the `apk`, `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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "git",
3-
"version": "1.2.1",
3+
"version": "1.3.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.",

src/git/install.sh

100644100755
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fi
2626
# Get an adjusted ID independent of distro variants
2727
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
2828
ADJUSTED_ID="debian"
29+
elif [ "${ID}" = "alpine" ]; then
30+
ADJUSTED_ID="alpine"
2931
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
3032
ADJUSTED_ID="rhel"
3133
VERSION_CODENAME="${ID}{$VERSION_ID}"
@@ -36,6 +38,8 @@ fi
3638

3739
if type apt-get > /dev/null 2>&1; then
3840
INSTALL_CMD=apt-get
41+
elif type apk > /dev/null 2>&1; then
42+
INSTALL_CMD=apk
3943
elif type microdnf > /dev/null 2>&1; then
4044
INSTALL_CMD=microdnf
4145
elif type dnf > /dev/null 2>&1; then
@@ -53,6 +57,9 @@ clean_up() {
5357
debian)
5458
rm -rf /var/lib/apt/lists/*
5559
;;
60+
alpine)
61+
rm -rf /var/cache/apk/*
62+
;;
5663
rhel)
5764
rm -rf /var/cache/dnf/*
5865
rm -rf /var/cache/yum/*
@@ -102,6 +109,11 @@ pkg_mgr_update() {
102109
echo "Running apt-get update..."
103110
${INSTALL_CMD} update -y
104111
fi
112+
elif [ ${INSTALL_CMD} = "apk" ]; then
113+
if [ "$(find /var/cache/apk/* | wc -l)" = "0" ]; then
114+
echo "Running apk update..."
115+
${INSTALL_CMD} update
116+
fi
105117
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
106118
if [ "$(find /var/cache/${INSTALL_CMD}/* | wc -l)" = "0" ]; then
107119
echo "Running ${INSTALL_CMD} check-update ..."
@@ -118,6 +130,10 @@ check_packages() {
118130
pkg_mgr_update
119131
${INSTALL_CMD} -y install --no-install-recommends "$@"
120132
fi
133+
elif [ ${INSTALL_CMD} = "apk" ]; then
134+
${INSTALL_CMD} add \
135+
--no-cache \
136+
"$@"
121137
elif [ ${INSTALL_CMD} = "dnf" ] || [ ${INSTALL_CMD} = "yum" ]; then
122138
_num_pkgs=$(echo "$@" | tr ' ' \\012 | wc -l)
123139
_num_installed=$(${INSTALL_CMD} -C list installed "$@" | sed '1,/^Installed/d' | wc -l)
@@ -154,6 +170,8 @@ if [ ${GIT_VERSION} = "os-provided" ] || [ ${GIT_VERSION} = "system" ]; then
154170

155171
if [ "$INSTALL_CMD" = "apt-get" ]; then
156172
echo "Installing git from OS apt repository"
173+
elif [ "$INSTALL_CMD" = "apk" ]; then
174+
echo "Installing git from OS apk repository"
157175
else
158176
echo "Installing git from OS yum/dnf repository"
159177
fi
@@ -194,6 +212,14 @@ if [ "${ADJUSTED_ID}" = "debian" ]; then
194212
check_packages libpcre2-posix3
195213
fi
196214

215+
elif [ "${ADJUSTED_ID}" = "alpine" ]; then
216+
217+
# update build dependencies
218+
${INSTALL_CMD} add --no-cache --update curl grep make zlib-dev
219+
220+
# ref. <https://github.com/alpinelinux/aports/blob/32ac93ffb642031b88ba8639fbb3abb324169dea/main/git/APKBUILD#L62>
221+
check_packages asciidoc curl-dev expat-dev g++ gcc openssl-dev pcre2-dev perl-dev perl-error python3-dev tcl tk xmlto
222+
197223
elif [ "${ADJUSTED_ID}" = "rhel" ]; then
198224

199225
if [ $VERSION_CODENAME = "centos7" ]; then
@@ -212,6 +238,10 @@ elif [ "${ADJUSTED_ID}" = "rhel" ]; then
212238
if [ $ID = "mariner" ]; then
213239
check_packages glibc-devel kernel-headers binutils
214240
fi
241+
242+
else
243+
echo "Linux distro ${ID} not supported."
244+
exit 1
215245
fi
216246

217247
# Partial version matching
@@ -235,7 +265,15 @@ echo "Downloading source for ${GIT_VERSION}..."
235265
curl -sL https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz | tar -xzC /tmp 2>&1
236266
echo "Building..."
237267
cd /tmp/git-${GIT_VERSION}
238-
make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc all && make -s USE_LIBPCRE=YesPlease prefix=/usr/local sysconfdir=/etc install 2>&1
268+
git_options=("prefix=/usr/local")
269+
git_options+=("sysconfdir=/etc")
270+
git_options+=("USE_LIBPCRE=YesPlease")
271+
if [ "${ADJUSTED_ID}" = "alpine" ]; then
272+
# ref. <https://github.com/alpinelinux/aports/blob/32ac93ffb642031b88ba8639fbb3abb324169dea/main/git/APKBUILD#L126>
273+
git_options+=("NO_REGEX=YesPlease")
274+
git_options+=("NO_GETTEXT=YesPlease")
275+
fi
276+
make -s "${git_options[@]}" all && make -s "${git_options[@]}" install 2>&1
239277
rm -rf /tmp/git-${GIT_VERSION}
240278
clean_up
241279
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+
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
14+
# Report result
15+
reportResults

test/git/scenarios.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
}
99
}
1010
},
11+
"install_git_from_src_alpine": {
12+
"image": "mcr.microsoft.com/devcontainers/base:alpine",
13+
"features": {
14+
"git": {
15+
"version": "latest",
16+
"ppa": "false"
17+
}
18+
}
19+
},
1120
"install_git_from_src_jammy": {
1221
"image": "ubuntu:jammy",
1322
"features": {
@@ -107,6 +116,15 @@
107116
}
108117
}
109118
},
119+
"install_git_from_system_alpine": {
120+
"image": "mcr.microsoft.com/devcontainers/base:alpine",
121+
"features": {
122+
"git": {
123+
"version": "system",
124+
"ppa": "false"
125+
}
126+
}
127+
},
110128
"install_git_from_system_centos-7": {
111129
"image": "centos:centos7",
112130
"features": {

0 commit comments

Comments
 (0)