Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

cli: prep seed tags

+46 -11
+1
apps/nix/lib/nix/build.ex
··· 19 19 field :end_time, DateTime.t() 20 20 field :status, :ok | :error | :timeout 21 21 field :log, list(binary()), default: [] 22 + field :cached, boolean(), default: false 22 23 end 23 24 24 25 typedstruct module: Exec do
+36 -11
apps/sower_cli/lib/sower_cli/build.ex
··· 129 129 if state.flags.fail_fast do 130 130 {:error, :build_failed} 131 131 else 132 - successful = Enum.filter(builds, &(&1.status == :ok)) 133 - 134 - if Enum.empty?(successful) do 132 + if not Enum.all?(builds, &(&1.status == :ok)) do 135 133 {:error, :build_failed} 136 134 else 137 - run_steps(rest, %{state | builds: successful}) 135 + run_steps(rest, %{state | builds: builds}) 138 136 end 139 137 end 140 138 end ··· 146 144 cache_url = state.options.cache || SowerCli.Config.get().cache 147 145 {:ok, {cache_module, cache_config}} = Cache.parse_url(cache_url) 148 146 149 - store_paths = 147 + builds = 150 148 state.builds 151 149 |> Enum.filter(&(&1.status == :ok)) 150 + 151 + store_paths = 152 + builds 152 153 |> Enum.map(& &1.store_path) 153 154 |> Enum.reject(&is_nil/1) 154 155 ··· 161 162 162 163 case result do 163 164 {:ok, _} -> 164 - run_steps(rest, %{state | cache_module: cache_module, cache_config: cache_config}) 165 + # we're batch uploading, so don't get individual results 166 + # mark all builds as cached 167 + builds = builds |> Enum.map(fn build -> %{build | cached: true} end) 168 + 169 + run_steps(rest, %{ 170 + state 171 + | cache_module: cache_module, 172 + cache_config: cache_config, 173 + builds: builds 174 + }) 165 175 166 176 {:error, _reason} -> 167 177 {:error, :push_failed} ··· 171 181 172 182 defp run_steps([:seed | rest], %__MODULE__{} = state) do 173 183 Output.step("Registering seed") 174 - Output.info("TODO: seed registration not yet implemented") 175 184 176 - # Show what would be registered 177 - if state.options.tag do 178 - Output.info("Tags: #{inspect(state.options.tag)}") 179 - end 185 + load_tags(state) 186 + |> dbg() 180 187 181 188 run_steps(rest, state) 189 + end 190 + 191 + defp load_tags(%__MODULE__{} = state) do 192 + state.options.tag 193 + |> Enum.map(&SowerClient.Schemas.SeedTag.from_string/1) 194 + |> add_env_tags() 195 + end 196 + 197 + defp add_env_tags(tags) do 198 + [ 199 + tag_git_branch() 200 + | tags 201 + ] 202 + end 203 + 204 + defp tag_git_branch() do 205 + # TODO put something real here 206 + %SowerClient.Schemas.SeedTag{key: "git_branch", value: "main"} 182 207 end 183 208 end
+9
apps/sower_client/lib/schemas/seed_tag.ex
··· 21 21 "value" => "production" 22 22 } 23 23 }) 24 + 25 + def from_string(tag) when is_binary(tag) do 26 + [key, val] = String.split(tag, "=") 27 + 28 + %__MODULE__{ 29 + key: key, 30 + value: val 31 + } 32 + end 24 33 end