Tell users to install kubectl if missing (#2791)

Co-authored-by: José Valim <jose.valim@dashbit.co>
This commit is contained in:
Jonatan Kłosko 2024-09-20 12:19:10 +02:00 committed by GitHub
parent ea6331f324
commit a2ecd117b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 2 deletions

View file

@ -421,6 +421,14 @@ defmodule Livebook.Config do
"""
def app_version(), do: @app_version
@app? Mix.target() == :app
@doc """
Returns whether running at the desktop app.
"""
@spec app?() :: boolean()
def app?(), do: @app?
@doc """
Returns the GitHub org/repo where the releases are created.
"""

View file

@ -87,6 +87,10 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
def render(assigns) do
~H"""
<div>
<div :if={warning = kubectl_warning()} class="mb-2">
<.message_box kind={:warning} message={warning} />
</div>
<p class="text-gray-700">
Start a temporary Kubernetes Pod with an Elixir node to evaluate code.
The Pod is automatically deleted, once you disconnect the runtime.
@ -777,4 +781,35 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
pod_template: socket.assigns.pod_template.template
}
end
defp kubectl_warning() do
if System.find_executable("kubectl") == nil || true do
warning = "Could not find kubectl in PATH. Make sure to install it and add it to PATH."
if Livebook.Config.app?() || true do
windows? = match?({:win32, _}, :os.type())
{path, command} =
if windows? do
path = "#{System.get_env("USERPROFILE", "%USERPROFILE%")}\\.livebookdesktop.bat"
command = ~s|set "PATH=C:\\path\\to\\dir\\;%PATH%"|
{path, command}
else
path = "#{System.get_env("HOME", "$HOME")}/.livebookdesktop.sh"
command = ~s|export PATH="/path/to/dir:$PATH"|
{path, command}
end
"""
#{warning}
For Livebook Desktop, this can be done by creating a file at #{path} with:
#{command}
"""
else
warning
end
end
end
end

View file

@ -8,7 +8,6 @@ set RELEASE_DISTRIBUTION=none
set MIX_ARCHIVES=!RELEASE_ROOT!\vendor\archives
set MIX_REBAR3=!RELEASE_ROOT!\vendor\rebar3
if not defined LIVEBOOK_SHUTDOWN_ENABLED set LIVEBOOK_SHUTDOWN_ENABLED=true
set LIVEBOOK_DESKTOP=true
if not defined LIVEBOOK_PORT (set LIVEBOOK_PORT=0)
set PATH=!RELEASE_ROOT!\vendor\otp\erts-<%= @release.erts_version%>\bin;!RELEASE_ROOT!\vendor\otp\bin;!RELEASE_ROOT!\vendor\elixir\bin;!PATH!

View file

@ -8,7 +8,6 @@ export RELEASE_DISTRIBUTION="none"
export MIX_ARCHIVES="${RELEASE_ROOT}/vendor/archives"
export MIX_REBAR3="${RELEASE_ROOT}/vendor/rebar3"
export LIVEBOOK_SHUTDOWN_ENABLED=${LIVEBOOK_SHUTDOWN_ENABLED:-true}
export LIVEBOOK_DESKTOP=true
[ -z "$LIVEBOOK_PORT" ] && export LIVEBOOK_PORT=0
export PATH="$RELEASE_ROOT/vendor/otp/erts-<%= @release.erts_version%>/bin:$RELEASE_ROOT/vendor/otp/bin:$RELEASE_ROOT/vendor/elixir/bin:$PATH"