Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Commit 8e18620

Browse files
committed
Improve git dependency installation
Make installation of git-lfs optional. For example it is missing from Debian 9.
1 parent 1ac7de7 commit 8e18620

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

prepare.sh

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ start_container() {
6363
sleep 999999999
6464
}
6565

66+
install_command() {
67+
# Run test if this binary exists
68+
PACKAGE=$1
69+
TEST_BINARY=$PACKAGE
70+
71+
podman exec --user root:root "$CONTAINER_ID" /bin/bash -c 'if ! type '"$TEST_BINARY"' >/dev/null 2>&1; then
72+
if type apt-get >/dev/null 2>&1; then
73+
echo "APT based distro without '"$TEST_BINARY"'"
74+
apt-get update && apt-get install --no-install-recommends --yes '"$PACKAGE"'
75+
elif type dnf >/dev/null 2>&1; then
76+
echo "DNF based distro without '"$TEST_BINARY"'"
77+
dnf install --setopt=install_weak_deps=False --assumeyes '"$PACKAGE"'
78+
elif type apk >/dev/null 2>&1; then
79+
echo "APK based distro without '"$TEST_BINARY"'"
80+
apk add '"$PACKAGE"'
81+
elif type yum >/dev/null 2>&1; then
82+
echo "YUM based distro without '"$TEST_BINARY"'"
83+
yum install --assumeyes '"$PACKAGE"'
84+
elif type pacman >/dev/null 2>&1; then
85+
echo "PACMAN based distro without '"$TEST_BINARY"'"
86+
pacman --sync --refresh --noconfirm '"$PACKAGE"'
87+
elif type zypper >/dev/null 2>&1; then
88+
echo "ZYPPER based distro without '"$TEST_BINARY"'"
89+
zypper install --no-confirm --no-recommends '"$PACKAGE"'
90+
fi
91+
fi'
92+
}
93+
6694
install_dependencies() {
6795
# Copy gitlab-runner binary from the server into the container
6896
if [ -x /usr/local/bin/gitlab-runner ]; then
@@ -72,23 +100,12 @@ install_dependencies() {
72100
fi
73101

74102
# Install bash in systems with APK (e.g., Alpine)
75-
podman exec "$CONTAINER_ID" sh -c 'if ! type bash >/dev/null 2>&1 && type apk >/dev/null 2>&1 ; then echo "APK based distro without bash"; apk add bash; fi'
76-
77-
# Install git in systems with APT (e.g., Debian)
78-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git >/dev/null 2>&1 && type apt-get >/dev/null 2>&1 ; then echo "APT based distro without git"; apt-get update && apt-get install --no-install-recommends -y ca-certificates git; fi'
79-
# Install git in systems with DNF (e.g., Fedora)
80-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git >/dev/null 2>&1 && type dnf >/dev/null 2>&1 ; then echo "DNF based distro without git"; dnf install --setopt=install_weak_deps=False --assumeyes git; fi'
81-
# Install git in systems with APK (e.g., Alpine)
82-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git >/dev/null 2>&1 && type apk >/dev/null 2>&1 ; then echo "APK based distro without git"; apk add git; fi'
83-
# Install git in systems with YUM (e.g., RHEL<=7)
84-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git >/dev/null 2>&1 && type yum >/dev/null 2>&1 ; then echo "YUM based distro without git"; yum install --assumeyes git; fi'
85-
86-
# Install git-lfs in systems with APT (e.g., Debian)
87-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git-lfs >/dev/null 2>&1 && type apt-get >/dev/null 2>&1 ; then echo "APT based distro without git-lfs"; apt-get update && apt-get install --no-install-recommends -y ca-certificates git-lfs; fi'
88-
# Install git-lfs in systems with DNF (e.g., Fedora)
89-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git-lfs >/dev/null 2>&1 && type dnf >/dev/null 2>&1 ; then echo "DNF based distro without git-lfs"; dnf install --setopt=install_weak_deps=False --assumeyes git-lfs; fi'
90-
# Install git-lfs in systems with APK (e.g., Alpine)
91-
podman exec "$CONTAINER_ID" /bin/bash -c 'if ! type git-lfs >/dev/null 2>&1 && type apk >/dev/null 2>&1 ; then echo "APK based distro without git-lfs"; apk add git-lfs; fi'
103+
podman exec --user root:root "$CONTAINER_ID" sh -c 'if ! type bash >/dev/null 2>&1 && type apk >/dev/null 2>&1 ; then echo "APK based distro without bash"; apk add bash; fi'
104+
105+
install_command ca-certificates
106+
install_command git
107+
# Not available on all systems, e.g., Debian 9 or RHEL 7
108+
install_command git-lfs || true
92109
}
93110

94111
echo "Running in $CONTAINER_ID"

0 commit comments

Comments
 (0)