Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

server: build out deployment views

+51 -111
+2 -1
apps/sower/lib/sower/orchestration.ex
··· 324 324 325 325 """ 326 326 def list_deployments do 327 - Repo.all(Deployment) 327 + query = from r in Deployment, order_by: [desc: r.inserted_at] 328 + Repo.all(query) 328 329 end 329 330 330 331 @doc """
+8
apps/sower/lib/sower_web/components/layouts.ex
··· 60 60 Forges 61 61 </.link> 62 62 </li> 63 + <li> 64 + <.link 65 + navigate={~p"/deployments"} 66 + class="hover:text-orange-700 dark:hover:text-orange-300" 67 + > 68 + Deployments 69 + </.link> 70 + </li> 63 71 </ul> 64 72 </div> 65 73
-95
apps/sower/lib/sower_web/live/deployment_live/form.ex
··· 1 - defmodule SowerWeb.DeploymentLive.Form do 2 - use SowerWeb, :live_view 3 - 4 - alias Sower.Orchestration 5 - alias Sower.Orchestration.Deployment 6 - 7 - @impl true 8 - def render(assigns) do 9 - ~H""" 10 - <Layouts.app flash={@flash} current_user={@current_user}> 11 - <.header> 12 - {@page_title} 13 - <:subtitle>Use this form to manage deployment records in your database.</:subtitle> 14 - </.header> 15 - 16 - <.form for={@form} id="deployment-form" phx-change="validate" phx-submit="save"> 17 - <.input field={@form[:seed_name]} type="text" label="Seed name" /> 18 - <.input field={@form[:seed_type]} type="text" label="Seed type" /> 19 - <footer> 20 - <.button phx-disable-with="Saving..." variant="primary">Save Deployment</.button> 21 - <.button navigate={return_path(@return_to, @deployment)}>Cancel</.button> 22 - </footer> 23 - </.form> 24 - </Layouts.app> 25 - """ 26 - end 27 - 28 - @impl true 29 - def mount(params, _session, socket) do 30 - {:ok, 31 - socket 32 - |> assign(:return_to, return_to(params["return_to"])) 33 - |> apply_action(socket.assigns.live_action, params)} 34 - end 35 - 36 - defp return_to("show"), do: "show" 37 - defp return_to(_), do: "index" 38 - 39 - defp apply_action(socket, :edit, %{"id" => id}) do 40 - deployment = Orchestration.get_deployment!(id) 41 - 42 - socket 43 - |> assign(:page_title, "Edit Deployment") 44 - |> assign(:deployment, deployment) 45 - |> assign(:form, to_form(Orchestration.change_deployment(deployment))) 46 - end 47 - 48 - defp apply_action(socket, :new, _params) do 49 - deployment = %Deployment{} 50 - 51 - socket 52 - |> assign(:page_title, "New Deployment") 53 - |> assign(:deployment, deployment) 54 - |> assign(:form, to_form(Orchestration.change_deployment(deployment))) 55 - end 56 - 57 - @impl true 58 - def handle_event("validate", %{"deployment" => deployment_params}, socket) do 59 - changeset = Orchestration.change_deployment(socket.assigns.deployment, deployment_params) 60 - {:noreply, assign(socket, form: to_form(changeset, action: :validate))} 61 - end 62 - 63 - def handle_event("save", %{"deployment" => deployment_params}, socket) do 64 - save_deployment(socket, socket.assigns.live_action, deployment_params) 65 - end 66 - 67 - defp save_deployment(socket, :edit, deployment_params) do 68 - case Orchestration.update_deployment(socket.assigns.deployment, deployment_params) do 69 - {:ok, deployment} -> 70 - {:noreply, 71 - socket 72 - |> put_flash(:info, "Deployment updated successfully") 73 - |> push_navigate(to: return_path(socket.assigns.return_to, deployment))} 74 - 75 - {:error, %Ecto.Changeset{} = changeset} -> 76 - {:noreply, assign(socket, form: to_form(changeset))} 77 - end 78 - end 79 - 80 - defp save_deployment(socket, :new, deployment_params) do 81 - case Orchestration.create_deployment(deployment_params) do 82 - {:ok, deployment} -> 83 - {:noreply, 84 - socket 85 - |> put_flash(:info, "Deployment created successfully") 86 - |> push_navigate(to: return_path(socket.assigns.return_to, deployment))} 87 - 88 - {:error, %Ecto.Changeset{} = changeset} -> 89 - {:noreply, assign(socket, form: to_form(changeset))} 90 - end 91 - end 92 - 93 - defp return_path("index", _deployment), do: ~p"/deployments" 94 - defp return_path("show", deployment), do: ~p"/deployments/#{deployment}" 95 - end
+4 -6
apps/sower/lib/sower_web/live/deployment_live/index.ex
··· 10 10 <Layouts.app flash={@flash} current_user={@current_user}> 11 11 <.header> 12 12 Listing Deployments 13 - <:actions> 14 - <.button variant="primary" navigate={~p"/deployments/new"}> 15 - <.icon name="hero-plus" /> New Deployment 16 - </.button> 17 - </:actions> 18 13 </.header> 19 14 20 15 <.table ··· 22 17 rows={@streams.deployments} 23 18 row_click={fn {_id, deployment} -> JS.navigate(~p"/deployments/#{deployment}") end} 24 19 > 25 - <:col :let={{_id, deployment}} label="Seed type">{deployment.sid}</:col> 20 + <:col :let={{_id, deployment}} label="sid">{deployment.sid}</:col> 21 + <:col :let={{_id, deployment}} label="result">{deployment.result}</:col> 22 + <:col :let={{_id, deployment}} label="initiated">{deployment.inserted_at}</:col> 23 + <:col :let={{_id, deployment}} label="done">{deployment.deployed_at}</:col> 26 24 <:action :let={{_id, deployment}}> 27 25 <div class="sr-only"> 28 26 <.link navigate={~p"/deployments/#{deployment}"}>Show</.link>
+36 -7
apps/sower/lib/sower_web/live/deployment_live/show.ex
··· 11 11 Deployment {@deployment.id} 12 12 <:subtitle>This is a deployment record from your database.</:subtitle> 13 13 <:actions> 14 - <.button navigate={~p"/deployments"}> 15 - <.icon name="hero-arrow-left" /> 16 - </.button> 17 - <.button variant="primary" navigate={~p"/deployments/#{@deployment}/edit?return_to=show"}> 18 - <.icon name="hero-pencil-square" /> Edit deployment 19 - </.button> 14 + <.link patch={~p"/deployments"}> 15 + <.button> 16 + <.icon name="hero-arrow-left" /> 17 + </.button> 18 + </.link> 20 19 </:actions> 21 20 </.header> 22 21 23 22 <.list> 24 23 <:item title="sid">{@deployment.sid}</:item> 24 + <:item title="Subscriptions"> 25 + <.table 26 + id="subscriptions" 27 + rows={@deployment.subscriptions} 28 + row_click={fn subscription -> JS.navigate(~p"/subscriptions/#{subscription.sid}") end} 29 + > 30 + <:col :let={subscription} label="agent">{subscription.agent.name}</:col> 31 + <:col :let={subscription} label="info"> 32 + {subscription.seed_type}/{subscription.seed_name} 33 + </:col> 34 + </.table> 35 + </:item> 36 + <:item title="Seeds"> 37 + <.table 38 + id="seeds" 39 + rows={@deployment.seeds} 40 + row_click={fn seed -> JS.navigate(~p"/seeds/#{seed.sid}") end} 41 + > 42 + <:col :let={seed}> 43 + {seed.seed_type}/{seed.name} 44 + </:col> 45 + <:col :let={seed}> 46 + {seed.artifact} 47 + </:col> 48 + </.table> 49 + </:item> 25 50 </.list> 26 51 </Layouts.app> 27 52 """ ··· 32 57 {:ok, 33 58 socket 34 59 |> assign(:page_title, "Show Deployment") 35 - |> assign(:deployment, Orchestration.get_deployment_sid!(sid))} 60 + |> assign( 61 + :deployment, 62 + Orchestration.get_deployment_sid!(sid) 63 + |> Sower.Repo.preload([:seeds, subscriptions: [:agent]]) 64 + )} 36 65 end 37 66 end
+1 -2
apps/sower/test/support/fixtures/orchestration_fixtures.ex
··· 26 26 def subscription_fixture(attrs \\ %{}) do 27 27 {:ok, subscription} = 28 28 attrs 29 - |> Enum.into(%{ 30 - }) 29 + |> Enum.into(%{}) 31 30 |> Sower.Orchestration.create_subscription() 32 31 33 32 subscription