mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-04 03:54:24 +08:00
Use deployment group id instead of name for deploy via CLI
This commit is contained in:
parent
e6d615432d
commit
26eef84503
4 changed files with 47 additions and 34 deletions
|
@ -264,10 +264,14 @@ defmodule Livebook.Teams do
|
|||
@doc """
|
||||
Deploys the given app deployment to given deployment group using a deploy key.
|
||||
"""
|
||||
@spec deploy_app_from_cli(Team.t(), Teams.AppDeployment.t(), String.t()) ::
|
||||
@spec deploy_app_from_cli(Team.t(), Teams.AppDeployment.t(), integer()) ::
|
||||
{:ok, String.t()} | {:error, map()} | {:transport_error, String.t()}
|
||||
def deploy_app_from_cli(%Team{} = team, %Teams.AppDeployment{} = app_deployment, name) do
|
||||
case Requests.deploy_app_from_cli(team, app_deployment, name) do
|
||||
def deploy_app_from_cli(
|
||||
%Team{} = team,
|
||||
%Teams.AppDeployment{} = app_deployment,
|
||||
deployment_group_id
|
||||
) do
|
||||
case Requests.deploy_app_from_cli(team, app_deployment, deployment_group_id) do
|
||||
{:ok, %{"url" => url}} -> {:ok, url}
|
||||
{:error, %{"errors" => errors}} -> {:error, errors}
|
||||
any -> any
|
||||
|
|
|
@ -239,8 +239,8 @@ defmodule Livebook.Teams.Requests do
|
|||
@doc """
|
||||
Send a request to Livebook Team API to deploy an app using a deploy key.
|
||||
"""
|
||||
@spec deploy_app_from_cli(Team.t(), Teams.AppDeployment.t(), String.t()) :: api_result()
|
||||
def deploy_app_from_cli(team, app_deployment, deployment_group_name) do
|
||||
@spec deploy_app_from_cli(Team.t(), Teams.AppDeployment.t(), integer()) :: api_result()
|
||||
def deploy_app_from_cli(team, app_deployment, deployment_group_id) do
|
||||
secret_key = Teams.derive_key(team.teams_key)
|
||||
|
||||
params = %{
|
||||
|
@ -248,7 +248,7 @@ defmodule Livebook.Teams.Requests do
|
|||
slug: app_deployment.slug,
|
||||
multi_session: app_deployment.multi_session,
|
||||
access_type: app_deployment.access_type,
|
||||
deployment_group_name: deployment_group_name,
|
||||
deployment_group_id: deployment_group_id,
|
||||
sha: app_deployment.sha
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ defmodule LivebookCLI.Deploy do
|
|||
|
||||
## Available options
|
||||
|
||||
--deploy-key Deploy key from your Livebook Teams organization
|
||||
--teams-key Teams key from your Teams workspace
|
||||
--deployment-group The deployment group name which you want to deploy to
|
||||
--deploy-key Deploy key from your Livebook Teams organization
|
||||
--teams-key Teams key from your Teams workspace
|
||||
--deployment-group-id The ID of the deployment group you want to deploy to
|
||||
|
||||
The --help option can be given to print this notice.
|
||||
|
||||
|
@ -24,18 +24,18 @@ defmodule LivebookCLI.Deploy do
|
|||
|
||||
Deploys a single notebook:
|
||||
|
||||
livebook deploy --deploy-key="lb_dk_..." --teams-key="lb_tk_..." --deployment-group="production" path/to/app1.livemd
|
||||
livebook deploy --deploy-key="lb_dk_..." --teams-key="lb_tk_..." --deployment-group-id=123 path/to/app1.livemd
|
||||
|
||||
Deploys multiple notebooks:
|
||||
|
||||
livebook deploy --deploy-key="lb_dk_..." --teams-key="lb_tk_..." --deployment-group="production" path/to/*.livemd\
|
||||
livebook deploy --deploy-key="lb_dk_..." --teams-key="lb_tk_..." --deployment-group-id=123 path/to/*.livemd\
|
||||
"""
|
||||
end
|
||||
|
||||
@switches [
|
||||
deploy_key: :string,
|
||||
teams_key: :string,
|
||||
deployment_group: :string
|
||||
deployment_group_id: :integer
|
||||
]
|
||||
|
||||
@impl true
|
||||
|
@ -56,7 +56,7 @@ defmodule LivebookCLI.Deploy do
|
|||
paths: paths,
|
||||
session_token: opts[:deploy_key],
|
||||
teams_key: opts[:teams_key],
|
||||
deployment_group: opts[:deployment_group]
|
||||
deployment_group_id: opts[:deployment_group_id]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -138,7 +138,7 @@ defmodule LivebookCLI.Deploy do
|
|||
|
||||
with {:ok, content} <- File.read(path),
|
||||
{:ok, app_deployment} <- prepare_app_deployment(path, content, files_dir) do
|
||||
case Livebook.Teams.deploy_app_from_cli(team, app_deployment, config.deployment_group) do
|
||||
case Livebook.Teams.deploy_app_from_cli(team, app_deployment, config.deployment_group_id) do
|
||||
{:ok, url} ->
|
||||
log_info([:green, " * #{app_deployment.title} deployed successfully. (#{url})"])
|
||||
|
||||
|
@ -191,7 +191,8 @@ defmodule LivebookCLI.Deploy do
|
|||
defp normalize_key(key) when is_atom(key), do: to_string(key) |> normalize_key()
|
||||
defp normalize_key("session_token"), do: "Deploy Key"
|
||||
defp normalize_key("teams_key"), do: "Teams Key"
|
||||
defp normalize_key("deployment_group"), do: "Deployment Group"
|
||||
defp normalize_key("deployment_group_id"), do: "Deployment Group ID"
|
||||
|
||||
defp normalize_key("paths"), do: "File Paths"
|
||||
|
||||
defp format_errors(errors, prefix) do
|
||||
|
|
|
@ -43,7 +43,7 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
assert deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
app_path
|
||||
) == :ok
|
||||
end)
|
||||
|
@ -92,7 +92,7 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
assert deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
Path.join(tmp_dir, "*.livemd")
|
||||
) == :ok
|
||||
end)
|
||||
|
@ -127,7 +127,7 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
deploy(
|
||||
"invalid_key",
|
||||
team.teams_key,
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
app_path
|
||||
)
|
||||
end
|
||||
|
@ -149,7 +149,7 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
deploy(
|
||||
key,
|
||||
"invalid-key",
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
app_path
|
||||
)
|
||||
end
|
||||
|
@ -167,14 +167,16 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
# Test App
|
||||
""")
|
||||
|
||||
assert_raise LivebookCLI.Error, ~r/Deployment Group can't be blank/s, fn ->
|
||||
deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
"",
|
||||
app_path
|
||||
)
|
||||
end
|
||||
assert_raise OptionParser.ParseError,
|
||||
~r/--deployment-group-id : Expected type integer, got ""/s,
|
||||
fn ->
|
||||
deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
"",
|
||||
app_path
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
test "fails with invalid deployment group",
|
||||
|
@ -199,12 +201,12 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
```
|
||||
""")
|
||||
|
||||
assert_raise LivebookCLI.Error, ~r/Deployment Group does not exist/s, fn ->
|
||||
assert_raise LivebookCLI.Error, ~r/Deployment Group ID does not exist/s, fn ->
|
||||
ExUnit.CaptureIO.capture_io(fn ->
|
||||
deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
Utils.random_short_id(),
|
||||
999_999,
|
||||
app_path
|
||||
)
|
||||
end)
|
||||
|
@ -228,7 +230,7 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
Path.join(tmp_dir, "app.livemd")
|
||||
)
|
||||
end
|
||||
|
@ -242,14 +244,14 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
deploy(
|
||||
key,
|
||||
team.teams_key,
|
||||
deployment_group.name,
|
||||
deployment_group.id,
|
||||
tmp_dir
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp deploy(deploy_key, teams_key, deployment_group_name, path) do
|
||||
defp deploy(deploy_key, teams_key, deployment_group_id, path) do
|
||||
paths =
|
||||
case Path.wildcard(path) do
|
||||
[] -> [path]
|
||||
|
@ -257,14 +259,20 @@ defmodule LivebookCLI.Integration.DeployTest do
|
|||
paths -> paths
|
||||
end
|
||||
|
||||
deployment_group_id =
|
||||
cond do
|
||||
deployment_group_id == "" -> ""
|
||||
true -> Integer.to_string(deployment_group_id)
|
||||
end
|
||||
|
||||
LivebookCLI.Deploy.call(
|
||||
[
|
||||
"--deploy-key",
|
||||
deploy_key,
|
||||
"--teams-key",
|
||||
teams_key,
|
||||
"--deployment-group",
|
||||
deployment_group_name
|
||||
"--deployment-group-id",
|
||||
deployment_group_id
|
||||
] ++ paths
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue