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

Commit 07d40d2

Browse files
committed
More ways of obtaining gitlab-runner for container
1 parent 7fd4cb4 commit 07d40d2

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
@@ -93,10 +93,72 @@ install_command() {
9393

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

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

0 commit comments

Comments
 (0)