Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: improve Dockerfile to make proper use of build cache #17584

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ ARG version=22.04
FROM ubuntu:"${version}"
ARG DEBIAN_FRONTEND=noninteractive

# Set the user ID to the default value of 1001 since different ubuntu
# versions yield to different user IDs with `useradd`
ENV USER_ID=1001

# We don't want to manually pin versions, happy to use whatever
# Ubuntu thinks is best.
# hadolint ignore=DL3008
Expand Down Expand Up @@ -48,7 +52,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i -E 's/^(USERGROUPS_ENAB\s+)yes$/\1no/' /etc/login.defs \
&& localedef -i en_US -f UTF-8 en_US.UTF-8 \
&& useradd --create-home --shell /bin/bash --user-group linuxbrew \
&& useradd -u "${USER_ID}" --create-home --shell /bin/bash --user-group linuxbrew \
&& echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers \
&& su - linuxbrew -c 'mkdir ~/.linuxbrew'

Expand All @@ -58,7 +62,17 @@ ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}
XDG_CACHE_HOME=/home/linuxbrew/.cache
WORKDIR /home/linuxbrew

RUN mkdir -p \

RUN --mount=type=cache,target=/tmp/homebrew-core,uid="${USER_ID}",sharing=locked \
# Clone the homebre-core repo into /tmp/homebrew-core or pull latest changes if it exists
marcosnils marked this conversation as resolved.
Show resolved Hide resolved
git clone https://github.com/homebrew/homebrew-core /tmp/homebrew-core || { cd /tmp/homebrew-core && git pull; } \
&& mkdir -p /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core \
&& cp -r /tmp/homebrew-core /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/


RUN --mount=type=cache,target=/home/linuxbrew/.cache,uid="${USER_ID}" \
--mount=type=cache,target=/home/linuxbrew/.bundle,uid="${USER_ID}" \
mkdir -p \
.linuxbrew/bin \
.linuxbrew/etc \
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
.linuxbrew/include \
Expand All @@ -76,5 +90,4 @@ RUN mkdir -p \
&& brew cleanup \
&& { git -C .linuxbrew/Homebrew config --unset gc.auto; true; } \
&& { git -C .linuxbrew/Homebrew config --unset homebrew.devcmdrun; true; } \
&& rm -rf .cache \
marcosnils marked this conversation as resolved.
Show resolved Hide resolved
&& touch .linuxbrew/.homebrewdocker