Skip to content

Commit

Permalink
feat(bluefin-cli): Persist State of Cellar
Browse files Browse the repository at this point in the history
Persist the state of Homebrew's Cellar for ublue-os#768

If the Cellar does not exist. It will be created in the User's home directory. It is then volume mounted into the container making it accessible on any distrobox enter for the container.

This also uses the brew_pkgs as a brewfile and brew_script to install/reinstall packages. The brew_script will first try to relink everything in the Cellar. However, just because an item is relink, doesn't mean it will be able to run necessitating a reinstall. Fortunately, any specified reinstalls seem to be quick.
  • Loading branch information
m2Giles committed Jan 4, 2024
1 parent 895aee9 commit a7d3f81
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
17 changes: 11 additions & 6 deletions just/custom.just
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ aqua:

[private]
bluefin-cli:
#!/usr/bin/env bash
if [ ! -f "${HOME}/.brew_pkgs" ]; then
echo dysk > "${HOME}/.brew_pkgs"
fi;
distrobox-create --nvidia --image ghcr.io/ublue-os/bluefin-cli:latest -n bluefin -Y -a "--env BREW_PKGS=.brew_pkgs"
echo "Entering bluefin-cli"
#!/usr/bin/env bash
if [ ! -f "${HOME}/.brew_pkgs" ]; then
echo dysk > "${HOME}/.brew_pkgs"
fi;
if [ ! -d "${HOME}/.homebrew/Cellar" ]; then
mkdir -p "${HOME}/.homebrew/Cellar"
fi;
distrobox-create --nvidia --image localhost/bluefin-cli:latest -n bluefin -Y -a "--env BREW_PKGS=.brew_pkgs" --volume "${HOME}/.homebrew/Cellar":/home/linuxbrew/.linuxbrew/Cellar
echo "Setting up bluefin-cli"
distrobox enter bluefin -- brew_script
echo "Entering bluefin-cli"
distrobox enter bluefin

# Enable Cockpit for web-based system management | https://cockpit-project.org/
Expand Down
6 changes: 5 additions & 1 deletion toolboxes/Containerfile.bluefin-cli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LABEL com.github.containers.toolbox="true" \

COPY ./toolboxes/packages.bluefin-cli /toolbox-packages

# Install brew_script
COPY ./toolboxes/brew_script.bluefin-cli /tmp/brew_script
RUN install -Dm755 /tmp/brew_script /usr/bin/brew_script

# Update image
RUN apk update && \
apk upgrade
Expand Down Expand Up @@ -36,7 +40,7 @@ COPY ./toolboxes/files.bluefin-cli/etc/sudoers /etc/sudoers
COPY ./toolboxes/files.bluefin-cli/etc/pam.d /etc/pam.d

# Have Linuxbrew owned by UID = 1000
RUN chown -R 1000 /home/linuxbrew/.linuxbrew /home/linuxbrew/.linuxbrew/bin
RUN chown -R 1000 /home/linuxbrew

# Change root shell to BASH

Expand Down
19 changes: 17 additions & 2 deletions toolboxes/brew_script.bluefin-cli
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/usr/bin/env bash
if [ ! -f /home/linuxbrew/.firstrun ] && [ -n "${BREW_PKGS}" ]; then
touch /home/linuxbrew/.firstrun

# `brew update-reset` is currently needed
# because somekind of issue with brew
brew update-reset
xargs brew install < "${HOME}"/"${BREW_PKGS}"
# /home/linuxbrew/.linuxbrew/bin/brew update-reset

# Package Install/Reinstall/Relink
if [ -n "$(ls -A /home/linuxbrew/.linuxbrew/Cellar)" ]; then
echo "Relinking packages. You may still need to reinstall binaries to run them"
/home/linuxbrew/.linuxbrew/bin/brew list -1 | while read line
do
/home/linuxbrew/.linuxbrew/bin/brew unlink $line
/home/linuxbrew/.linuxbrew/bin/brew link $line
done
echo "Reinstalling Packages from brewfile ${HOME}/${BREW_PKGS}"
xargs /home/linuxbrew/.linuxbrew/bin/brew reinstall < "${HOME}"/"${BREW_PKGS}"
else
echo "Installing Packages from brewfile ${HOME}/${BREW_PKGS}"
xargs /home/linuxbrew/.linuxbrew/bin/brew install < "${HOME}"/"${BREW_PKGS}"
fi
fi

0 comments on commit a7d3f81

Please sign in to comment.