Skip to content

Commit

Permalink
Adjustment of deployment status updates.
Browse files Browse the repository at this point in the history
Signed-off-by: EdmondFrank <edmondfrank@hotmail.com>
  • Loading branch information
EdmondFrank committed Jul 2, 2024
1 parent 2c4ce78 commit be5b667
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lib/compass_admin/agents/backend_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ defmodule CompassAdmin.Agents.BackendAgent do
{:update_deploy_state, :processing, trigger_id, {:ok, "processing"}}
)

do_deployment()
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:ok, :success}})
do_deployment(trigger_id)
end)

new_state = %{
Expand Down Expand Up @@ -119,15 +118,22 @@ defmodule CompassAdmin.Agents.BackendAgent do
{:noreply, state}
end

defp do_deployment() do
defp do_deployment(trigger_id) do
[input: input, execute: execute] = Application.fetch_env!(:compass_admin, __MODULE__)

Exile.stream(["bash", "-l", "-c", execute], input: input, stderr: :consume)
|> Stream.each(fn stream ->
case stream do
{:stdout, data} -> log(data)
{:stderr, msg} -> log(msg)
{:exit, {:status, code}} -> log("exit with status: #{code}")
{:exit, {:status, code}} ->
msg = "exit with status: #{code}"
log(msg)
if code != 0 do
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:error, msg}})
else
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:ok, :success}})
end
end
end)
|> Stream.run()
Expand Down
14 changes: 10 additions & 4 deletions lib/compass_admin/agents/frontend_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ defmodule CompassAdmin.Agents.FrontendAgent do
{:update_deploy_state, :processing, trigger_id, {:ok, "processing"}}
)

do_deployment()
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:ok, :success}})
do_deployment(trigger_id)
end)

new_state = %{
Expand Down Expand Up @@ -119,15 +118,22 @@ defmodule CompassAdmin.Agents.FrontendAgent do
{:noreply, state}
end

defp do_deployment() do
defp do_deployment(trigger_id) do
[input: input, execute: execute] = Application.fetch_env!(:compass_admin, __MODULE__)

Exile.stream(["bash", "-l", "-c", execute], input: input, stderr: :consume)
|> Stream.each(fn stream ->
case stream do
{:stdout, data} -> log(data)
{:stderr, msg} -> log(msg)
{:exit, {:status, code}} -> log("exit with status: #{code}")
{:exit, {:status, code}} ->
msg = "exit with status: #{code}"
log(msg)
if code != 0 do
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:error, msg}})
else
GenServer.cast(__MODULE__, {:update_deploy_state, :ok, trigger_id, {:ok, :success}})
end
end
end)
|> Stream.run()
Expand Down
2 changes: 1 addition & 1 deletion lib/compass_admin_web/components/deployment_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule CompassAdminWeb.Components.DeploymentPage do
</.alert>
<div class="grid grid-cols-3 gap-4">
<div class="col-span-2 bg-white shadow-md rounded-lg p-4 max-h-screen">
<h2 class="text-xl pb-2">Backend recent deployment logs</h2>
<h2 class="text-xl pb-2"><%= @title %></h2>
<div class="overflow-auto h-4/5">
<ul>
<%= for log <- Enum.reverse(@agent_state.logs) do %>
Expand Down
2 changes: 2 additions & 0 deletions lib/compass_admin_web/live/backend_deployment_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule CompassAdminWeb.BackendDeploymentLive do

{:ok,
assign(socket,
title: "Backend recent deployment logs",
agent_state: state,
can_deploy: can_deploy,
current_user: current_user,
Expand Down Expand Up @@ -73,6 +74,7 @@ defmodule CompassAdminWeb.BackendDeploymentLive do
def render(assigns) do
~H"""
<.deployment_page
title={@title}
agent_state={@agent_state}
last_trigger={@last_trigger}
last_deployer={@last_deployer}
Expand Down
2 changes: 2 additions & 0 deletions lib/compass_admin_web/live/frontend_deployment_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule CompassAdminWeb.FrontendDeploymentLive do

{:ok,
assign(socket,
title: "Frontend recent deployment logs",
agent_state: state,
can_deploy: can_deploy,
current_user: current_user,
Expand Down Expand Up @@ -73,6 +74,7 @@ defmodule CompassAdminWeb.FrontendDeploymentLive do
def render(assigns) do
~H"""
<.deployment_page
title={@title}
agent_state={@agent_state}
last_trigger={@last_trigger}
last_deployer={@last_deployer}
Expand Down

0 comments on commit be5b667

Please sign in to comment.