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

Commit 2754017

Browse files
authored
Merge pull request #15 from TpmKranz/runner-binary
More ways of obtaining gitlab-runner for container
2 parents 9313843 + 07d40d2 commit 2754017

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

prepare.sh

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,72 @@ install_command() {
9696

9797
install_dependencies() {
9898
# Copy gitlab-runner binary from the server into the container
99-
if [ -x /usr/local/bin/gitlab-runner ]; then
100-
podman cp --pause=false /usr/local/bin/gitlab-runner "$CONTAINER_ID":/usr/bin/gitlab-runner
101-
else
102-
podman cp --pause=false /usr/bin/gitlab-runner "$CONTAINER_ID":/usr/bin/gitlab-runner
99+
local RUNNER_BINARY
100+
local RUNNER_BINARY_PREFIX
101+
local RUNNER_BINARY_TMP
102+
103+
# First check some predefined paths
104+
for RUNNER_BINARY_PREFIX in /usr{/local,}/bin
105+
do
106+
RUNNER_BINARY="${RUNNER_BINARY_PREFIX}/gitlab-runner"
107+
if [ -x "${RUNNER_BINARY}" ]
108+
then
109+
break
110+
fi
111+
done
112+
113+
# If unsuccessful, check shell PATHs
114+
if [ ! -x "${RUNNER_BINARY}" ]
115+
then
116+
RUNNER_BINARY="$(type -p gitlab-runner || true)"
117+
fi
118+
119+
# As a last resort, download binary...
120+
if [ ! -x "${RUNNER_BINARY}" ]
121+
then
122+
# ... to temporary directory
123+
RUNNER_BINARY_TMP="$(mktemp --directory --tmpdir="${CACHE_DIR}")"
124+
RUNNER_BINARY="${RUNNER_BINARY_TMP}/gitlab-runner"
125+
126+
# Find local architecture to download correct binary
127+
# https://stackoverflow.com/questions/45125516/possible-values-for-uname-m/45125525#45125525
128+
local RUNNER_BINARY_ARCH
129+
local RUNNER_BINARY_URL
130+
case "$(uname -m)" in
131+
x86_64)
132+
RUNNER_BINARY_ARCH=amd64
133+
;;
134+
arm)
135+
RUNNER_BINARY_ARCH=arm
136+
;;
137+
i[36]86)
138+
RUNNER_BINARY_ARCH=386
139+
;;
140+
aarch64|armv8l)
141+
RUNNER_BINARY_ARCH=arm64
142+
;;
143+
s390*)
144+
RUNNER_BINARY_ARCH=s390x
145+
;;
146+
ppc64le)
147+
RUNNER_BINARY_ARCH=ppc64le
148+
;;
149+
esac
150+
# https://docs.gitlab.com/runner/install/linux-manually.html#install-1
151+
RUNNER_BINARY_URL="https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-${RUNNER_BINARY_ARCH}"
152+
153+
# Errors during download should kill the script...
154+
curl --location --output "${RUNNER_BINARY}" "${RUNNER_BINARY_URL}"
155+
# ... otherwise, we now have a working gitlab-runner binary
156+
chmod +x "${RUNNER_BINARY}"
157+
fi
158+
159+
podman cp --pause=false "${RUNNER_BINARY}" "$CONTAINER_ID":/usr/bin/gitlab-runner
160+
161+
# Clean up if download directory was used
162+
if [ -d "${RUNNER_BINARY_TMP}" ]
163+
then
164+
rm -rf "${RUNNER_BINARY_TMP}"
103165
fi
104166

105167
# Install bash in systems with APK (e.g., Alpine)

0 commit comments

Comments
 (0)