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

Conditionally use Homebrew location for Spin plugins and templates #1494

Merged
merged 3 commits into from
Jun 8, 2023

Conversation

kate-goldenring
Copy link
Contributor

@kate-goldenring kate-goldenring commented May 15, 2023

The current experience for installing spin is to either use the install script or build from source. Users should be able to install Spin using their favorite package manager, such as Homebrew. #641

I am working on creating a fermyon-spin Homebrew formula. Homebrew is sandboxed such that you can only install into a subdirectory of $HOMEBREW_PREFIX (/opt/homebrew on ARM macOs and /usr/local on Intel macOs ). The formula installs default plugins and templates to the $HOMEBREW_PREFIX/etc/fermyon-spin directory.

The plugin and templates systems look at $XDG_DATA_HOME or more specifically $HOME/Library/Application Support for macOS. This updates them to look for the existence of a brew installation of Spin and if exists, use the $HOMEBREW_PREFIX/etc/fermyon-spin directory for plugins and templates.

If a user has a brew installation of spin and another installation or local execution, there could be duplication of plugins and templates, with each executable using their expected directory

@kate-goldenring kate-goldenring marked this pull request as draft May 15, 2023 17:46
@lann
Copy link
Collaborator

lann commented May 15, 2023

I don't know much about homebrew but this doesn't seem right to me. If I install e.g. iTerm from homebrew and spin from source, will spin see HOMEBREW_PREFIX if its run from iTerm?

@kate-goldenring
Copy link
Contributor Author

I don't know much about homebrew but this doesn't seem right to me. If I install e.g. iTerm from homebrew and spin from source, will spin see HOMEBREW_PREFIX if its run from iTerm?

@lann This installs the plugins to $HOMEBREW_PREFIX/var/spin iff both $HOMEBREW_PREFIX exists and $HOMEBREW_PREFIX/var/spin/plugins exists. If only $HOMEBREW_PREFIX exists (which would be the case in the above scenario), it continues with the normal installation path.

crates/plugins/src/store.rs Outdated Show resolved Hide resolved
@lann
Copy link
Collaborator

lann commented May 15, 2023

Ohhh so the formula creates those dirs? I have no opinion then 😅

@kate-goldenring
Copy link
Contributor Author

Ohhh so the formula creates those dirs? I have no opinion then 😅

Yes exactly. In the formula install step, those directories are created:

  def spin_datadir
      var/"spin"
  end
  
  def install
    system "#{Formula["rustup-init"].bin}/rustup-init", "-qy", "--no-modify-path"
    ENV.prepend_path "PATH", HOMEBREW_CACHE/"cargo_cache/bin"
    system "rustup", "target", "add", "wasm32-wasi", "wasm32-unknown-unknown"
    system "cargo", "install", *std_cargo_args

    (spin_datadir/"templates").mkpath
    (spin_datadir/"plugins").mkpath

    system "#{bin}/spin", "templates", "install", "--git", "https://github.com/fermyon/spin", "--upgrade"
    system "#{bin}/spin", "templates", "install", "--git", "https://github.com/fermyon/spin-python-sdk", "--upgrade"
    system "#{bin}/spin", "templates", "install", "--git", "https://github.com/fermyon/spin-js-sdk", "--upgrade"
    system "#{bin}/spin", "plugins", "update"
    system "#{bin}/spin", "plugins", "install", "js2wasm", "--yes"
    system "#{bin}/spin", "plugins", "install", "py2wasm", "--yes"
  end

@tpmccallum
Copy link
Contributor

Issue added to developer documentation repository Re: documenting this work fermyon/developer#612

crates/plugins/src/store.rs Outdated Show resolved Hide resolved
crates/plugins/src/store.rs Outdated Show resolved Hide resolved
… plugins and templates

Checks if Spin was installed with brew package manager and does plugin and template opperations in a directory inside the HOMEBREW_PREFIX directory

Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
@kate-goldenring kate-goldenring merged commit 459ee0e into fermyon:main Jun 8, 2023
@kate-goldenring kate-goldenring deleted the brew branch June 8, 2023 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants