Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

server: move deployment to orchestation

+113 -117
-106
apps/sower/lib/sower/distribution.ex
··· 1 - defmodule Sower.Distribution do 2 - @moduledoc """ 3 - The Distribution context. 4 - """ 5 - 6 - import Ecto.Query, warn: false 7 - alias Sower.Repo 8 - 9 - alias Sower.Distribution.Deployment 10 - 11 - @doc """ 12 - Returns the list of deployments. 13 - 14 - ## Examples 15 - 16 - iex> list_deployments() 17 - [%Deployment{}, ...] 18 - 19 - """ 20 - def list_deployments do 21 - Repo.all(Deployment) 22 - end 23 - 24 - @doc """ 25 - Gets a single deployment. 26 - 27 - Raises `Ecto.NoResultsError` if the Deployment does not exist. 28 - 29 - ## Examples 30 - 31 - iex> get_deployment!(123) 32 - %Deployment{} 33 - 34 - iex> get_deployment!(456) 35 - ** (Ecto.NoResultsError) 36 - 37 - """ 38 - def get_deployment!(id), do: Repo.get!(Deployment, id) 39 - 40 - @doc """ 41 - Creates a deployment. 42 - 43 - ## Examples 44 - 45 - iex> create_deployment(%{field: value}) 46 - {:ok, %Deployment{}} 47 - 48 - iex> create_deployment(%{field: bad_value}) 49 - {:error, %Ecto.Changeset{}} 50 - 51 - """ 52 - def create_deployment(attrs \\ %{}) do 53 - %Deployment{ 54 - org_id: Sower.Repo.get_org_id() 55 - } 56 - |> Deployment.changeset(attrs) 57 - |> Repo.insert() 58 - end 59 - 60 - @doc """ 61 - Updates a deployment. 62 - 63 - ## Examples 64 - 65 - iex> update_deployment(deployment, %{field: new_value}) 66 - {:ok, %Deployment{}} 67 - 68 - iex> update_deployment(deployment, %{field: bad_value}) 69 - {:error, %Ecto.Changeset{}} 70 - 71 - """ 72 - def update_deployment(%Deployment{} = deployment, attrs) do 73 - deployment 74 - |> Deployment.changeset(attrs) 75 - |> Repo.update() 76 - end 77 - 78 - @doc """ 79 - Deletes a deployment. 80 - 81 - ## Examples 82 - 83 - iex> delete_deployment(deployment) 84 - {:ok, %Deployment{}} 85 - 86 - iex> delete_deployment(deployment) 87 - {:error, %Ecto.Changeset{}} 88 - 89 - """ 90 - def delete_deployment(%Deployment{} = deployment) do 91 - Repo.delete(deployment) 92 - end 93 - 94 - @doc """ 95 - Returns an `%Ecto.Changeset{}` for tracking deployment changes. 96 - 97 - ## Examples 98 - 99 - iex> change_deployment(deployment) 100 - %Ecto.Changeset{data: %Deployment{}} 101 - 102 - """ 103 - def change_deployment(%Deployment{} = deployment, attrs \\ %{}) do 104 - Deployment.changeset(deployment, attrs) 105 - end 106 - end
+6 -4
apps/sower/lib/sower/distribution/deployment.ex apps/sower/lib/sower/orchestration/deployment.ex
··· 1 - defmodule Sower.Distribution.Deployment do 1 + defmodule Sower.Orchestration.Deployment do 2 2 use Sower.Schema 3 3 import Ecto.Changeset 4 4 5 - alias Sower.Distribution 5 + alias Sower.Orchestration 6 6 7 7 @derive {Jason.Encoder, only: [:sid]} 8 8 @derive {Phoenix.Param, key: :sid} ··· 11 11 field :sid, Sower.Schema.Sid, autogenerate: true 12 12 field :org_id, Ecto.UUID 13 13 14 - many_to_many :seeds, Sower.Seed, join_through: Distribution.SeedDeployment 15 - many_to_many :store_paths, Sower.Nix.StorePath, join_through: Distribution.StorePathDeployment 14 + many_to_many :seeds, Sower.Seed, join_through: Orchestration.SeedDeployment 15 + 16 + many_to_many :store_paths, Sower.Nix.StorePath, 17 + join_through: Orchestration.StorePathDeployment 16 18 17 19 field :deployed_at, :utc_datetime 18 20
+1 -1
apps/sower/lib/sower/distribution/seed_deployment.ex apps/sower/lib/sower/orchestration/seed_deployment.ex
··· 1 - defmodule Sower.Distribution.SeedDeployment do 1 + defmodule Sower.Orchestration.SeedDeployment do 2 2 use Sower.Schema 3 3 import Ecto.Changeset 4 4
+1 -1
apps/sower/lib/sower/distribution/store_path_deployment.ex apps/sower/lib/sower/orchestration/store_path_deployment.ex
··· 1 - defmodule Sower.Distribution.StorePathDeployment do 1 + defmodule Sower.Orchestration.StorePathDeployment do 2 2 use Sower.Schema 3 3 import Ecto.Changeset 4 4
+2 -2
apps/sower/lib/sower/nix/store_path.ex
··· 14 14 15 15 many_to_many :seeds, Sower.Seed, join_through: Sower.SeedStorePath 16 16 17 - many_to_many :deployments, Sower.Distribution.Deployment, 18 - join_through: Sower.Distribution.StorePathDeployment 17 + many_to_many :deployments, Sower.Orchestration.Deployment, 18 + join_through: Sower.Orchestration.StorePathDeployment 19 19 20 20 timestamps() 21 21 end
+98
apps/sower/lib/sower/orchestration.ex
··· 288 288 |> Repo.preload(:agent) 289 289 |> Subscription.changeset(attrs) 290 290 end 291 + 292 + alias Sower.Orchestration.Deployment 293 + 294 + @doc """ 295 + Returns the list of deployments. 296 + 297 + ## Examples 298 + 299 + iex> list_deployments() 300 + [%Deployment{}, ...] 301 + 302 + """ 303 + def list_deployments do 304 + Repo.all(Deployment) 305 + end 306 + 307 + @doc """ 308 + Gets a single deployment. 309 + 310 + Raises `Ecto.NoResultsError` if the Deployment does not exist. 311 + 312 + ## Examples 313 + 314 + iex> get_deployment!(123) 315 + %Deployment{} 316 + 317 + iex> get_deployment!(456) 318 + ** (Ecto.NoResultsError) 319 + 320 + """ 321 + def get_deployment!(id), do: Repo.get!(Deployment, id) 322 + 323 + @doc """ 324 + Creates a deployment. 325 + 326 + ## Examples 327 + 328 + iex> create_deployment(%{field: value}) 329 + {:ok, %Deployment{}} 330 + 331 + iex> create_deployment(%{field: bad_value}) 332 + {:error, %Ecto.Changeset{}} 333 + 334 + """ 335 + def create_deployment(attrs \\ %{}) do 336 + %Deployment{ 337 + org_id: Sower.Repo.get_org_id() 338 + } 339 + |> Deployment.changeset(attrs) 340 + |> Repo.insert() 341 + end 342 + 343 + @doc """ 344 + Updates a deployment. 345 + 346 + ## Examples 347 + 348 + iex> update_deployment(deployment, %{field: new_value}) 349 + {:ok, %Deployment{}} 350 + 351 + iex> update_deployment(deployment, %{field: bad_value}) 352 + {:error, %Ecto.Changeset{}} 353 + 354 + """ 355 + def update_deployment(%Deployment{} = deployment, attrs) do 356 + deployment 357 + |> Deployment.changeset(attrs) 358 + |> Repo.update() 359 + end 360 + 361 + @doc """ 362 + Deletes a deployment. 363 + 364 + ## Examples 365 + 366 + iex> delete_deployment(deployment) 367 + {:ok, %Deployment{}} 368 + 369 + iex> delete_deployment(deployment) 370 + {:error, %Ecto.Changeset{}} 371 + 372 + """ 373 + def delete_deployment(%Deployment{} = deployment) do 374 + Repo.delete(deployment) 375 + end 376 + 377 + @doc """ 378 + Returns an `%Ecto.Changeset{}` for tracking deployment changes. 379 + 380 + ## Examples 381 + 382 + iex> change_deployment(deployment) 383 + %Ecto.Changeset{data: %Deployment{}} 384 + 385 + """ 386 + def change_deployment(%Deployment{} = deployment, attrs \\ %{}) do 387 + Deployment.changeset(deployment, attrs) 388 + end 291 389 end
+4 -2
apps/sower/lib/sower/seed.ex
··· 4 4 import Ecto.Changeset 5 5 import Ecto.Query, only: [from: 2] 6 6 7 - alias Sower.{Distribution, Nix, Repo, Seed, SeedStorePath} 7 + alias Sower.{Orchestration, Nix, Repo, Seed, SeedStorePath} 8 8 9 9 @derive {Jason.Encoder, only: [:sid, :name, :seed_type]} 10 10 ··· 19 19 field :org_id, Ecto.UUID 20 20 21 21 many_to_many :store_paths, Nix.StorePath, join_through: Sower.SeedStorePath 22 - many_to_many :deployments, Distribution.Deployment, join_through: Distribution.SeedDeployment 22 + 23 + many_to_many :deployments, Orchestration.Deployment, 24 + join_through: Orchestration.SeedDeployment 23 25 24 26 timestamps() 25 27 end
+1 -1
apps/sower/lib/sower_web/agent_channel.ex
··· 89 89 90 90 store_path = Sower.Nix.submit_store_path!(payload.path) 91 91 92 - Sower.Distribution.create_deployment(%{ 92 + Sower.Orchestration.create_deployment(%{ 93 93 deployed_at: payload.created, 94 94 store_paths: [store_path] 95 95 })