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

Track homebrew's state inside bluefin-cli #768

Closed
castrojo opened this issue Dec 31, 2023 · 5 comments
Closed

Track homebrew's state inside bluefin-cli #768

castrojo opened this issue Dec 31, 2023 · 5 comments
Labels
dx Developer Experience Image specific

Comments

@castrojo
Copy link
Member

It'd be nice to destroy and assemble the bluefin-cli container without losing all the packages I've installed inside. Jeefy has an idea on how to do this.

@castrojo castrojo added the dx Developer Experience Image specific label Dec 31, 2023
@jeefy
Copy link
Contributor

jeefy commented Dec 31, 2023

We CANNOT use $USER and must use explicit naming. For this, it's jeefy and we're using wolfi distrobox

  • On first boot we make a folder named /home/jeefy/.homebrew
  • On first boot we create a file (/etc/homebrew/brew.env) upon first-boot that contains the following:
HOMEBREW_PREFIX=/home/jeefy/.homebrew
HOMEBREW_REPOSITORY=/home/jeefy/.homebrew

From then on, any brew command will reference/install/use the mounted user's home directory. Example output after doing that and running brew install go

📦[jeefy@bluefin ~]$ brew config
HOMEBREW_VERSION: >=4.1.0 (shallow or no git repository)
...
HOMEBREW_PREFIX: /home/jeefy/.homebrew
HOMEBREW_REPOSITORY: /home/jeefy/.homebrew
HOMEBREW_CELLAR: /home/jeefy/.homebrew/Cellar
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :1
HOMEBREW_EDITOR: /usr/bin/nano
HOMEBREW_MAKE_JOBS: 16
HOMEBREW_NO_AUTO_UPDATE: set
Homebrew Ruby: 3.1.4 => /usr/bin/ruby
...
📦[jeefy@bluefin ~]$ brew ls
go
📦[jeefy@bluefin ~]$

In #745 I add a on-start script just for the DX Bluefin variant, and I'd suggest putting another on-start script in to handle this.

@m2Giles
Copy link
Member

m2Giles commented Jan 3, 2024

I think we could use Distrobox's ability to mount volumes at specified locations.

If the workflow for creating this container is going to happen via assemble file (or just command), we could make .homebrew inside the user's home folder via skel and then mount that to /home/linuxbrew/.linuxbrew.

@jeefy
Copy link
Contributor

jeefy commented Jan 3, 2024

That's another decent approach! My one nit on that is it's (essentially) double-mounting the same folder. If we had to trick brew, that's the approach I'd go, but this is something we can configure instead.

@m2Giles
Copy link
Member

m2Giles commented Jan 4, 2024

I've been trying to use the brew.env and it seems to pull in a ton of additional packages compared to using the default /home/linuxbrew/.linuxbrew. Additionally, it wants to compile basically everything locally as well. This also seems to fail quite a bit. This was a pretty off experience for me and I think its due to the fact that we are missing most of the brew preinstalled scripts /home/linuxbrew/.linuxbrew.

Everything seems to be in the Cellar. Having just that be linked into the /home/linuxbrew/.linuxbrew will have every package tracked. But they are unlinked when recreating the container. Manually relinking them sorta works, but somethings will require a reinstall (but it's already on disk so it's relatively fast).

But basically, on container enter. Make symlink between $HOME/.homebrew/Cellar and /home/linuxbrew/.linuxbrew. Relink if necessary. Reinstall if necessary. The making a symlink can be done from bash_profile or whatnot. The relink could have a convenience script on the container. The reinstall I have no idea how to catch.

And symlinks are not recommended for Cellar. It needs to be an actual Directory. So I'm back to volume mounting just the Cellar now.

m2Giles added a commit to m2Giles/bluefin that referenced this issue Jan 4, 2024
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.
m2Giles added a commit to m2Giles/bluefin that referenced this issue Jan 4, 2024
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.
m2Giles added a commit to m2Giles/bluefin that referenced this issue Jan 4, 2024
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.
m2Giles added a commit to m2Giles/bluefin that referenced this issue Jan 5, 2024
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.

When using just bluefin-cli, it will relink all packages and reinstall explicitly installed packages.
@m2Giles
Copy link
Member

m2Giles commented Jan 22, 2024

This is now complete and works with no additional arguments during container creation.

@m2Giles m2Giles closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Developer Experience Image specific
Projects
None yet
Development

No branches or pull requests

3 participants