Skip to content

Commit 3039318

Browse files
authored
feat: install Homebrew in github-runner-ci image (#791)
## Summary - install Homebrew into the github-runner-ci image under `/home/linuxbrew/.linuxbrew` - keep the installation owned by the `runner` user so job containers can install packages at runtime - extend the image workflow test to run `brew install hello` and execute `hello --version` ## Validation - `devcontainer exec --workspace-folder . just check-format` - `devcontainer exec --workspace-folder . shellcheck images/github-runner-ci/build_files/build.sh images/github-runner-ci/build_files/create-runner-user.sh images/github-runner-ci/build_files/packages.sh images/github-runner-ci/build_files/packages/homebrew.sh` - `devcontainer exec --workspace-folder . hadolint images/github-runner-ci/Containerfile` - `docker build --progress=plain -t github-runner-ci:brew-review -f images/github-runner-ci/Containerfile images/github-runner-ci` - `docker run --rm github-runner-ci:brew-review bash -lc 'set -euo pipefail; test "$(id -u):$(id -g)" = "1001:1001"; test "$HOME" = "/home/runner"; brew --version; brew install hello; brew list --versions hello; hello --version'`
1 parent 8c7b62c commit 3039318

6 files changed

Lines changed: 75 additions & 7 deletions

File tree

.github/workflows/image-github-runner-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
test -w "$HOME/.local"
8282
test -w "$HOME/.local/bin"
8383
test -w "$HOME/.local/share"
84+
brew --version
8485
git --version
8586
just --version
8687
jq --version
@@ -127,6 +128,11 @@ jobs:
127128
test -w "${GITHUB_WORKSPACE}"
128129
test -w "${RUNNER_TEMP}"
129130
131+
brew --version
132+
brew install hello
133+
brew list --versions hello
134+
hello --version
135+
130136
touch "${GITHUB_WORKSPACE}/.github-runner-ci-write-test"
131137
rm "${GITHUB_WORKSPACE}/.github-runner-ci-write-test"
132138
printf 'github-runner-ci job container test\n' > "${RUNNER_TEMP}/github-runner-ci.txt"

images/github-runner-ci/Containerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ ARG RUNNER_USER=runner
1313
ARG RUNNER_UID=1001
1414
ARG RUNNER_GID=1001
1515

16+
RUN --mount=type=bind,from=ctx,source=/,target=/ctx \
17+
/ctx/create-runner-user.sh
18+
1619
RUN --mount=type=cache,dst=/var/cache \
1720
--mount=type=cache,dst=/var/log \
1821
--mount=type=tmpfs,dst=/tmp \
1922
--mount=type=bind,from=ctx,source=/,target=/ctx \
2023
/ctx/build.sh
2124

22-
RUN --mount=type=bind,from=ctx,source=/,target=/ctx \
23-
/ctx/create-runner-user.sh
24-
2525
ENV HOME="/home/${RUNNER_USER}" \
26+
HOMEBREW_CELLAR="/home/linuxbrew/.linuxbrew/Cellar" \
27+
HOMEBREW_NO_ANALYTICS="1" \
28+
HOMEBREW_NO_AUTO_UPDATE="1" \
29+
HOMEBREW_NO_ENV_HINTS="1" \
30+
HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew" \
31+
HOMEBREW_REPOSITORY="/home/linuxbrew/.linuxbrew/Homebrew" \
32+
LOGNAME="${RUNNER_USER}" \
33+
PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}" \
34+
USER="${RUNNER_USER}" \
2635
XDG_CACHE_HOME="/home/${RUNNER_USER}/.cache" \
2736
XDG_CONFIG_HOME="/home/${RUNNER_USER}/.config" \
2837
XDG_DATA_HOME="/home/${RUNNER_USER}/.local/share"

images/github-runner-ci/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ This image is intended for GitHub Actions job containers running on ARC
44
`kubernetes-novolume` runners.
55

