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

feature request: support brew link --overwrite #1062

Closed
tekumara opened this issue Feb 19, 2022 · 7 comments · May be fixed by #1455
Closed

feature request: support brew link --overwrite #1062

tekumara opened this issue Feb 19, 2022 · 7 comments · May be fixed by #1455

Comments

@tekumara
Copy link

To handle cases like:

Using kubernetes-cli
Linking kubernetes-cli formula.
Linking /usr/local/Cellar/kubernetes-cli/1.23.4...
Error: Could not symlink bin/kubectl
Target /usr/local/bin/kubectl
already exists. You may want to remove it:
  rm '/usr/local/bin/kubectl'

To force the link and overwrite all conflicting files:
  brew link --overwrite kubernetes-cli

To list all files that would be deleted:
  brew link --overwrite --dry-run kubernetes-cli
@MikeMcQuaid
Copy link
Member

link --force is supported (

Bundle.system(HOMEBREW_BREW_FILE, "link", "--force", @name, verbose: verbose)
). link --overwrite seems a bit dangerous to support in a DSL like this.

@tekumara
Copy link
Author

Thanks @MikeMcQuaid for taking a look at this.

I've tried --force but it produces the same error.

Our problem is that our brewfile includes:

cask docker
brew "kubernetes-cli"
brew "kubectx"

Docker installs an older version of kubectl to /Applications/Docker.app/Contents/Resources/bin/kubectl and links it to /usr/local/bin/kubectl. But we need kubernetes-cli as a depedency of kubectx, and also because it's newer than the Docker version.

It is possible to wrap the Brewfile in a bash script that does the overwrite, eg:

# install packages in Brewfile
brew bundle install --verbose --no-lock

# overwrite docker's kubectl because kubernetes-cli is newer
brew link --overwrite kubernetes-cli

But it would be more convenient if we could do the overwrite within the Brewfile.

@MikeMcQuaid
Copy link
Member

@tekumara Yeh, I think you've convinced me here. Reopening and I'll review a PR for this.

@MikeMcQuaid MikeMcQuaid reopened this Feb 22, 2022
tekumara added a commit to tekumara/setup that referenced this issue Mar 14, 2022
Docker installs kubectl to /Applications/Docker.app/Contents/Resources/bin/kubectl and links it to /usr/local/bin/kubectl.
But it's an older version than kubernetes-cli.

When running `setup upgrade` a newer version of Docker will overwrite kubernetes-cli. The next time `setup upgrade` runs and there's a newer version of kubernetes-cli it will show the error:

```
Linking /usr/local/Cellar/kubernetes-cli/1.23.4...
Error: Could not symlink bin/kubectl
Target /usr/local/bin/kubectl
already exists. You may want to remove it:
  rm '/usr/local/bin/kubectl'

To force the link and overwrite all conflicting files:
  brew link --overwrite kubernetes-cli

To list all files that would be deleted:
  brew link --overwrite --dry-run kubernetes-cli
```

This PR adds  `brew link --overwrite --dry-run kubernetes-cli` to the install script so we never have the Docker version of kubectl installed (and therefore don't get the error above) and always have the latest version of kubectl.

Ideally this would be possible in the Brewfile itself, see Homebrew/homebrew-bundle#1062
@maxromanovsky
Copy link

Nube question: after the issue is closed, would it be possible to apply this behaviour by default? E.g.:

brew_args link:overwrite

@MikeMcQuaid
Copy link
Member

would it be possible to apply this behaviour by default?

No, sorry.

@lygstate
Copy link

lygstate commented Nov 9, 2022

seems related

https://github.com/Mesa3D/mesa/actions/runs/3425503489/jobs/5706360682

How to getting github actions more reliable

@MikeMcQuaid
Copy link
Member

brew bundle --force can be used to accomplish this now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants