Skip to content

Commit

Permalink
Tell users to install kubectl if missing (#2791)
Browse files Browse the repository at this point in the history
Co-authored-by: José Valim <[email protected]>
  • Loading branch information
jonatanklosko and josevalim authored Sep 20, 2024
1 parent ea6331f commit a2ecd11
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/livebook/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
35 changes: 35 additions & 0 deletions lib/livebook_web/live/session_live/k8s_runtime_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion rel/app/env.bat.eex
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
1 change: 0 additions & 1 deletion rel/app/env.sh.eex
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit a2ecd11

Please sign in to comment.