66
It inherits from `ghcr.io/marinatedconcrete/devcontainer-base`, installs a small
7-
set of common shell/system tools, and runs as `runner` with UID/GID `1001:1001`
8-
so job containers match the ownership of the ARC runner workspace. The default
9-
home directory is `/home/runner`, and it is writable by that user.
7+
set of common shell/system tools plus Homebrew, and runs as `runner` with
8+
UID/GID `1001:1001` so job containers match the ownership of the ARC runner
9+
workspace. The default home directory is `/home/runner`, and it is writable by
10+
that user.
1011

1112
Language runtimes and domain-specific tools such as Node.js, Python, the GitHub
1213
CLI, Kubernetes tooling, and container-specific linters are intentionally left
13-
for downstream CI images or workflows to choose.
14+
for downstream CI images or workflows to choose. Workflows can use `brew` to
15+
install additional packages at job runtime.

images/github-runner-ci/build_files/create-runner-user.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ useradd \
1818
install -d \
1919
--owner "${RUNNER_USER}" \
2020
--group "${RUNNER_USER}" \
21+
"/home/linuxbrew" \
2122
"/home/${RUNNER_USER}/.cache" \
2223
"/home/${RUNNER_USER}/.config" \
2324
"/home/${RUNNER_USER}/.local" \

images/github-runner-ci/build_files/packages.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ set -eoux pipefail
55
# The small set of broadly useful shell/system tools for CI job containers.
66
PACKAGES=(
77
"bash"
8+
"bubblewrap"
89
"ca-certificates"
10+
"file"
911
"findutils"
1012
"jq"
13+
"procps-ng"
1114
"ripgrep"
1215
"shadow-utils"
1316
"ShellCheck"
@@ -18,7 +21,14 @@ PACKAGES=(
1821
)
1922

2023
dnf upgrade -y
24+
25+
# Homebrew-on-Linux needs a build toolchain for formulae that compile from source.
26+
dnf group install \
27+
-y \
28+
development-tools
2129
dnf install \
2230
--setopt=install_weak_deps=False \
2331
-y \
2432
"${PACKAGES[@]}"
33+
34+
/ctx/packages/homebrew.sh
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
RUNNER_USER="${RUNNER_USER:-runner}"
6+
HOMEBREW_PREFIX="${HOMEBREW_PREFIX:-/home/linuxbrew/.linuxbrew}"
7+
HOMEBREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
8+
9+
if [[ "$(id -u)" -eq 0 ]]; then
10+
exec runuser -u "${RUNNER_USER}" -- env \
11+
HOME="/home/${RUNNER_USER}" \
12+
HOMEBREW_CELLAR="${HOMEBREW_PREFIX}/Cellar" \
13+
HOMEBREW_NO_ANALYTICS="1" \
14+
HOMEBREW_NO_AUTO_UPDATE="1" \
15+
HOMEBREW_NO_ENV_HINTS="1" \
16+
HOMEBREW_PREFIX="${HOMEBREW_PREFIX}" \
17+
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew" \
18+
LOGNAME="${RUNNER_USER}" \
19+
PATH="${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:${PATH}" \
20+
USER="${RUNNER_USER}" \
21+
"$0"
22+
fi
23+
24+
installer="$(mktemp --tmpdir homebrew-install.XXXXXX.sh)"
25+
26+
curl \
27+
--fail \
28+
--location \
29+
--show-error \
30+
--silent \
31+
"${HOMEBREW_INSTALL_URL}" \
32+
--output "${installer}"
33+
chmod 0755 "${installer}"
34+
35+
CI=1 NONINTERACTIVE=1 /bin/bash "${installer}"
36+
37+
cd "${HOME}"
38+
39+
"${HOMEBREW_PREFIX}/bin/brew" analytics off
40+
"${HOMEBREW_PREFIX}/bin/brew" --version

0 commit comments

Comments
 (0)