From 8bda59692ff357e16aa5cb7241d617ca3638c34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:24:48 +0200 Subject: [PATCH 01/24] Add Phoenix.PubSub to the supervision tree --- lib/bob/application.ex | 1 + mix.exs | 3 ++- mix.lock | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bob/application.ex b/lib/bob/application.ex index 54bbe1c4..ce3e2e85 100644 --- a/lib/bob/application.ex +++ b/lib/bob/application.ex @@ -16,6 +16,7 @@ defmodule Bob.Application do [ {Finch, name: Bob.Finch}, {Task.Supervisor, [name: Bob.Tasks]}, + {Phoenix.PubSub, name: Bob.PubSub}, Bob.DockerHub.RateLimiter, Bob.DockerHub.Auth, runner_spec(), diff --git a/mix.exs b/mix.exs index 12f6d9e9..c4b6d2ca 100644 --- a/mix.exs +++ b/mix.exs @@ -36,7 +36,8 @@ defmodule Bob.Mixfile do {:sentry, "~> 10.2"}, {:sweet_xml, "~> 0.5"}, {:logster, "~> 1.0"}, - {:observer_cli, "~> 1.7"} + {:observer_cli, "~> 1.7"}, + {:phoenix_pubsub, "~> 2.1"} ] end diff --git a/mix.lock b/mix.lock index e3d79562..e914ffe4 100644 --- a/mix.lock +++ b/mix.lock @@ -18,6 +18,7 @@ "nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, "observer_cli": {:hex, :observer_cli, "1.8.5", "6771e73560432049891b7737b0edce67ef28aa7973a8dd2b39b21da8c1227386", [:mix, :rebar3], [{:recon, "~> 2.5.6", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm", "4252f4af00b48b51718ef8ccd9da5ce879cdfc8da66debaa9d471fc9bf099f59"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"}, "plug_cowboy": {:hex, :plug_cowboy, "2.7.4", "729c752d17cf364e2b8da5bdb34fb5804f56251e88bb602aff48ae0bd8673d11", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9b85632bd7012615bae0a5d70084deb1b25d2bcbb32cab82d1e9a1e023168aa3"}, "plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"}, From 6ec6a50ed347ece3f2b73a222dbd0e1234561da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:27:53 +0200 Subject: [PATCH 02/24] Add Bob.Queue read functions for the web UI --- lib/bob/queue.ex | 31 +++++++++++++++++++++++++++++++ test/bob/queue_test.exs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/bob/queue.ex b/lib/bob/queue.ex index 3b72349f..683cd7af 100644 --- a/lib/bob/queue.ex +++ b/lib/bob/queue.ex @@ -150,6 +150,37 @@ defmodule Bob.Queue do ) end + def running() do + Repo.all( + from(j in Job, + where: j.state == "running", + order_by: [desc: j.started_at, desc: j.id] + ) + ) + end + + def queued_listing(limit \\ 100, offset \\ 0) do + Repo.all( + from(j in Job, + where: j.state == "queued", + order_by: [j.inserted_at, j.id], + limit: ^limit, + offset: ^offset + ) + ) + end + + def recent(limit \\ 50, offset \\ 0) do + Repo.all( + from(j in Job, + where: j.state in ["done", "failed"], + order_by: [desc: j.finished_at, desc: j.id], + limit: ^limit, + offset: ^offset + ) + ) + end + defp finish(id, state) do now = DateTime.utc_now() diff --git a/test/bob/queue_test.exs b/test/bob/queue_test.exs index d69fcb07..5048da98 100644 --- a/test/bob/queue_test.exs +++ b/test/bob/queue_test.exs @@ -204,4 +204,40 @@ defmodule Bob.QueueTest do assert Queue.queued() == [{TestJob, [:a]}, {{TestJob, :variant}, [:b, :c]}] end + + describe "read functions" do + test "running/0 returns running jobs newest-started first" do + Bob.Queue.add(Bob.Job.OTPChecker, [:a]) + Bob.Queue.add(Bob.Job.OTPChecker, [:b]) + {:ok, _} = Bob.Queue.start(Bob.Job.OTPChecker) + {:ok, _} = Bob.Queue.start(Bob.Job.OTPChecker) + + running = Bob.Queue.running() + assert length(running) == 2 + assert Enum.all?(running, &(&1.state == "running")) + assert hd(running).started_at >= List.last(running).started_at + end + + test "queued_listing/2 returns queued jobs oldest-first with limit/offset" do + for n <- 1..3, do: Bob.Queue.add(Bob.Job.OTPChecker, [n]) + + assert [a, b] = Bob.Queue.queued_listing(2, 0) + assert a.inserted_at <= b.inserted_at + assert [_c] = Bob.Queue.queued_listing(2, 2) + end + + test "recent/2 returns done and failed jobs newest-finished first" do + Bob.Queue.add(Bob.Job.OTPChecker, [:done]) + {:ok, {id1, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + Bob.Queue.success(id1) + + Bob.Queue.add(Bob.Job.OTPChecker, [:fail]) + {:ok, {id2, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + Bob.Queue.failure(id2) + + recent = Bob.Queue.recent(50, 0) + assert Enum.map(recent, & &1.state) |> Enum.sort() == ["done", "failed"] + assert hd(recent).finished_at >= List.last(recent).finished_at + end + end end From c8596d9f0ae0efbdbcaa516c27afe2b687a64898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:31:28 +0200 Subject: [PATCH 03/24] Add Bob.Artifacts search and distinct-value functions --- lib/bob/artifacts.ex | 57 +++++++++++++++++++++++++++++++++++ test/bob/artifacts_test.exs | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/lib/bob/artifacts.ex b/lib/bob/artifacts.ex index 3f8169c2..646ebbf2 100644 --- a/lib/bob/artifacts.ex +++ b/lib/bob/artifacts.ex @@ -188,6 +188,63 @@ defmodule Bob.Artifacts do num_rows end + def search_artifacts(filters \\ %{}, limit \\ 100, offset \\ 0) do + query = blank_to_nil(Map.get(filters, :query)) + + from(a in Artifact, order_by: [desc: a.built_at, desc: a.id], limit: ^limit, offset: ^offset) + |> text_filter(query, [:name, :ref]) + |> eq_filter(:kind, Map.get(filters, :kind)) + |> eq_filter(:arch, Map.get(filters, :arch)) + |> eq_filter(:os, Map.get(filters, :os)) + |> Repo.all() + end + + def search_docker_tags(filters \\ %{}, limit \\ 100, offset \\ 0) do + query = blank_to_nil(Map.get(filters, :query)) + + from(d in DockerTag, order_by: [desc: d.built_at, desc: d.id], limit: ^limit, offset: ^offset) + |> text_filter(query, [:tag]) + |> eq_filter(:repo, Map.get(filters, :repo)) + |> Repo.all() + end + + def distinct_kinds(), do: distinct_values(Artifact, :kind) + def distinct_arches(), do: distinct_values(Artifact, :arch) + def distinct_oses(), do: distinct_values(Artifact, :os) + def distinct_repos(), do: distinct_values(DockerTag, :repo) + + defp distinct_values(schema, field) do + Repo.all( + from(s in schema, distinct: true, select: field(s, ^field), order_by: field(s, ^field)) + ) + end + + defp blank_to_nil(nil), do: nil + defp blank_to_nil(""), do: nil + defp blank_to_nil(value), do: value + + defp eq_filter(query, _field, nil), do: query + defp eq_filter(query, _field, ""), do: query + defp eq_filter(query, field, value), do: from(s in query, where: field(s, ^field) == ^value) + + defp text_filter(query, nil, _fields), do: query + + defp text_filter(query, text, [first_field | rest_fields]) do + pattern = "%" <> escape_like(text) <> "%" + + conditions = + Enum.reduce(rest_fields, dynamic([s], ilike(field(s, ^first_field), ^pattern)), fn field, + acc -> + dynamic([s], ^acc or ilike(field(s, ^field), ^pattern)) + end) + + from(s in query, where: ^conditions) + end + + defp escape_like(string) do + String.replace(string, ~r/([\\%_])/, "\\\\\\1") + end + def docker_tags(repo) do Repo.all( from(d in DockerTag, diff --git a/test/bob/artifacts_test.exs b/test/bob/artifacts_test.exs index 38d937b4..2570ad2b 100644 --- a/test/bob/artifacts_test.exs +++ b/test/bob/artifacts_test.exs @@ -428,6 +428,66 @@ defmodule Bob.ArtifactsTest do end end + describe "search" do + setup do + Bob.Artifacts.upsert(%{ + kind: "otp", + arch: "amd64", + os: "ubuntu-24.04", + name: "OTP-27.0", + ref: "aaa", + built_at: ~U[2026-01-01 00:00:00Z] + }) + + Bob.Artifacts.upsert(%{ + kind: "otp", + arch: "arm64", + os: "ubuntu-22.04", + name: "OTP-26.2", + ref: "bbb", + built_at: ~U[2026-02-01 00:00:00Z] + }) + + :ok + end + + test "search_artifacts/1 with blank filters returns newest first" do + assert [%{name: "OTP-26.2"}, %{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{}) + end + + test "search_artifacts/1 filters by free-text on name" do + assert [%{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{query: "27.0"}) + end + + test "search_artifacts/1 filters by arch" do + assert [%{arch: "arm64"}] = Bob.Artifacts.search_artifacts(%{arch: "arm64"}) + end + + test "distinct value helpers" do + assert Bob.Artifacts.distinct_kinds() == ["otp"] + assert Bob.Artifacts.distinct_arches() == ["amd64", "arm64"] + assert Bob.Artifacts.distinct_oses() == ["ubuntu-22.04", "ubuntu-24.04"] + end + + test "search_docker_tags/1 filters by repo and tag text" do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-alpine", ["amd64"]) + Bob.Artifacts.add_docker_tag("hexpm/elixir", "1.18.0-alpine", ["amd64"]) + + assert [%{repo: "hexpm/erlang"}] = Bob.Artifacts.search_docker_tags(%{repo: "hexpm/erlang"}) + assert [%{tag: "1.18.0-alpine"}] = Bob.Artifacts.search_docker_tags(%{query: "1.18"}) + assert Bob.Artifacts.distinct_repos() == ["hexpm/elixir", "hexpm/erlang"] + end + + test "search_artifacts/1 does not treat % as a LIKE wildcard" do + assert Bob.Artifacts.search_artifacts(%{query: "%"}) == [] + end + + test "search_artifacts/3 respects limit and offset" do + assert [%{name: "OTP-26.2"}] = Bob.Artifacts.search_artifacts(%{}, 1, 0) + assert [%{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{}, 1, 1) + end + end + defp replace(repo, tag_archs) do token = Ecto.UUID.generate() Artifacts.stage_docker_tags(token, repo, tag_archs) From ab27acc8d984efc2ebd0aacddaf46ce0d5dad16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:38:03 +0200 Subject: [PATCH 04/24] Broadcast :jobs_changed from Bob.Queue mutations --- lib/bob/queue.ex | 8 ++++++++ test/bob/queue_test.exs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/bob/queue.ex b/lib/bob/queue.ex index 683cd7af..090766c3 100644 --- a/lib/bob/queue.ex +++ b/lib/bob/queue.ex @@ -59,6 +59,7 @@ defmodule Bob.Queue do ) end) + broadcast() :ok end @@ -87,6 +88,7 @@ defmodule Bob.Queue do [[id, args_binary]] -> args = Term.decode(args_binary) Logger.info("STARTING #{inspect(key)} #{inspect(args)}") + broadcast() {:ok, {id, args}} [] -> @@ -111,6 +113,7 @@ defmodule Bob.Queue do end end) + broadcast() :ok end @@ -126,6 +129,7 @@ defmodule Bob.Queue do end end) + broadcast() :ok end @@ -255,4 +259,8 @@ defmodule Bob.Queue do defp backoff_seconds(count) do min(@backoff_base * Integer.pow(2, min(count - 1, 12)), @backoff_max) end + + defp broadcast() do + Phoenix.PubSub.broadcast(Bob.PubSub, "jobs", :jobs_changed) + end end diff --git a/test/bob/queue_test.exs b/test/bob/queue_test.exs index 5048da98..4699320c 100644 --- a/test/bob/queue_test.exs +++ b/test/bob/queue_test.exs @@ -205,6 +205,41 @@ defmodule Bob.QueueTest do assert Queue.queued() == [{TestJob, [:a]}, {{TestJob, :variant}, [:b, :c]}] end + describe "pubsub broadcasts" do + setup do + Phoenix.PubSub.subscribe(Bob.PubSub, "jobs") + :ok + end + + test "add broadcasts :jobs_changed" do + Bob.Queue.add(Bob.Job.OTPChecker, [:a]) + assert_receive :jobs_changed + end + + test "start broadcasts :jobs_changed" do + Bob.Queue.add(Bob.Job.OTPChecker, [:a]) + assert_receive :jobs_changed + {:ok, _} = Bob.Queue.start(Bob.Job.OTPChecker) + assert_receive :jobs_changed + end + + test "success and failure broadcast :jobs_changed" do + Bob.Queue.add(Bob.Job.OTPChecker, [:a]) + assert_receive :jobs_changed + {:ok, {id, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + assert_receive :jobs_changed + Bob.Queue.success(id) + assert_receive :jobs_changed + + Bob.Queue.add(Bob.Job.OTPChecker, [:b]) + assert_receive :jobs_changed + {:ok, {id2, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + assert_receive :jobs_changed + Bob.Queue.failure(id2) + assert_receive :jobs_changed + end + end + describe "read functions" do test "running/0 returns running jobs newest-started first" do Bob.Queue.add(Bob.Job.OTPChecker, [:a]) From f5576469746d6febbf8b1a305d99f58756e4b786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:44:07 +0200 Subject: [PATCH 05/24] Add Phoenix, Bandit, and asset toolchain dependencies --- mix.exs | 15 +++++++++++++-- mix.lock | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index c4b6d2ca..22d9fdf3 100644 --- a/mix.exs +++ b/mix.exs @@ -37,14 +37,25 @@ defmodule Bob.Mixfile do {:sweet_xml, "~> 0.5"}, {:logster, "~> 1.0"}, {:observer_cli, "~> 1.7"}, - {:phoenix_pubsub, "~> 2.1"} + {:phoenix_pubsub, "~> 2.1"}, + {:phoenix, "~> 1.7"}, + {:phoenix_html, "~> 4.1"}, + {:phoenix_live_view, "~> 1.0"}, + {:phoenix_live_reload, "~> 1.5", only: :dev}, + {:bandit, "~> 1.5"}, + {:esbuild, "~> 0.8", runtime: Mix.env() == :dev}, + {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, + {:floki, ">= 0.30.0", only: :test} ] end defp aliases() do [ "ecto.setup": ["ecto.create", "ecto.migrate"], - "ecto.reset": ["ecto.drop", "ecto.setup"] + "ecto.reset": ["ecto.drop", "ecto.setup"], + "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"], + "assets.build": ["tailwind bob", "esbuild bob"], + "assets.deploy": ["tailwind bob --minify", "esbuild bob --minify", "phx.digest"] ] end diff --git a/mix.lock b/mix.lock index e914ffe4..89d39723 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,5 @@ %{ + "bandit": {:hex, :bandit, "1.12.0", "6c5214daa2469644ac4ab0113b98abc24f75e348378e6a974c6343b3e5da22ef", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.5", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "45dac82dc86f45cf4a196dee9cc5a8b791d9c9469d996055f055e6ee36c66e20"}, "cowboy": {:hex, :cowboy, "2.13.0", "09d770dd5f6a22cc60c071f432cd7cb87776164527f205c5a6b0f24ff6b38990", [:make, :rebar3], [{:cowlib, ">= 2.14.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "e724d3a70995025d654c1992c7b11dbfea95205c047d86ff9bf1cda92ddc5614"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.15.0", "3c97a318a933962d1c12b96ab7c1d728267d2c523c25a5b57b0f93392b6e9e25", [:make, :rebar3], [], "hexpm", "4f00c879a64b4fe7c8fcb42a4281925e9ffdb928820b03c3ad325a617e857532"}, @@ -6,9 +7,12 @@ "decimal": {:hex, :decimal, "2.4.1", "6c0fbede12fb122ba685e9ab41c6a40c129e322b3aa192f9e072e61f3a6ffaf2", [:mix], [], "hexpm", "7e618897933a8455f19a727d7c5e50a2c071a544b700e5e724298ecb4340187f"}, "ecto": {:hex, :ecto, "3.13.6", "352135b474f91d1ab99a1b502171d207e9db60421c9e3d0ecab4c7ab96b24d14", [:mix], [{:decimal, "~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8afa059bc16cd2c94739ec0a11e3e5df69d828125119109bef35f20a21a76af2"}, "ecto_sql": {:hex, :ecto_sql, "3.13.5", "2f8282b2ad97bf0f0d3217ea0a6fff320ead9e2f8770f810141189d182dc304e", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aa36751f4e6a2b56ae79efb0e088042e010ff4935fc8684e74c23b1f49e25fdc"}, + "esbuild": {:hex, :esbuild, "0.10.0", "b0aa3388a1c23e727c5a3e7427c932d89ee791746b0081bbe56103e9ef3d291f", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "468489cda427b974a7cc9f03ace55368a83e1a7be12fba7e30969af78e5f8c70"}, "ex_aws": {:hex, :ex_aws, "2.5.10", "d3f8ca8959dad6533a2a934dfdf380df1b1bef425feeb215a47a5176dee8736c", [:mix], [{:configparser_ex, "~> 5.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "88fcd9cc1b2e0fcea65106bdaa8340ac56c6e29bf72f46cf7ef174027532d3da"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.5.7", "e571424d2f345299753382f3a01b005c422b1a460a8bc3ed47659b3d3ef91e9e", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "858e51241e50181e29aa2bc128fef548873a3a9cd580471f57eda5b64dec937f"}, + "file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"}, "finch": {:hex, :finch, "0.22.0", "5c48fa6f9706a78eb9036cacb67b8b996b4e66d111c543f4c29bb0f879a6806b", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b94e83c47780fc6813f746a1f1a34ee65cda42da4c5ea26a68f0acc4498e23dc"}, + "floki": {:hex, :floki, "0.38.3", "40d291831d93f49aa360f09447cf2e2a902e33d8711e5fb22a75f3f333e9d063", [:mix], [], "hexpm", "025aa1f5f24a70cb31bfbc7011419228596f3b062d7feda617238ba4926f83cb"}, "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "logster": {:hex, :logster, "1.1.1", "d6fddac540dd46adde0c894024500867fe63b0043713f842c62da5815e21db10", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d18e852c430812ad1c9756998ebe46ec814c724e6eb551a512d7e3f8dee24cef"}, @@ -18,7 +22,12 @@ "nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, "observer_cli": {:hex, :observer_cli, "1.8.5", "6771e73560432049891b7737b0edce67ef28aa7973a8dd2b39b21da8c1227386", [:mix, :rebar3], [{:recon, "~> 2.5.6", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm", "4252f4af00b48b51718ef8ccd9da5ce879cdfc8da66debaa9d471fc9bf099f59"}, + "phoenix": {:hex, :phoenix, "1.8.7", "d8d755b4ff4b449f610223dd706b4ae64155cb720d3dc09c706c079ecea189e4", [:mix], [{:bandit, "~> 1.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "47352f72d6ab31009ef77516b1b3a14745be97b54061fd458031b9d8294869d5"}, + "phoenix_html": {:hex, :phoenix_html, "4.3.0", "d3577a5df4b6954cd7890c84d955c470b5310bb49647f0a114a6eeecc850f7ad", [:mix], [], "hexpm", "3eaa290a78bab0f075f791a46a981bbe769d94bc776869f4f3063a14f30497ad"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.6.2", "b18b0773a1ba77f28c52decbb0f10fd1ac4d3ae5b8632399bbf6986e3b665f62", [:mix], [{:file_system, "~> 0.2.10 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "d1f89c18114c50d394721365ffb428cce24f1c13de0467ffa773e2ff4a30d5b9"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "1.1.31", "c45c85df509dd79c917bc530e26c71299e3920850f65ea52ab6a19ccee66875a", [:mix], [{:igniter, ">= 0.6.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:lazy_html, "~> 0.1.0", [hex: :lazy_html, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0 or ~> 1.8.0-rc", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2f53cc6a9e149f30449341c2775990819d97e3b22338fe719c4d30342e6f9638"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, + "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"}, "plug_cowboy": {:hex, :plug_cowboy, "2.7.4", "729c752d17cf364e2b8da5bdb34fb5804f56251e88bb602aff48ae0bd8673d11", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9b85632bd7012615bae0a5d70084deb1b25d2bcbb32cab82d1e9a1e023168aa3"}, "plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"}, @@ -29,5 +38,9 @@ "req": {:hex, :req, "0.6.0", "85dec26488ea23e29b4b516dc1fb9615b2f6f32fe824980d1adc9d79d44a83fd", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21.0 or ~> 0.22.0", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "f90e15671bfcc0c40ba26aaf825c47aec3f8b4f14f54a41bdd14e255fb67118e"}, "sentry": {:hex, :sentry, "10.10.0", "d058b635f3796947545c8057a42996f6dbefd12152da947209b56d16af41b161", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7c7ddd3cfdd63fcee53b1e28f9a653037e6927b2b1dbd300b7aeee9687c7a8f6"}, "sweet_xml": {:hex, :sweet_xml, "0.7.5", "803a563113981aaac202a1dbd39771562d0ad31004ddbfc9b5090bdcd5605277", [:mix], [], "hexpm", "193b28a9b12891cae351d81a0cead165ffe67df1b73fe5866d10629f4faefb12"}, + "tailwind": {:hex, :tailwind, "0.4.1", "e7bcc222fe96a1e55f948e76d13dd84a1a7653fb051d2a167135db3b4b08d3e9", [:mix], [], "hexpm", "6249d4f9819052911120dbdbe9e532e6bd64ea23476056adb7f730aa25c220d1"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, + "thousand_island": {:hex, :thousand_island, "1.5.0", "f50a213cac97262b6d5ebb85745aa2c00fec1413191e6e66834788d45425cecb", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "708923d40523e43cf99041ab37a0d4b0ec426ac6438fa3716ab23d919eaeb412"}, + "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, + "websock_adapter": {:hex, :websock_adapter, "0.5.9", "43dc3ba6d89ef5dec5b1d0a39698436a1e856d000d84bf31a3149862b01a287f", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5534d5c9adad3c18a0f58a9371220d75a803bf0b9a3d87e6fe072faaeed76a08"}, } From bead2293a1d5efef732d60aefcbee3bab9feb47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:48:30 +0200 Subject: [PATCH 06/24] Configure Phoenix endpoint and Tailwind/esbuild asset pipeline --- assets/css/app.css | 3 +++ assets/js/app.js | 9 +++++++++ assets/tailwind.config.js | 9 +++++++++ assets/vendor/.gitkeep | 0 config/config.exs | 28 ++++++++++++++++++++++++++++ config/dev.exs | 17 +++++++++++++++++ config/runtime.exs | 7 +++++++ config/test.exs | 5 +++++ 8 files changed, 78 insertions(+) create mode 100644 assets/css/app.css create mode 100644 assets/js/app.js create mode 100644 assets/tailwind.config.js create mode 100644 assets/vendor/.gitkeep diff --git a/assets/css/app.css b/assets/css/app.css new file mode 100644 index 00000000..b5c61c95 --- /dev/null +++ b/assets/css/app.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/assets/js/app.js b/assets/js/app.js new file mode 100644 index 00000000..71e58668 --- /dev/null +++ b/assets/js/app.js @@ -0,0 +1,9 @@ +import "phoenix_html" +import {Socket} from "phoenix" +import {LiveSocket} from "phoenix_live_view" + +let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) + +liveSocket.connect() +window.liveSocket = liveSocket diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js new file mode 100644 index 00000000..cacb0d73 --- /dev/null +++ b/assets/tailwind.config.js @@ -0,0 +1,9 @@ +module.exports = { + content: [ + "./js/**/*.js", + "../lib/bob_web.ex", + "../lib/bob_web/**/*.*ex" + ], + theme: {extend: {}}, + plugins: [] +} diff --git a/assets/vendor/.gitkeep b/assets/vendor/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/config/config.exs b/config/config.exs index 96ccb41e..8cc60f70 100644 --- a/config/config.exs +++ b/config/config.exs @@ -64,4 +64,32 @@ config :sentry, client: Bob.SentryClient config :logger, :default_formatter, format: "$metadata[$level] $message\n" +config :bob, BobWeb.Endpoint, + url: [host: "localhost"], + adapter: Bandit.PhoenixAdapter, + render_errors: [ + formats: [html: BobWeb.ErrorHTML, json: BobWeb.ErrorJSON], + layout: false + ], + pubsub_server: Bob.PubSub, + live_view: [signing_salt: "u8xQ2rPspeARxr1n"] + +config :phoenix, :json_library, JSON + +config :esbuild, + version: "0.21.5", + bob: [ + args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets), + cd: Path.expand("../assets", __DIR__), + env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} + ] + +config :tailwind, + version: "3.4.3", + bob: [ + args: + ~w(--config=tailwind.config.js --input=css/app.css --output=../priv/static/assets/app.css), + cd: Path.expand("../assets", __DIR__) + ] + import_config "#{Mix.env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index 592d8eec..5dfa2e85 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -10,3 +10,20 @@ config :bob, Bob.Repo, hostname: "localhost", database: "bob_dev", pool_size: 10 + +config :bob, BobWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4003], + check_origin: false, + code_reloader: true, + debug_errors: true, + secret_key_base: "kQv8mZr2hP0sJX4bN6wL9cT1dY3fA5gH7uE2iO4kR6mS8tV0xZ2bC4dF6hJ8lN0", + watchers: [ + esbuild: {Esbuild, :install_and_run, [:bob, ~w(--sourcemap=inline --watch)]}, + tailwind: {Tailwind, :install_and_run, [:bob, ~w(--watch)]} + ], + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"lib/bob_web/(controllers|live|components)/.*(ex|heex)$" + ] + ] diff --git a/config/runtime.exs b/config/runtime.exs index 63ca057f..1fce7eae 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -29,4 +29,11 @@ if config_env() == :prod do bob_who: System.fetch_env!("BOB_WHO"), bob_hostname: System.fetch_env!("BOB_HOSTNAME") } + + config :bob, BobWeb.Endpoint, + server: true, + url: [host: System.fetch_env!("BOB_HOST"), port: 443, scheme: "https"], + http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("BOB_PORT") || "4003")], + secret_key_base: System.fetch_env!("SECRET_KEY_BASE"), + check_origin: [System.fetch_env!("BOB_HOST")] end diff --git a/config/test.exs b/config/test.exs index 581ebfe9..41f09b20 100644 --- a/config/test.exs +++ b/config/test.exs @@ -18,3 +18,8 @@ config :bob, Bob.Repo, database: "bob_test", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 10 + +config :bob, BobWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], + secret_key_base: "tT9wQ2eR5yU8iO1pA4sD7fG0hJ3kL6zX9cV2bN5mQ8wE1rT4yU7iO0pA3sD6fG9", + server: false From 27238f09f1fece68cf44af5669c1222f5a20371d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:53:24 +0200 Subject: [PATCH 07/24] Add BobWeb entry module, error views, components, and layouts --- lib/bob_web.ex | 59 +++++++++++++++++++ lib/bob_web/components/core_components.ex | 36 +++++++++++ lib/bob_web/components/layouts.ex | 5 ++ lib/bob_web/components/layouts/app.html.heex | 2 + lib/bob_web/components/layouts/root.html.heex | 25 ++++++++ lib/bob_web/controllers/error_html.ex | 7 +++ lib/bob_web/controllers/error_json.ex | 5 ++ lib/bob_web/router.ex | 3 + 8 files changed, 142 insertions(+) create mode 100644 lib/bob_web.ex create mode 100644 lib/bob_web/components/core_components.ex create mode 100644 lib/bob_web/components/layouts.ex create mode 100644 lib/bob_web/components/layouts/app.html.heex create mode 100644 lib/bob_web/components/layouts/root.html.heex create mode 100644 lib/bob_web/controllers/error_html.ex create mode 100644 lib/bob_web/controllers/error_json.ex create mode 100644 lib/bob_web/router.ex diff --git a/lib/bob_web.ex b/lib/bob_web.ex new file mode 100644 index 00000000..769d2d18 --- /dev/null +++ b/lib/bob_web.ex @@ -0,0 +1,59 @@ +defmodule BobWeb do + def static_paths, do: ~w(assets) + + def router do + quote do + use Phoenix.Router, helpers: false + import Plug.Conn + import Phoenix.Controller + import Phoenix.LiveView.Router + end + end + + def controller do + quote do + use Phoenix.Controller, + formats: [:html, :json], + layouts: [html: BobWeb.Layouts] + + import Plug.Conn + unquote(verified_routes()) + end + end + + def live_view do + quote do + use Phoenix.LiveView, layout: {BobWeb.Layouts, :app} + unquote(html_helpers()) + end + end + + def html do + quote do + use Phoenix.Component + import Phoenix.Controller, only: [get_csrf_token: 0] + unquote(html_helpers()) + end + end + + defp html_helpers do + quote do + import BobWeb.CoreComponents + alias Phoenix.LiveView.JS + unquote(verified_routes()) + end + end + + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: BobWeb.Endpoint, + router: BobWeb.Router, + statics: BobWeb.static_paths() + end + end + + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/lib/bob_web/components/core_components.ex b/lib/bob_web/components/core_components.ex new file mode 100644 index 00000000..30ebcd0b --- /dev/null +++ b/lib/bob_web/components/core_components.ex @@ -0,0 +1,36 @@ +defmodule BobWeb.CoreComponents do + use Phoenix.Component + + attr(:flash, :map, default: %{}) + + def flash_group(assigns) do + ~H""" +
+ <%= kind %>: <%= message %> +
+ """ + end + + attr(:rows, :list, required: true) + + slot :col, required: true do + attr(:label, :string) + end + + def table(assigns) do + ~H""" + + + + + + + + + + + +
<%= col[:label] %>
<%= render_slot(col, row) %>
+ """ + end +end diff --git a/lib/bob_web/components/layouts.ex b/lib/bob_web/components/layouts.ex new file mode 100644 index 00000000..c171f554 --- /dev/null +++ b/lib/bob_web/components/layouts.ex @@ -0,0 +1,5 @@ +defmodule BobWeb.Layouts do + use BobWeb, :html + + embed_templates("layouts/*") +end diff --git a/lib/bob_web/components/layouts/app.html.heex b/lib/bob_web/components/layouts/app.html.heex new file mode 100644 index 00000000..46dced18 --- /dev/null +++ b/lib/bob_web/components/layouts/app.html.heex @@ -0,0 +1,2 @@ + +<%= @inner_content %> diff --git a/lib/bob_web/components/layouts/root.html.heex b/lib/bob_web/components/layouts/root.html.heex new file mode 100644 index 00000000..7f851b7a --- /dev/null +++ b/lib/bob_web/components/layouts/root.html.heex @@ -0,0 +1,25 @@ + + + + + + + Bob + + + + + +
+ <%= @inner_content %> +
+ + diff --git a/lib/bob_web/controllers/error_html.ex b/lib/bob_web/controllers/error_html.ex new file mode 100644 index 00000000..03a99172 --- /dev/null +++ b/lib/bob_web/controllers/error_html.ex @@ -0,0 +1,7 @@ +defmodule BobWeb.ErrorHTML do + use BobWeb, :html + + def render(template, _assigns) do + Phoenix.Controller.status_message_from_template(template) + end +end diff --git a/lib/bob_web/controllers/error_json.ex b/lib/bob_web/controllers/error_json.ex new file mode 100644 index 00000000..71d816d7 --- /dev/null +++ b/lib/bob_web/controllers/error_json.ex @@ -0,0 +1,5 @@ +defmodule BobWeb.ErrorJSON do + def render(template, _assigns) do + %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} + end +end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex new file mode 100644 index 00000000..03a238a0 --- /dev/null +++ b/lib/bob_web/router.ex @@ -0,0 +1,3 @@ +defmodule BobWeb.Router do + use BobWeb, :router +end From a607a4a7a2bf74ba9c0006464dd203ea5089a1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 18:59:38 +0200 Subject: [PATCH 08/24] Add /api controllers and secret plug --- .../controllers/artifact_controller.ex | 22 ++++++++++++++ lib/bob_web/controllers/queue_controller.ex | 29 +++++++++++++++++++ lib/bob_web/plugs/secret.ex | 17 +++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/bob_web/controllers/artifact_controller.ex create mode 100644 lib/bob_web/controllers/queue_controller.ex create mode 100644 lib/bob_web/plugs/secret.ex diff --git a/lib/bob_web/controllers/artifact_controller.ex b/lib/bob_web/controllers/artifact_controller.ex new file mode 100644 index 00000000..d06deb84 --- /dev/null +++ b/lib/bob_web/controllers/artifact_controller.ex @@ -0,0 +1,22 @@ +defmodule BobWeb.ArtifactController do + use BobWeb, :controller + + def add(conn, params) do + Bob.Artifacts.add(%{ + kind: params["kind"], + arch: params["arch"], + os: params["os"], + name: params["name"], + ref: params["ref"], + sha256: params["sha256"], + built_at: params["date"] + }) + + send_resp(conn, 204, "") + end + + def add_docker(conn, params) do + Bob.Artifacts.add_docker_tag(params.repo, params.tag, params.archs) + send_resp(conn, 204, "") + end +end diff --git a/lib/bob_web/controllers/queue_controller.ex b/lib/bob_web/controllers/queue_controller.ex new file mode 100644 index 00000000..151a065a --- /dev/null +++ b/lib/bob_web/controllers/queue_controller.ex @@ -0,0 +1,29 @@ +defmodule BobWeb.QueueController do + use BobWeb, :controller + + def start(conn, params) do + jobs = + params.jobs + |> Bob.RemoteQueue.prioritize() + |> Bob.RemoteQueue.start_jobs(params.max_weight, params.weights) + + conn + |> put_resp_header("content-type", "application/vnd.bob+erlang") + |> send_resp(200, Bob.Plug.ErlangFormat.encode_to_iodata!(%{jobs: jobs})) + end + + def success(conn, params) do + Bob.Queue.success(params.id) + send_resp(conn, 204, "") + end + + def failure(conn, params) do + Bob.Queue.failure(params.id) + send_resp(conn, 204, "") + end + + def add(conn, params) do + Bob.Queue.add(params.module, params.args) + send_resp(conn, 204, "") + end +end diff --git a/lib/bob_web/plugs/secret.ex b/lib/bob_web/plugs/secret.ex new file mode 100644 index 00000000..6a5dd673 --- /dev/null +++ b/lib/bob_web/plugs/secret.ex @@ -0,0 +1,17 @@ +defmodule BobWeb.Plugs.Secret do + import Plug.Conn + + def init(opts), do: opts + + def call(conn, _opts) do + secret = Application.get_env(:bob, :agent_secret) + + if get_req_header(conn, "authorization") == [secret] do + conn + else + conn + |> send_resp(401, "") + |> halt() + end + end +end From a21957255e102db0216af90fb9cb96af5dd1e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:06:16 +0200 Subject: [PATCH 09/24] Replace Plug.Cowboy/Bob.Router with BobWeb.Endpoint and /api controllers --- lib/bob/application.ex | 10 +-- lib/bob/router.ex | 86 ------------------- lib/bob_web/endpoint.ex | 42 +++++++++ lib/bob_web/router.ex | 24 ++++++ mix.exs | 1 - mix.lock | 5 -- .../controllers/api_test.exs} | 57 +++++++----- test/support/conn_case.ex | 23 +++++ 8 files changed, 127 insertions(+), 121 deletions(-) delete mode 100644 lib/bob/router.ex create mode 100644 lib/bob_web/endpoint.ex rename test/{bob/router_test.exs => bob_web/controllers/api_test.exs} (58%) create mode 100644 test/support/conn_case.ex diff --git a/lib/bob/application.ex b/lib/bob/application.ex index ce3e2e85..65b26aab 100644 --- a/lib/bob/application.ex +++ b/lib/bob/application.ex @@ -21,7 +21,7 @@ defmodule Bob.Application do Bob.DockerHub.Auth, runner_spec(), {Bob.Schedule, [schedule()]}, - {Plug.Cowboy, scheme: :http, plug: Bob.Router, options: [port: port(), compress: true]} + BobWeb.Endpoint ] opts = [strategy: :one_for_one, name: Bob.Supervisor] @@ -42,14 +42,6 @@ defmodule Bob.Application do defp maintenance_children(), do: [Bob.Queue.Maintenance] end - defp port() do - if port = System.get_env("BOB_PORT") do - String.to_integer(port) - else - 4003 - end - end - defp setup_docker() do if config = System.get_env("BOB_DOCKER_CONFIG") do config = fix_env_newlines(config) diff --git a/lib/bob/router.ex b/lib/bob/router.ex deleted file mode 100644 index 275376c6..00000000 --- a/lib/bob/router.ex +++ /dev/null @@ -1,86 +0,0 @@ -defmodule Bob.Router do - use Plug.Router - use Sentry.PlugCapture - - import Plug.Conn - - plug(Bob.Plug.Forwarded) - plug(Bob.Plug.Status) - # TODO: SSL? - - plug(Plug.RequestId) - plug(Logster.Plugs.Logger, excludes: [:params]) - - plug(:secret) - - plug(Plug.Parsers, - pass: ["application/json", "application/vnd.bob+erlang"], - parsers: [:json, Bob.Plug.Parser], - json_decoder: JSON - ) - - plug(Sentry.PlugContext) - plug(:match) - plug(:dispatch) - - post "queue/start" do - jobs = - conn.params.jobs - |> Bob.RemoteQueue.prioritize() - |> Bob.RemoteQueue.start_jobs(conn.params.max_weight, conn.params.weights) - - conn - |> put_resp_header("content-type", "application/vnd.bob+erlang") - |> send_resp(200, Bob.Plug.ErlangFormat.encode_to_iodata!(%{jobs: jobs})) - end - - post "queue/success" do - Bob.Queue.success(conn.params.id) - send_resp(conn, 204, "") - end - - post "queue/failure" do - Bob.Queue.failure(conn.params.id) - send_resp(conn, 204, "") - end - - post "queue/add" do - Bob.Queue.add(conn.params.module, conn.params.args) - send_resp(conn, 204, "") - end - - post "artifacts/add" do - Bob.Artifacts.add(%{ - kind: conn.params["kind"], - arch: conn.params["arch"], - os: conn.params["os"], - name: conn.params["name"], - ref: conn.params["ref"], - sha256: conn.params["sha256"], - built_at: conn.params["date"] - }) - - send_resp(conn, 204, "") - end - - post "docker/add" do - Bob.Artifacts.add_docker_tag(conn.params.repo, conn.params.tag, conn.params.archs) - send_resp(conn, 204, "") - end - - match _ do - send_resp(conn, 404, "") - end - - defp secret(conn, _opts) do - secret = Application.get_env(:bob, :agent_secret) - - if get_req_header(conn, "authorization") == [secret] do - conn - else - conn - |> send_resp(401, "") - |> halt() - end - end -end diff --git a/lib/bob_web/endpoint.ex b/lib/bob_web/endpoint.ex new file mode 100644 index 00000000..83fc785c --- /dev/null +++ b/lib/bob_web/endpoint.ex @@ -0,0 +1,42 @@ +defmodule BobWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :bob + use Sentry.PlugCapture + + @session_options [ + store: :cookie, + key: "_bob_key", + signing_salt: "9kLm2Qx7", + same_site: "Lax" + ] + + socket("/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]) + + plug(Bob.Plug.Forwarded) + plug(Bob.Plug.Status) + + plug(Plug.Static, + at: "/", + from: :bob, + gzip: true, + only: BobWeb.static_paths() + ) + + if code_reloading? do + socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket) + plug(Phoenix.LiveReloader) + plug(Phoenix.CodeReloader) + end + + plug(Plug.RequestId) + plug(Logster.Plugs.Logger, excludes: [:params]) + + plug(Plug.Parsers, + parsers: [:json, Bob.Plug.Parser], + pass: ["application/json", "application/vnd.bob+erlang"], + json_decoder: JSON + ) + + plug(Sentry.PlugContext) + plug(Plug.Session, @session_options) + plug(BobWeb.Router) +end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex index 03a238a0..6d6bd40d 100644 --- a/lib/bob_web/router.ex +++ b/lib/bob_web/router.ex @@ -1,3 +1,27 @@ defmodule BobWeb.Router do use BobWeb, :router + + pipeline :browser do + plug(:accepts, ["html"]) + plug(:fetch_session) + plug(:fetch_live_flash) + plug(:put_root_layout, html: {BobWeb.Layouts, :root}) + plug(:protect_from_forgery) + plug(:put_secure_browser_headers) + end + + pipeline :api do + plug(BobWeb.Plugs.Secret) + end + + scope "/api", BobWeb do + pipe_through(:api) + + post("/queue/start", QueueController, :start) + post("/queue/success", QueueController, :success) + post("/queue/failure", QueueController, :failure) + post("/queue/add", QueueController, :add) + post("/artifacts/add", ArtifactController, :add) + post("/docker/add", ArtifactController, :add_docker) + end end diff --git a/mix.exs b/mix.exs index 22d9fdf3..f210f2b1 100644 --- a/mix.exs +++ b/mix.exs @@ -30,7 +30,6 @@ defmodule Bob.Mixfile do {:ex_aws_s3, "~> 2.0"}, {:finch, "~> 0.19"}, {:req, "~> 0.5"}, - {:plug_cowboy, "~> 2.0"}, {:porcelain, "~> 2.0"}, {:postgrex, "~> 0.19"}, {:sentry, "~> 10.2"}, diff --git a/mix.lock b/mix.lock index 89d39723..4cb40e72 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,5 @@ %{ "bandit": {:hex, :bandit, "1.12.0", "6c5214daa2469644ac4ab0113b98abc24f75e348378e6a974c6343b3e5da22ef", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.5", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "45dac82dc86f45cf4a196dee9cc5a8b791d9c9469d996055f055e6ee36c66e20"}, - "cowboy": {:hex, :cowboy, "2.13.0", "09d770dd5f6a22cc60c071f432cd7cb87776164527f205c5a6b0f24ff6b38990", [:make, :rebar3], [{:cowlib, ">= 2.14.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "e724d3a70995025d654c1992c7b11dbfea95205c047d86ff9bf1cda92ddc5614"}, - "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, - "cowlib": {:hex, :cowlib, "2.15.0", "3c97a318a933962d1c12b96ab7c1d728267d2c523c25a5b57b0f93392b6e9e25", [:make, :rebar3], [], "hexpm", "4f00c879a64b4fe7c8fcb42a4281925e9ffdb928820b03c3ad325a617e857532"}, "db_connection": {:hex, :db_connection, "2.10.1", "d5465f6bcc125c1b8981c1dbf23c193ca16f446ec0b25832dc174f74f18be510", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "18ed94c6e627b4bf452dbd4df61b69a35a1e768525140bc1917b7a685026a6a3"}, "decimal": {:hex, :decimal, "2.4.1", "6c0fbede12fb122ba685e9ab41c6a40c129e322b3aa192f9e072e61f3a6ffaf2", [:mix], [], "hexpm", "7e618897933a8455f19a727d7c5e50a2c071a544b700e5e724298ecb4340187f"}, "ecto": {:hex, :ecto, "3.13.6", "352135b474f91d1ab99a1b502171d207e9db60421c9e3d0ecab4c7ab96b24d14", [:mix], [{:decimal, "~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8afa059bc16cd2c94739ec0a11e3e5df69d828125119109bef35f20a21a76af2"}, @@ -29,11 +26,9 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"}, - "plug_cowboy": {:hex, :plug_cowboy, "2.7.4", "729c752d17cf364e2b8da5bdb34fb5804f56251e88bb602aff48ae0bd8673d11", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9b85632bd7012615bae0a5d70084deb1b25d2bcbb32cab82d1e9a1e023168aa3"}, "plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"}, "porcelain": {:hex, :porcelain, "2.0.3", "2d77b17d1f21fed875b8c5ecba72a01533db2013bd2e5e62c6d286c029150fdc", [:mix], [], "hexpm", "dc996ab8fadbc09912c787c7ab8673065e50ea1a6245177b0c24569013d23620"}, "postgrex": {:hex, :postgrex, "0.22.2", "4aec14df2a72722aee92492566edbeeb44e233ecb86b1915d03136297ef1385d", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8946382ddb06294f56026ac4278b3cc212bac8a2c82ed68b4087819ed1abc53b"}, - "ranch": {:hex, :ranch, "2.2.0", "25528f82bc8d7c6152c57666ca99ec716510fe0925cb188172f41ce93117b1b0", [:make, :rebar3], [], "hexpm", "fa0b99a1780c80218a4197a59ea8d3bdae32fbff7e88527d7d8a4787eff4f8e7"}, "recon": {:hex, :recon, "2.5.6", "9052588e83bfedfd9b72e1034532aee2a5369d9d9343b61aeb7fbce761010741", [:mix, :rebar3], [], "hexpm", "96c6799792d735cc0f0fd0f86267e9d351e63339cbe03df9d162010cefc26bb0"}, "req": {:hex, :req, "0.6.0", "85dec26488ea23e29b4b516dc1fb9615b2f6f32fe824980d1adc9d79d44a83fd", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21.0 or ~> 0.22.0", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "f90e15671bfcc0c40ba26aaf825c47aec3f8b4f14f54a41bdd14e255fb67118e"}, "sentry": {:hex, :sentry, "10.10.0", "d058b635f3796947545c8057a42996f6dbefd12152da947209b56d16af41b161", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7c7ddd3cfdd63fcee53b1e28f9a653037e6927b2b1dbd300b7aeee9687c7a8f6"}, diff --git a/test/bob/router_test.exs b/test/bob_web/controllers/api_test.exs similarity index 58% rename from test/bob/router_test.exs rename to test/bob_web/controllers/api_test.exs index 9ce23348..5333f26b 100644 --- a/test/bob/router_test.exs +++ b/test/bob_web/controllers/api_test.exs @@ -1,14 +1,9 @@ -defmodule Bob.RouterTest do - use Bob.DataCase - - import Plug.Test - import Plug.Conn +defmodule BobWeb.ApiTest do + use BobWeb.ConnCase alias Bob.Artifacts alias Bob.Artifacts.Artifact - @opts Bob.Router.init([]) - setup do Bob.FakeHttpClient.reset() Application.put_env(:bob, :agent_secret, "secret") @@ -16,7 +11,7 @@ defmodule Bob.RouterTest do :ok end - defp body() do + defp artifact_body() do JSON.encode!(%{ kind: "otp", arch: "amd64", @@ -28,7 +23,7 @@ defmodule Bob.RouterTest do }) end - test "POST /artifacts/add upserts an artifact and returns 204" do + test "POST /api/artifacts/add upserts an artifact and returns 204", %{conn: conn} do Bob.FakeHttpClient.stub( :put, "https://s3.amazonaws.com/s3.hex.pm/builds/otp/amd64/ubuntu-24.04/builds.txt", @@ -37,10 +32,10 @@ defmodule Bob.RouterTest do ) conn = - conn(:post, "/artifacts/add", body()) + conn |> put_req_header("content-type", "application/json") |> put_req_header("authorization", "secret") - |> Bob.Router.call(@opts) + |> post(~p"/api/artifacts/add", artifact_body()) assert conn.status == 204 @@ -48,17 +43,17 @@ defmodule Bob.RouterTest do Repo.all(Artifact) end - test "POST /artifacts/add rejects a missing/wrong secret with 401" do + test "POST /api/artifacts/add rejects a missing secret with 401", %{conn: conn} do conn = - conn(:post, "/artifacts/add", body()) + conn |> put_req_header("content-type", "application/json") - |> Bob.Router.call(@opts) + |> post(~p"/api/artifacts/add", artifact_body()) assert conn.status == 401 assert Repo.all(Artifact) == [] end - test "POST /docker/add upserts a docker tag and returns 204" do + test "POST /api/docker/add upserts a docker tag and returns 204", %{conn: conn} do body = Bob.Plug.ErlangFormat.encode_to_iodata!(%{ repo: "hexpm/erlang-amd64", @@ -67,10 +62,10 @@ defmodule Bob.RouterTest do }) conn = - conn(:post, "/docker/add", body) + conn |> put_req_header("content-type", "application/vnd.bob+erlang") |> put_req_header("authorization", "secret") - |> Bob.Router.call(@opts) + |> post(~p"/api/docker/add", body) assert conn.status == 204 @@ -78,7 +73,7 @@ defmodule Bob.RouterTest do [{"27.0-ubuntu-noble-20250101", ["amd64"]}] end - test "POST /docker/add rejects a missing/wrong secret with 401" do + test "POST /api/docker/add rejects a missing secret with 401", %{conn: conn} do body = Bob.Plug.ErlangFormat.encode_to_iodata!(%{ repo: "hexpm/erlang-amd64", @@ -87,11 +82,33 @@ defmodule Bob.RouterTest do }) conn = - conn(:post, "/docker/add", body) + conn |> put_req_header("content-type", "application/vnd.bob+erlang") - |> Bob.Router.call(@opts) + |> post(~p"/api/docker/add", body) assert conn.status == 401 assert Artifacts.docker_tags("hexpm/erlang-amd64") == [] end + + test "POST /api/queue/add with erlang body enqueues a job (atom-keyed params)", %{conn: conn} do + body = + Bob.Plug.ErlangFormat.encode_to_iodata!(%{ + module: Bob.Job.OTPChecker, + args: [:tags] + }) + + conn = + conn + |> put_req_header("content-type", "application/vnd.bob+erlang") + |> put_req_header("authorization", "secret") + |> post(~p"/api/queue/add", body) + + assert conn.status == 204 + assert [{Bob.Job.OTPChecker, [:tags]}] = Bob.Queue.queued() + end + + test "GET /status still returns 200 at the root", %{conn: conn} do + conn = get(conn, "/status") + assert conn.status == 200 + end end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex new file mode 100644 index 00000000..822706ee --- /dev/null +++ b/test/support/conn_case.ex @@ -0,0 +1,23 @@ +defmodule BobWeb.ConnCase do + use ExUnit.CaseTemplate + + using do + quote do + use BobWeb, :verified_routes + + import Plug.Conn + import Phoenix.ConnTest + import BobWeb.ConnCase + + alias Bob.Repo + + @endpoint BobWeb.Endpoint + end + end + + setup tags do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Bob.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + {:ok, conn: Phoenix.ConnTest.build_conn()} + end +end From 1ccbe5f650b8fa5456dbc61b66d9c4699d7ada7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:12:30 +0200 Subject: [PATCH 10/24] Point agent API callers at /api routes --- lib/bob/remote_queue.ex | 8 ++++---- priv/scripts/otp/otp.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bob/remote_queue.ex b/lib/bob/remote_queue.ex index 3864d306..29f21772 100644 --- a/lib/bob/remote_queue.ex +++ b/lib/bob/remote_queue.ex @@ -1,10 +1,10 @@ defmodule Bob.RemoteQueue do def add(module, args) do - request("/queue/add", %{module: module, args: args}) + request("/api/queue/add", %{module: module, args: args}) end def docker_add(repo, tag, archs) do - request("/docker/add", %{repo: repo, tag: tag, archs: archs}) + request("/api/docker/add", %{repo: repo, tag: tag, archs: archs}) end def success({:local, id}) do @@ -81,7 +81,7 @@ defmodule Bob.RemoteQueue do defp apply_job(module, fun, args), do: apply(module, fun, args) defp done_request(type, id) do - request("/queue/#{type}", %{id: id}) + request("/api/queue/#{type}", %{id: id}) :ok end @@ -91,7 +91,7 @@ defmodule Bob.RemoteQueue do defp start_request(remote_jobs, max_weight, weights) do {:ok, %{jobs: jobs}} = - request("/queue/start", %{jobs: remote_jobs, max_weight: max_weight, weights: weights}) + request("/api/queue/start", %{jobs: remote_jobs, max_weight: max_weight, weights: weights}) jobs end diff --git a/priv/scripts/otp/otp.sh b/priv/scripts/otp/otp.sh index f92c6d56..0e778813 100755 --- a/priv/scripts/otp/otp.sh +++ b/priv/scripts/otp/otp.sh @@ -49,4 +49,4 @@ curl \ -H "authorization: ${BOB_AGENT_SECRET}" \ -H "content-type: application/json" \ -d "{\"kind\":\"otp\",\"arch\":\"${arch}\",\"os\":\"${linux}\",\"name\":\"${ref_name}\",\"ref\":\"${ref}\",\"sha256\":\"${build_sha256}\",\"date\":\"${date}\"}" \ - "${BOB_MASTER_URL}/artifacts/add" + "${BOB_MASTER_URL}/api/artifacts/add" From 49db2d414fecc6dfa5ad8f222251ea171ea2b66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:17:36 +0200 Subject: [PATCH 11/24] Add JobsLive with running/queued/past views and live refresh --- config/test.exs | 2 +- lib/bob_web/live/jobs_live.ex | 138 +++++++++++++++++++++++++++ lib/bob_web/router.ex | 6 ++ mix.exs | 2 +- mix.lock | 5 +- test/bob_web/live/jobs_live_test.exs | 38 ++++++++ test/support/conn_case.ex | 7 +- 7 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 lib/bob_web/live/jobs_live.ex create mode 100644 test/bob_web/live/jobs_live_test.exs diff --git a/config/test.exs b/config/test.exs index 41f09b20..f43b4b78 100644 --- a/config/test.exs +++ b/config/test.exs @@ -21,5 +21,5 @@ config :bob, Bob.Repo, config :bob, BobWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4002], - secret_key_base: "tT9wQ2eR5yU8iO1pA4sD7fG0hJ3kL6zX9cV2bN5mQ8wE1rT4yU7iO0pA3sD6fG9", + secret_key_base: "tT9wQ2eR5yU8iO1pA4sD7fG0hJ3kL6zX9cV2bN5mQ8wE1rT4yU7iO0pA3sD6fG90", server: false diff --git a/lib/bob_web/live/jobs_live.ex b/lib/bob_web/live/jobs_live.ex new file mode 100644 index 00000000..65e11494 --- /dev/null +++ b/lib/bob_web/live/jobs_live.ex @@ -0,0 +1,138 @@ +defmodule BobWeb.JobsLive do + use BobWeb, :live_view + + @queued_page 100 + @past_page 50 + @debounce_ms 250 + + @impl true + def mount(_params, _session, socket) do + if connected?(socket), do: Phoenix.PubSub.subscribe(Bob.PubSub, "jobs") + + socket = + socket + |> assign( + queued_offset: 0, + past_offset: 0, + refresh_scheduled: false, + queued_page: @queued_page, + past_page: @past_page + ) + |> load() + + {:ok, socket} + end + + @impl true + def handle_info(:jobs_changed, %{assigns: %{refresh_scheduled: true}} = socket) do + {:noreply, socket} + end + + def handle_info(:jobs_changed, socket) do + Process.send_after(self(), :refresh, @debounce_ms) + {:noreply, assign(socket, refresh_scheduled: true)} + end + + def handle_info(:refresh, socket) do + {:noreply, socket |> assign(refresh_scheduled: false) |> load()} + end + + @impl true + def handle_event("queued_page", %{"dir" => dir}, socket) do + offset = max(socket.assigns.queued_offset + step(dir, @queued_page), 0) + {:noreply, socket |> assign(queued_offset: offset) |> load()} + end + + def handle_event("past_page", %{"dir" => dir}, socket) do + offset = max(socket.assigns.past_offset + step(dir, @past_page), 0) + {:noreply, socket |> assign(past_offset: offset) |> load()} + end + + defp step("next", page), do: page + defp step("prev", page), do: -page + + defp load(socket) do + assign(socket, + running: Bob.Queue.running(), + queue_sizes: Enum.sort(Bob.Queue.queue_sizes()), + queued: Bob.Queue.queued_listing(@queued_page, socket.assigns.queued_offset), + past: Bob.Queue.recent(@past_page, socket.assigns.past_offset) + ) + end + + defp fmt(nil), do: "—" + defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + + @impl true + def render(assigns) do + ~H""" +
+
+

Running (<%= length(@running) %>)

+ <.table :if={@running != []} rows={@running}> + <:col :let={j} label="Module"><%= inspect(j.module_key) %> + <:col :let={j} label="Args"><%= inspect(j.args) %> + <:col :let={j} label="Started"><%= fmt(j.started_at) %> + +

Nothing running.

+
+ +
+

Queue

+
    +
  • + <%= inspect(mod) %> — <%= count %> +
  • +
+ <.table :if={@queued != []} rows={@queued}> + <:col :let={j} label="Module"><%= inspect(j.module_key) %> + <:col :let={j} label="Args"><%= inspect(j.args) %> + <:col :let={j} label="Queued"><%= fmt(j.inserted_at) %> + +

Queue is empty.

+ <.pager event="queued_page" offset={@queued_offset} count={length(@queued)} page={@queued_page} /> +
+ +
+

Past

+ <.table :if={@past != []} rows={@past}> + <:col :let={j} label="State"><%= j.state %> + <:col :let={j} label="Module"><%= inspect(j.module_key) %> + <:col :let={j} label="Args"><%= inspect(j.args) %> + <:col :let={j} label="Finished"><%= fmt(j.finished_at) %> + +

No finished jobs.

+ <.pager event="past_page" offset={@past_offset} count={length(@past)} page={@past_page} /> +
+
+ """ + end + + attr(:event, :string, required: true) + attr(:offset, :integer, required: true) + attr(:count, :integer, required: true) + attr(:page, :integer, required: true) + + defp pager(assigns) do + ~H""" +
+ + +
+ """ + end +end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex index 6d6bd40d..ae9c7d01 100644 --- a/lib/bob_web/router.ex +++ b/lib/bob_web/router.ex @@ -24,4 +24,10 @@ defmodule BobWeb.Router do post("/artifacts/add", ArtifactController, :add) post("/docker/add", ArtifactController, :add_docker) end + + scope "/", BobWeb do + pipe_through(:browser) + + live("/", JobsLive) + end end diff --git a/mix.exs b/mix.exs index f210f2b1..a4d1a2b3 100644 --- a/mix.exs +++ b/mix.exs @@ -44,7 +44,7 @@ defmodule Bob.Mixfile do {:bandit, "~> 1.5"}, {:esbuild, "~> 0.8", runtime: Mix.env() == :dev}, {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, - {:floki, ">= 0.30.0", only: :test} + {:lazy_html, ">= 0.1.0", only: :test} ] end diff --git a/mix.lock b/mix.lock index 4cb40e72..4e543b87 100644 --- a/mix.lock +++ b/mix.lock @@ -1,17 +1,20 @@ %{ "bandit": {:hex, :bandit, "1.12.0", "6c5214daa2469644ac4ab0113b98abc24f75e348378e6a974c6343b3e5da22ef", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.5", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "45dac82dc86f45cf4a196dee9cc5a8b791d9c9469d996055f055e6ee36c66e20"}, + "cc_precompiler": {:hex, :cc_precompiler, "0.1.11", "8c844d0b9fb98a3edea067f94f616b3f6b29b959b6b3bf25fee94ffe34364768", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "3427232caf0835f94680e5bcf082408a70b48ad68a5f5c0b02a3bea9f3a075b9"}, "db_connection": {:hex, :db_connection, "2.10.1", "d5465f6bcc125c1b8981c1dbf23c193ca16f446ec0b25832dc174f74f18be510", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "18ed94c6e627b4bf452dbd4df61b69a35a1e768525140bc1917b7a685026a6a3"}, "decimal": {:hex, :decimal, "2.4.1", "6c0fbede12fb122ba685e9ab41c6a40c129e322b3aa192f9e072e61f3a6ffaf2", [:mix], [], "hexpm", "7e618897933a8455f19a727d7c5e50a2c071a544b700e5e724298ecb4340187f"}, "ecto": {:hex, :ecto, "3.13.6", "352135b474f91d1ab99a1b502171d207e9db60421c9e3d0ecab4c7ab96b24d14", [:mix], [{:decimal, "~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8afa059bc16cd2c94739ec0a11e3e5df69d828125119109bef35f20a21a76af2"}, "ecto_sql": {:hex, :ecto_sql, "3.13.5", "2f8282b2ad97bf0f0d3217ea0a6fff320ead9e2f8770f810141189d182dc304e", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aa36751f4e6a2b56ae79efb0e088042e010ff4935fc8684e74c23b1f49e25fdc"}, + "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, "esbuild": {:hex, :esbuild, "0.10.0", "b0aa3388a1c23e727c5a3e7427c932d89ee791746b0081bbe56103e9ef3d291f", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "468489cda427b974a7cc9f03ace55368a83e1a7be12fba7e30969af78e5f8c70"}, "ex_aws": {:hex, :ex_aws, "2.5.10", "d3f8ca8959dad6533a2a934dfdf380df1b1bef425feeb215a47a5176dee8736c", [:mix], [{:configparser_ex, "~> 5.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "88fcd9cc1b2e0fcea65106bdaa8340ac56c6e29bf72f46cf7ef174027532d3da"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.5.7", "e571424d2f345299753382f3a01b005c422b1a460a8bc3ed47659b3d3ef91e9e", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "858e51241e50181e29aa2bc128fef548873a3a9cd580471f57eda5b64dec937f"}, "file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"}, "finch": {:hex, :finch, "0.22.0", "5c48fa6f9706a78eb9036cacb67b8b996b4e66d111c543f4c29bb0f879a6806b", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b94e83c47780fc6813f746a1f1a34ee65cda42da4c5ea26a68f0acc4498e23dc"}, - "floki": {:hex, :floki, "0.38.3", "40d291831d93f49aa360f09447cf2e2a902e33d8711e5fb22a75f3f333e9d063", [:mix], [], "hexpm", "025aa1f5f24a70cb31bfbc7011419228596f3b062d7feda617238ba4926f83cb"}, + "fine": {:hex, :fine, "0.1.6", "4bf7151493443c454aac9f2fa2f34f5fefd0346a83fb5586a016c4a135c63247", [:mix], [], "hexpm", "5638eb4495488e885ebec167fa57973e5c35e1a50c344eb7666c90ec1c4e3b12"}, "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "lazy_html": {:hex, :lazy_html, "0.1.11", "136c8e9cd616b4f4e9c1562daa683880891120b759606dc4c3b6b18058ba5d79", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "3b1be592929c31eca1a21673d25696e5c14cddfe922d9d1a3e3b48be4163883b"}, "logster": {:hex, :logster, "1.1.1", "d6fddac540dd46adde0c894024500867fe63b0043713f842c62da5815e21db10", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d18e852c430812ad1c9756998ebe46ec814c724e6eb551a512d7e3f8dee24cef"}, "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"}, "mint": {:hex, :mint, "1.9.0", "d6f534c2a3e98b2a8cc749b4796eb77e9e3af79a76f96e4c74035a827de0d318", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "007154c7d8c43916aed3c93afd1f11aebbaa9c5ff4b7ba55ebe0d17ee0296042"}, diff --git a/test/bob_web/live/jobs_live_test.exs b/test/bob_web/live/jobs_live_test.exs new file mode 100644 index 00000000..455d0792 --- /dev/null +++ b/test/bob_web/live/jobs_live_test.exs @@ -0,0 +1,38 @@ +defmodule BobWeb.JobsLiveTest do + use BobWeb.ConnCase + + import Phoenix.LiveViewTest + + @debounce_pause 400 + + test "renders running, queued, and past jobs", %{conn: conn} do + Bob.Queue.add(Bob.Job.OTPChecker, [:queued]) + + Bob.Queue.add(Bob.Job.OTPChecker, [:running]) + {:ok, _} = Bob.Queue.start(Bob.Job.OTPChecker) + + Bob.Queue.add(Bob.Job.OTPChecker, [:done]) + {:ok, {id, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + Bob.Queue.success(id) + + {:ok, _view, html} = live(conn, ~p"/") + + assert html =~ "Running" + assert html =~ "Queue" + assert html =~ "Past" + assert html =~ "OTPChecker" + assert html =~ "done" + end + + test "refreshes when a :jobs_changed broadcast arrives", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/") + refute render(view) =~ ":refreshed" + + Bob.Queue.add(Bob.Job.OTPChecker, [:refreshed]) + {:ok, _} = Bob.Queue.start(Bob.Job.OTPChecker) + + # The add/start broadcasts :jobs_changed; the view reloads after the debounce window. + Process.sleep(@debounce_pause) + assert render(view) =~ ":refreshed" + end +end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 822706ee..21ef3ed2 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -18,6 +18,11 @@ defmodule BobWeb.ConnCase do setup tags do pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Bob.Repo, shared: not tags[:async]) on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) - {:ok, conn: Phoenix.ConnTest.build_conn()} + + conn = + Phoenix.ConnTest.build_conn() + |> Map.put(:secret_key_base, BobWeb.Endpoint.config(:secret_key_base)) + + {:ok, conn: conn} end end From a49ea3c849ed179513906300e7d54c810b23391a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:25:10 +0200 Subject: [PATCH 12/24] Add ArtifactsLive search page --- lib/bob_web/live/artifacts_live.ex | 110 ++++++++++++++++++++++ lib/bob_web/router.ex | 1 + test/bob_web/live/artifacts_live_test.exs | 49 ++++++++++ 3 files changed, 160 insertions(+) create mode 100644 lib/bob_web/live/artifacts_live.ex create mode 100644 test/bob_web/live/artifacts_live_test.exs diff --git a/lib/bob_web/live/artifacts_live.ex b/lib/bob_web/live/artifacts_live.ex new file mode 100644 index 00000000..c02413fe --- /dev/null +++ b/lib/bob_web/live/artifacts_live.ex @@ -0,0 +1,110 @@ +defmodule BobWeb.ArtifactsLive do + use BobWeb, :live_view + + @page 100 + + @impl true + def mount(_params, _session, socket) do + socket = + socket + |> assign( + query: "", + kind: "", + arch: "", + os: "", + offset: 0, + page: @page, + kinds: Bob.Artifacts.distinct_kinds(), + arches: Bob.Artifacts.distinct_arches(), + oses: Bob.Artifacts.distinct_oses() + ) + |> load() + + {:ok, socket} + end + + @impl true + def handle_event("search", params, socket) do + socket = + socket + |> assign( + query: params["query"] || "", + kind: params["kind"] || "", + arch: params["arch"] || "", + os: params["os"] || "", + offset: 0 + ) + |> load() + + {:noreply, socket} + end + + def handle_event("page", %{"dir" => dir}, socket) do + offset = max(socket.assigns.offset + step(dir), 0) + {:noreply, socket |> assign(offset: offset) |> load()} + end + + defp step("next"), do: @page + defp step("prev"), do: -@page + + defp load(socket) do + %{query: q, kind: kind, arch: arch, os: os, offset: offset} = socket.assigns + + results = + Bob.Artifacts.search_artifacts( + %{query: q, kind: kind, arch: arch, os: os}, + @page, + offset + ) + + assign(socket, results: results) + end + + defp fmt(nil), do: "—" + defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + + @impl true + def render(assigns) do + ~H""" +

Build artifacts

+ +
+ + + + +
+ + <.table :if={@results != []} rows={@results}> + <:col :let={a} label="kind"><%= a.kind %> + <:col :let={a} label="arch"><%= a.arch %> + <:col :let={a} label="os"><%= a.os %> + <:col :let={a} label="name"><%= a.name %> + <:col :let={a} label="ref"><%= a.ref %> + <:col :let={a} label="sha256"><%= a.sha256 %> + <:col :let={a} label="built"><%= fmt(a.built_at) %> + +

No matching artifacts.

+ +
+ + +
+ """ + end +end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex index ae9c7d01..6bb8f15f 100644 --- a/lib/bob_web/router.ex +++ b/lib/bob_web/router.ex @@ -29,5 +29,6 @@ defmodule BobWeb.Router do pipe_through(:browser) live("/", JobsLive) + live("/artifacts", ArtifactsLive) end end diff --git a/test/bob_web/live/artifacts_live_test.exs b/test/bob_web/live/artifacts_live_test.exs new file mode 100644 index 00000000..b00b5414 --- /dev/null +++ b/test/bob_web/live/artifacts_live_test.exs @@ -0,0 +1,49 @@ +defmodule BobWeb.ArtifactsLiveTest do + use BobWeb.ConnCase + + import Phoenix.LiveViewTest + + setup do + Bob.Artifacts.upsert(%{ + kind: "otp", + arch: "amd64", + os: "ubuntu-24.04", + name: "OTP-27.0", + ref: "aaa", + built_at: ~U[2026-01-01 00:00:00Z] + }) + + Bob.Artifacts.upsert(%{ + kind: "otp", + arch: "arm64", + os: "ubuntu-22.04", + name: "OTP-26.2", + ref: "bbb", + built_at: ~U[2026-02-01 00:00:00Z] + }) + + :ok + end + + test "lists artifacts and filters by free-text", %{conn: conn} do + {:ok, view, html} = live(conn, ~p"/artifacts") + assert html =~ "OTP-27.0" + assert html =~ "OTP-26.2" + + html = + render_change(view, "search", %{"query" => "27.0", "kind" => "", "arch" => "", "os" => ""}) + + assert html =~ "OTP-27.0" + refute html =~ "OTP-26.2" + end + + test "filters by arch dropdown", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/artifacts") + + html = + render_change(view, "search", %{"query" => "", "kind" => "", "arch" => "arm64", "os" => ""}) + + assert html =~ "OTP-26.2" + refute html =~ "OTP-27.0" + end +end From 0c5cbb208592d91e73b6fe55e5a49f34f3fb27ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:29:25 +0200 Subject: [PATCH 13/24] Add DockerTagsLive search page --- lib/bob_web/live/docker_tags_live.ex | 82 +++++++++++++++++++++ lib/bob_web/router.ex | 1 + test/bob_web/live/docker_tags_live_test.exs | 28 +++++++ 3 files changed, 111 insertions(+) create mode 100644 lib/bob_web/live/docker_tags_live.ex create mode 100644 test/bob_web/live/docker_tags_live_test.exs diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex new file mode 100644 index 00000000..d5179a86 --- /dev/null +++ b/lib/bob_web/live/docker_tags_live.ex @@ -0,0 +1,82 @@ +defmodule BobWeb.DockerTagsLive do + use BobWeb, :live_view + + @page 100 + + @impl true + def mount(_params, _session, socket) do + socket = + socket + |> assign( + query: "", + repo: "", + offset: 0, + page: @page, + repos: Bob.Artifacts.distinct_repos() + ) + |> load() + + {:ok, socket} + end + + @impl true + def handle_event("search", params, socket) do + socket = + socket + |> assign(query: params["query"] || "", repo: params["repo"] || "", offset: 0) + |> load() + + {:noreply, socket} + end + + def handle_event("page", %{"dir" => dir}, socket) do + offset = max(socket.assigns.offset + step(dir), 0) + {:noreply, socket |> assign(offset: offset) |> load()} + end + + defp step("next"), do: @page + defp step("prev"), do: -@page + + defp load(socket) do + %{query: q, repo: repo, offset: offset} = socket.assigns + results = Bob.Artifacts.search_docker_tags(%{query: q, repo: repo}, @page, offset) + assign(socket, results: results) + end + + defp fmt(nil), do: "—" + defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + + @impl true + def render(assigns) do + ~H""" +

Docker tags

+ +
+ + +
+ + <.table :if={@results != []} rows={@results}> + <:col :let={d} label="repo"><%= d.repo %> + <:col :let={d} label="tag"><%= d.tag %> + <:col :let={d} label="archs"><%= Enum.join(d.archs, ", ") %> + <:col :let={d} label="built"><%= fmt(d.built_at) %> + +

No matching tags.

+ +
+ + +
+ """ + end +end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex index 6bb8f15f..1a802849 100644 --- a/lib/bob_web/router.ex +++ b/lib/bob_web/router.ex @@ -30,5 +30,6 @@ defmodule BobWeb.Router do live("/", JobsLive) live("/artifacts", ArtifactsLive) + live("/docker", DockerTagsLive) end end diff --git a/test/bob_web/live/docker_tags_live_test.exs b/test/bob_web/live/docker_tags_live_test.exs new file mode 100644 index 00000000..e6deedcb --- /dev/null +++ b/test/bob_web/live/docker_tags_live_test.exs @@ -0,0 +1,28 @@ +defmodule BobWeb.DockerTagsLiveTest do + use BobWeb.ConnCase + + import Phoenix.LiveViewTest + + setup do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-alpine", ["amd64"]) + Bob.Artifacts.add_docker_tag("hexpm/elixir", "1.18.0-alpine", ["amd64", "arm64"]) + :ok + end + + test "lists tags and filters by tag text", %{conn: conn} do + {:ok, view, html} = live(conn, ~p"/docker") + assert html =~ "27.0-alpine" + assert html =~ "1.18.0-alpine" + + html = render_change(view, "search", %{"query" => "1.18", "repo" => ""}) + assert html =~ "1.18.0-alpine" + refute html =~ "27.0-alpine" + end + + test "filters by repo dropdown", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/docker") + html = render_change(view, "search", %{"query" => "", "repo" => "hexpm/erlang"}) + assert html =~ "27.0-alpine" + refute html =~ "1.18.0-alpine" + end +end From df4e11bfb32434b34f64e942100ea150d4c04acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:32:10 +0200 Subject: [PATCH 14/24] Build digested assets in the release image --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 246f35d3..bfac0cdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,8 @@ RUN mix deps.compile # build project COPY priv priv COPY lib lib +COPY assets assets +RUN mix assets.deploy RUN mix compile # build release From d913a10fa63211863a5d9313ed4683a72be3033b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Mon, 8 Jun 2026 19:36:30 +0200 Subject: [PATCH 15/24] Ignore generated static assets --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 99e2f804..26e1e9e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ erl_crash.dump *.ez /tmp /persist + +# Generated assets +/priv/static/assets/ +/priv/static/cache_manifest.json From d5e88d7e6c7b01bd50e52b24a050388763476ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 00:08:32 +0200 Subject: [PATCH 16/24] Add structured Docker tag search --- config/dev.exs | 2 +- lib/bob/artifacts.ex | 127 ++++++++++++-- lib/bob/artifacts/docker_tag.ex | 1 + lib/bob/artifacts/docker_tag_search.ex | 49 ++++++ lib/bob/artifacts/docker_tag_staging.ex | 1 + lib/bob_web.ex | 2 +- lib/bob_web/components/layouts/root.html.heex | 3 + lib/bob_web/endpoint.ex | 4 + lib/bob_web/live/docker_tags_live.ex | 99 +++++++++-- mix.exs | 3 + mix.lock | 20 ++- ...8120000_add_docker_tag_search_metadata.exs | 90 ++++++++++ priv/static/favicon.ico | Bin 0 -> 5430 bytes priv/static/images/favicon-160.png | Bin 0 -> 5691 bytes priv/static/images/favicon-64.png | Bin 0 -> 2267 bytes test/bob/artifacts/docker_tag_search_test.exs | 95 ++++++++++ test/bob/artifacts_test.exs | 162 +++++++++++++++++- test/bob/mixfile_test.exs | 7 + test/bob_web/endpoint_config_test.exs | 25 +++ test/bob_web/live/docker_tags_live_test.exs | 132 ++++++++++++-- test/bob_web/live/jobs_live_test.exs | 8 + 21 files changed, 781 insertions(+), 49 deletions(-) create mode 100644 lib/bob/artifacts/docker_tag_search.ex create mode 100644 priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs create mode 100644 priv/static/favicon.ico create mode 100644 priv/static/images/favicon-160.png create mode 100644 priv/static/images/favicon-64.png create mode 100644 test/bob/artifacts/docker_tag_search_test.exs create mode 100644 test/bob/mixfile_test.exs create mode 100644 test/bob_web/endpoint_config_test.exs diff --git a/config/dev.exs b/config/dev.exs index 5dfa2e85..5e7f6895 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -16,7 +16,7 @@ config :bob, BobWeb.Endpoint, check_origin: false, code_reloader: true, debug_errors: true, - secret_key_base: "kQv8mZr2hP0sJX4bN6wL9cT1dY3fA5gH7uE2iO4kR6mS8tV0xZ2bC4dF6hJ8lN0", + secret_key_base: "kQv8mZr2hP0sJX4bN6wL9cT1dY3fA5gH7uE2iO4kR6mS8tV0xZ2bC4dF6hJ8lN09", watchers: [ esbuild: {Esbuild, :install_and_run, [:bob, ~w(--sourcemap=inline --watch)]}, tailwind: {Tailwind, :install_and_run, [:bob, ~w(--watch)]} diff --git a/lib/bob/artifacts.ex b/lib/bob/artifacts.ex index 646ebbf2..eec34b23 100644 --- a/lib/bob/artifacts.ex +++ b/lib/bob/artifacts.ex @@ -2,11 +2,11 @@ defmodule Bob.Artifacts do import Ecto.Query alias Bob.Repo - alias Bob.Artifacts.{Artifact, DockerTag, BaseImageTag, DockerTagStaging} + alias Bob.Artifacts.{Artifact, BaseImageTag, DockerTag, DockerTagSearch, DockerTagStaging} @builds_txt_lock 4_771_002 - # Each staging row binds five parameters; Postgres caps a statement at 65535, + # Each staging row binds six parameters; Postgres caps a statement at 65535, # so a page is inserted in chunks well under that ceiling. @staging_chunk 5000 @@ -25,20 +25,24 @@ defmodule Bob.Artifacts do end def add_docker_tag(repo, tag, archs) do + now = NaiveDateTime.utc_now() + search = DockerTagSearch.metadata(repo, tag) + Repo.query!( """ - INSERT INTO docker_tags (repo, tag, archs, built_at, inserted_at, updated_at) - VALUES ($1, $2, $3, $4, $4, $4) + INSERT INTO docker_tags (repo, tag, archs, search, built_at, inserted_at, updated_at) + VALUES ($1, $2, $3, $4, $5, $5, $5) ON CONFLICT (repo, tag) DO UPDATE SET archs = ( SELECT array_agg(DISTINCT a ORDER BY a) FROM unnest(docker_tags.archs || EXCLUDED.archs) AS a ), + search = EXCLUDED.search, built_at = EXCLUDED.built_at, updated_at = EXCLUDED.updated_at """, - [repo, tag, archs, NaiveDateTime.utc_now()] + [repo, tag, archs, search, now] ) :ok @@ -60,7 +64,14 @@ defmodule Bob.Artifacts do tag_archs |> Enum.map(fn {tag, archs} -> - %{token: token, repo: repo, tag: tag, archs: archs, inserted_at: now} + %{ + token: token, + repo: repo, + tag: tag, + archs: archs, + search: DockerTagSearch.metadata(repo, tag), + inserted_at: now + } end) |> Enum.chunk_every(@staging_chunk) |> Enum.each(&Repo.insert_all(DockerTagStaging, &1)) @@ -84,14 +95,19 @@ defmodule Bob.Artifacts do fn -> Repo.query!( """ - INSERT INTO docker_tags (repo, tag, archs, built_at, inserted_at, updated_at) - SELECT DISTINCT ON (repo, tag) repo, tag, archs, $3, $3, $3 + INSERT INTO docker_tags (repo, tag, archs, search, built_at, inserted_at, updated_at) + SELECT DISTINCT ON (repo, tag) repo, tag, archs, search, $3, $3, $3 FROM docker_tags_staging WHERE token = $1 AND repo = $2 ORDER BY repo, tag ON CONFLICT (repo, tag) - DO UPDATE SET archs = EXCLUDED.archs, built_at = EXCLUDED.built_at, updated_at = EXCLUDED.updated_at + DO UPDATE SET + archs = EXCLUDED.archs, + search = EXCLUDED.search, + built_at = EXCLUDED.built_at, + updated_at = EXCLUDED.updated_at WHERE docker_tags.archs IS DISTINCT FROM EXCLUDED.archs + OR docker_tags.search IS DISTINCT FROM EXCLUDED.search """, [token, repo, now], timeout: @long_query_timeout @@ -200,11 +216,14 @@ defmodule Bob.Artifacts do end def search_docker_tags(filters \\ %{}, limit \\ 100, offset \\ 0) do - query = blank_to_nil(Map.get(filters, :query)) - from(d in DockerTag, order_by: [desc: d.built_at, desc: d.id], limit: ^limit, offset: ^offset) - |> text_filter(query, [:tag]) - |> eq_filter(:repo, Map.get(filters, :repo)) + |> prefix_filter(:repo, Map.get(filters, :repo)) + |> prefix_filter(:tag, Map.get(filters, :tag)) + |> arch_prefix_filter(Map.get(filters, :arch)) + |> search_metadata_prefix_filter(:elixir_version, Map.get(filters, :elixir_version)) + |> search_metadata_prefix_filter(:erlang_version, Map.get(filters, :erlang_version)) + |> search_metadata_prefix_filter(:os, Map.get(filters, :os)) + |> search_metadata_prefix_filter(:os_version, Map.get(filters, :os_version)) |> Repo.all() end @@ -213,6 +232,30 @@ defmodule Bob.Artifacts do def distinct_oses(), do: distinct_values(Artifact, :os) def distinct_repos(), do: distinct_values(DockerTag, :repo) + def distinct_docker_arches() do + %{rows: rows} = + Repo.query!(""" + SELECT DISTINCT arches.arch + FROM docker_tags + CROSS JOIN LATERAL unnest(archs) AS arches(arch) + ORDER BY arches.arch + """) + + Enum.map(rows, fn [arch] -> arch end) + end + + def distinct_docker_oses() do + %{rows: rows} = + Repo.query!(""" + SELECT DISTINCT search->>'os' AS os + FROM docker_tags + WHERE search->>'os' IS NOT NULL + ORDER BY os + """) + + Enum.map(rows, fn [os] -> os end) + end + defp distinct_values(schema, field) do Repo.all( from(s in schema, distinct: true, select: field(s, ^field), order_by: field(s, ^field)) @@ -227,6 +270,64 @@ defmodule Bob.Artifacts do defp eq_filter(query, _field, ""), do: query defp eq_filter(query, field, value), do: from(s in query, where: field(s, ^field) == ^value) + defp prefix_filter(query, _field, nil), do: query + defp prefix_filter(query, _field, ""), do: query + + defp prefix_filter(query, field, value) do + pattern = prefix_pattern(value) + from(s in query, where: fragment("? LIKE ? ESCAPE '\\'", field(s, ^field), ^pattern)) + end + + defp arch_prefix_filter(query, nil), do: query + defp arch_prefix_filter(query, ""), do: query + + defp arch_prefix_filter(query, value) do + pattern = prefix_pattern(value) + + from(d in query, + where: + fragment( + "EXISTS (SELECT 1 FROM unnest(?) AS arch(value) WHERE value LIKE ? ESCAPE '\\')", + d.archs, + ^pattern + ) + ) + end + + defp search_metadata_prefix_filter(query, _field, nil), do: query + defp search_metadata_prefix_filter(query, _field, ""), do: query + + defp search_metadata_prefix_filter(query, :elixir_version, value) do + pattern = prefix_pattern(value) + + from(d in query, + where: fragment("?->>'elixir_version' LIKE ? ESCAPE '\\'", d.search, ^pattern) + ) + end + + defp search_metadata_prefix_filter(query, :erlang_version, value) do + pattern = prefix_pattern(value) + + from(d in query, + where: fragment("?->>'erlang_version' LIKE ? ESCAPE '\\'", d.search, ^pattern) + ) + end + + defp search_metadata_prefix_filter(query, :os, value) do + pattern = prefix_pattern(value) + from(d in query, where: fragment("?->>'os' LIKE ? ESCAPE '\\'", d.search, ^pattern)) + end + + defp search_metadata_prefix_filter(query, :os_version, value) do + pattern = prefix_pattern(value) + + from(d in query, + where: fragment("?->>'os_version' LIKE ? ESCAPE '\\'", d.search, ^pattern) + ) + end + + defp prefix_pattern(value), do: escape_like(value) <> "%" + defp text_filter(query, nil, _fields), do: query defp text_filter(query, text, [first_field | rest_fields]) do diff --git a/lib/bob/artifacts/docker_tag.ex b/lib/bob/artifacts/docker_tag.ex index 57369b19..ab5a8806 100644 --- a/lib/bob/artifacts/docker_tag.ex +++ b/lib/bob/artifacts/docker_tag.ex @@ -5,6 +5,7 @@ defmodule Bob.Artifacts.DockerTag do field(:repo, :string) field(:tag, :string) field(:archs, {:array, :string}) + field(:search, :map, default: %{}) field(:built_at, :utc_datetime_usec) timestamps(type: :utc_datetime_usec) end diff --git a/lib/bob/artifacts/docker_tag_search.ex b/lib/bob/artifacts/docker_tag_search.ex new file mode 100644 index 00000000..1fef00ef --- /dev/null +++ b/lib/bob/artifacts/docker_tag_search.ex @@ -0,0 +1,49 @@ +defmodule Bob.Artifacts.DockerTagSearch do + @erlang_repos ~w(hexpm/erlang hexpm/erlang-amd64 hexpm/erlang-arm64) + @elixir_repos ~w(hexpm/elixir hexpm/elixir-amd64 hexpm/elixir-arm64) + + @erlang_tag_regex ~r/^(.+)-(alpine|ubuntu|debian)-(.+)$/ + @elixir_tag_regex ~r/^(.+)-erlang-(.+)-(alpine|ubuntu|debian)-(.+)$/ + @version_regex ~r/^\d+(?:\.\d+)*(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?$/ + + def metadata(repo, tag) when repo in @erlang_repos do + case Regex.run(@erlang_tag_regex, tag, capture: :all_but_first) do + [erlang_version, os, os_version] -> + if version?(erlang_version) do + %{ + "erlang_version" => erlang_version, + "os" => os, + "os_version" => os_version + } + else + %{} + end + + _other -> + %{} + end + end + + def metadata(repo, tag) when repo in @elixir_repos do + case Regex.run(@elixir_tag_regex, tag, capture: :all_but_first) do + [elixir_version, erlang_version, os, os_version] -> + if version?(elixir_version) and version?(erlang_version) do + %{ + "elixir_version" => elixir_version, + "erlang_version" => erlang_version, + "os" => os, + "os_version" => os_version + } + else + %{} + end + + _other -> + %{} + end + end + + def metadata(_repo, _tag), do: %{} + + defp version?(version), do: Regex.match?(@version_regex, version) +end diff --git a/lib/bob/artifacts/docker_tag_staging.ex b/lib/bob/artifacts/docker_tag_staging.ex index cd989cc7..91aeb482 100644 --- a/lib/bob/artifacts/docker_tag_staging.ex +++ b/lib/bob/artifacts/docker_tag_staging.ex @@ -7,6 +7,7 @@ defmodule Bob.Artifacts.DockerTagStaging do field(:repo, :string) field(:tag, :string) field(:archs, {:array, :string}) + field(:search, :map, default: %{}) field(:inserted_at, :naive_datetime_usec) end end diff --git a/lib/bob_web.ex b/lib/bob_web.ex index 769d2d18..d299c214 100644 --- a/lib/bob_web.ex +++ b/lib/bob_web.ex @@ -1,5 +1,5 @@ defmodule BobWeb do - def static_paths, do: ~w(assets) + def static_paths, do: ~w(assets favicon.ico images/favicon-64.png images/favicon-160.png) def router do quote do diff --git a/lib/bob_web/components/layouts/root.html.heex b/lib/bob_web/components/layouts/root.html.heex index 7f851b7a..c1e60501 100644 --- a/lib/bob_web/components/layouts/root.html.heex +++ b/lib/bob_web/components/layouts/root.html.heex @@ -5,6 +5,9 @@ Bob + + + diff --git a/lib/bob_web/endpoint.ex b/lib/bob_web/endpoint.ex index 83fc785c..4875bd96 100644 --- a/lib/bob_web/endpoint.ex +++ b/lib/bob_web/endpoint.ex @@ -21,6 +21,10 @@ defmodule BobWeb.Endpoint do only: BobWeb.static_paths() ) + if Mix.env() == :dev do + plug(Tidewave) + end + if code_reloading? do socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket) plug(Phoenix.LiveReloader) diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex index d5179a86..e3172177 100644 --- a/lib/bob_web/live/docker_tags_live.ex +++ b/lib/bob_web/live/docker_tags_live.ex @@ -8,11 +8,18 @@ defmodule BobWeb.DockerTagsLive do socket = socket |> assign( - query: "", repo: "", + tag: "", + arch: "", + elixir_version: "", + erlang_version: "", + os: "", + os_version: "", offset: 0, page: @page, - repos: Bob.Artifacts.distinct_repos() + repos: Bob.Artifacts.distinct_repos(), + arches: Bob.Artifacts.distinct_docker_arches(), + oses: Bob.Artifacts.distinct_docker_oses() ) |> load() @@ -21,9 +28,20 @@ defmodule BobWeb.DockerTagsLive do @impl true def handle_event("search", params, socket) do + tag = params["tag"] || "" + socket = socket - |> assign(query: params["query"] || "", repo: params["repo"] || "", offset: 0) + |> assign( + repo: params["repo"] || "", + tag: tag, + arch: params["arch"] || "", + elixir_version: structured_param(params, "elixir_version", tag), + erlang_version: structured_param(params, "erlang_version", tag), + os: structured_param(params, "os", tag), + os_version: structured_param(params, "os_version", tag), + offset: 0 + ) |> load() {:noreply, socket} @@ -37,9 +55,36 @@ defmodule BobWeb.DockerTagsLive do defp step("next"), do: @page defp step("prev"), do: -@page + defp structured_param(_params, _key, tag) when tag != "", do: "" + defp structured_param(params, key, _tag), do: params[key] || "" + defp load(socket) do - %{query: q, repo: repo, offset: offset} = socket.assigns - results = Bob.Artifacts.search_docker_tags(%{query: q, repo: repo}, @page, offset) + %{ + repo: repo, + tag: tag, + arch: arch, + elixir_version: elixir_version, + erlang_version: erlang_version, + os: os, + os_version: os_version, + offset: offset + } = socket.assigns + + results = + Bob.Artifacts.search_docker_tags( + %{ + repo: repo, + tag: tag, + arch: arch, + elixir_version: elixir_version, + erlang_version: erlang_version, + os: os, + os_version: os_version + }, + @page, + offset + ) + assign(socket, results: results) end @@ -52,16 +97,48 @@ defmodule BobWeb.DockerTagsLive do

Docker tags

+ - + + + +
diff --git a/mix.exs b/mix.exs index a4d1a2b3..1526aa62 100644 --- a/mix.exs +++ b/mix.exs @@ -8,6 +8,7 @@ defmodule Bob.Mixfile do elixir: "~> 1.18", start_permanent: Mix.env() == :prod, elixirc_paths: elixirc_paths(Mix.env()), + listeners: [Phoenix.CodeReloader], releases: releases(), aliases: aliases(), deps: deps() @@ -26,6 +27,7 @@ defmodule Bob.Mixfile do defp deps() do [ + {:tidewave, "~> 0.5", only: [:dev]}, {:ecto_sql, "~> 3.12"}, {:ex_aws_s3, "~> 2.0"}, {:finch, "~> 0.19"}, @@ -44,6 +46,7 @@ defmodule Bob.Mixfile do {:bandit, "~> 1.5"}, {:esbuild, "~> 0.8", runtime: Mix.env() == :dev}, {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}, + {:igniter, "~> 0.8.1", only: [:dev, :test], runtime: false}, {:lazy_html, ">= 0.1.0", only: :test} ] end diff --git a/mix.lock b/mix.lock index 4e543b87..cbbcc990 100644 --- a/mix.lock +++ b/mix.lock @@ -1,19 +1,23 @@ %{ "bandit": {:hex, :bandit, "1.12.0", "6c5214daa2469644ac4ab0113b98abc24f75e348378e6a974c6343b3e5da22ef", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.5", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "45dac82dc86f45cf4a196dee9cc5a8b791d9c9469d996055f055e6ee36c66e20"}, "cc_precompiler": {:hex, :cc_precompiler, "0.1.11", "8c844d0b9fb98a3edea067f94f616b3f6b29b959b6b3bf25fee94ffe34364768", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "3427232caf0835f94680e5bcf082408a70b48ad68a5f5c0b02a3bea9f3a075b9"}, + "circular_buffer": {:hex, :circular_buffer, "1.0.1", "01f0e3d5fe945080692cf6521c0988e9dbb5dc312831cefe77e5b63a4e658160", [:mix], [], "hexpm", "7d4ece3137d49c1f8dd0b3e0aa7c484f4d83a0be5d4b516c282085c1d5f2d7b9"}, "db_connection": {:hex, :db_connection, "2.10.1", "d5465f6bcc125c1b8981c1dbf23c193ca16f446ec0b25832dc174f74f18be510", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "18ed94c6e627b4bf452dbd4df61b69a35a1e768525140bc1917b7a685026a6a3"}, - "decimal": {:hex, :decimal, "2.4.1", "6c0fbede12fb122ba685e9ab41c6a40c129e322b3aa192f9e072e61f3a6ffaf2", [:mix], [], "hexpm", "7e618897933a8455f19a727d7c5e50a2c071a544b700e5e724298ecb4340187f"}, + "decimal": {:hex, :decimal, "3.1.1", "430d87b04011ce6cbd4fd205be758311a81f87d552d40904abd00f015935b1d0", [:mix], [], "hexpm", "c5f25f2ced74a0587d03e6023f595db8e924c9d3922c8c8ffd9edfc4498cf1f6"}, "ecto": {:hex, :ecto, "3.13.6", "352135b474f91d1ab99a1b502171d207e9db60421c9e3d0ecab4c7ab96b24d14", [:mix], [{:decimal, "~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8afa059bc16cd2c94739ec0a11e3e5df69d828125119109bef35f20a21a76af2"}, "ecto_sql": {:hex, :ecto_sql, "3.13.5", "2f8282b2ad97bf0f0d3217ea0a6fff320ead9e2f8770f810141189d182dc304e", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aa36751f4e6a2b56ae79efb0e088042e010ff4935fc8684e74c23b1f49e25fdc"}, "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, "esbuild": {:hex, :esbuild, "0.10.0", "b0aa3388a1c23e727c5a3e7427c932d89ee791746b0081bbe56103e9ef3d291f", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "468489cda427b974a7cc9f03ace55368a83e1a7be12fba7e30969af78e5f8c70"}, + "ex_ast": {:hex, :ex_ast, "0.12.0", "052ad63711da41b7efbfb3490dbf3d757bb67caec17d02f6deb0db4a0363e5f6", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.7", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "66b4797f157d32f0a63c6da227515f78816c0ac8f621f6d7a2b22108e7b4dd85"}, "ex_aws": {:hex, :ex_aws, "2.5.10", "d3f8ca8959dad6533a2a934dfdf380df1b1bef425feeb215a47a5176dee8736c", [:mix], [{:configparser_ex, "~> 5.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "88fcd9cc1b2e0fcea65106bdaa8340ac56c6e29bf72f46cf7ef174027532d3da"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.5.7", "e571424d2f345299753382f3a01b005c422b1a460a8bc3ed47659b3d3ef91e9e", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "858e51241e50181e29aa2bc128fef548873a3a9cd580471f57eda5b64dec937f"}, "file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"}, "finch": {:hex, :finch, "0.22.0", "5c48fa6f9706a78eb9036cacb67b8b996b4e66d111c543f4c29bb0f879a6806b", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b94e83c47780fc6813f746a1f1a34ee65cda42da4c5ea26a68f0acc4498e23dc"}, "fine": {:hex, :fine, "0.1.6", "4bf7151493443c454aac9f2fa2f34f5fefd0346a83fb5586a016c4a135c63247", [:mix], [], "hexpm", "5638eb4495488e885ebec167fa57973e5c35e1a50c344eb7666c90ec1c4e3b12"}, + "glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"}, "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"}, - "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "igniter": {:hex, :igniter, "0.8.1", "3c6ea47f3a6031015e29da8b4ba5c685f0a2e409facf63041fd83e982ca3aa89", [:mix], [{:ex_ast, "~> 0.5", [hex: :ex_ast, repo: "hexpm", optional: false]}, {:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4.5", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:phx_new, "~> 1.7", [hex: :phx_new, repo: "hexpm", optional: true]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "d99472e6daf3bfc3675d699c6c7ace9196f377207aab83e09d7b95e9d90e8ae8"}, + "jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"}, "lazy_html": {:hex, :lazy_html, "0.1.11", "136c8e9cd616b4f4e9c1562daa683880891120b759606dc4c3b6b18058ba5d79", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "3b1be592929c31eca1a21673d25696e5c14cddfe922d9d1a3e3b48be4163883b"}, "logster": {:hex, :logster, "1.1.1", "d6fddac540dd46adde0c894024500867fe63b0043713f842c62da5815e21db10", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d18e852c430812ad1c9756998ebe46ec814c724e6eb551a512d7e3f8dee24cef"}, "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"}, @@ -22,23 +26,29 @@ "nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, "observer_cli": {:hex, :observer_cli, "1.8.5", "6771e73560432049891b7737b0edce67ef28aa7973a8dd2b39b21da8c1227386", [:mix, :rebar3], [{:recon, "~> 2.5.6", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm", "4252f4af00b48b51718ef8ccd9da5ce879cdfc8da66debaa9d471fc9bf099f59"}, + "owl": {:hex, :owl, "0.13.1", "1ec4a5dea170465f0e90c502c203079224516bc0cbd599281c8667b3c6ef8848", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "351e768af8f2edc575cdaab1a5a2f6d6381be591758a026c701c703145508a0c"}, "phoenix": {:hex, :phoenix, "1.8.7", "d8d755b4ff4b449f610223dd706b4ae64155cb720d3dc09c706c079ecea189e4", [:mix], [{:bandit, "~> 1.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "47352f72d6ab31009ef77516b1b3a14745be97b54061fd458031b9d8294869d5"}, "phoenix_html": {:hex, :phoenix_html, "4.3.0", "d3577a5df4b6954cd7890c84d955c470b5310bb49647f0a114a6eeecc850f7ad", [:mix], [], "hexpm", "3eaa290a78bab0f075f791a46a981bbe769d94bc776869f4f3063a14f30497ad"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.6.2", "b18b0773a1ba77f28c52decbb0f10fd1ac4d3ae5b8632399bbf6986e3b665f62", [:mix], [{:file_system, "~> 0.2.10 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "d1f89c18114c50d394721365ffb428cce24f1c13de0467ffa773e2ff4a30d5b9"}, "phoenix_live_view": {:hex, :phoenix_live_view, "1.1.31", "c45c85df509dd79c917bc530e26c71299e3920850f65ea52ab6a19ccee66875a", [:mix], [{:igniter, ">= 0.6.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:lazy_html, "~> 0.1.0", [hex: :lazy_html, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0 or ~> 1.8.0-rc", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2f53cc6a9e149f30449341c2775990819d97e3b22338fe719c4d30342e6f9638"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, - "plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"}, + "plug": {:hex, :plug, "1.19.2", "e4950525b22c6789dfb38a3f95d47171ba159da3fc5a33be9643b43d5e8adb98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b6fce20a56af5e60fa5dfecf3f907bb98ec981be43c79a3809a499bc3d133de0"}, "plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"}, "porcelain": {:hex, :porcelain, "2.0.3", "2d77b17d1f21fed875b8c5ecba72a01533db2013bd2e5e62c6d286c029150fdc", [:mix], [], "hexpm", "dc996ab8fadbc09912c787c7ab8673065e50ea1a6245177b0c24569013d23620"}, "postgrex": {:hex, :postgrex, "0.22.2", "4aec14df2a72722aee92492566edbeeb44e233ecb86b1915d03136297ef1385d", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8946382ddb06294f56026ac4278b3cc212bac8a2c82ed68b4087819ed1abc53b"}, "recon": {:hex, :recon, "2.5.6", "9052588e83bfedfd9b72e1034532aee2a5369d9d9343b61aeb7fbce761010741", [:mix, :rebar3], [], "hexpm", "96c6799792d735cc0f0fd0f86267e9d351e63339cbe03df9d162010cefc26bb0"}, - "req": {:hex, :req, "0.6.0", "85dec26488ea23e29b4b516dc1fb9615b2f6f32fe824980d1adc9d79d44a83fd", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21.0 or ~> 0.22.0", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "f90e15671bfcc0c40ba26aaf825c47aec3f8b4f14f54a41bdd14e255fb67118e"}, + "req": {:hex, :req, "0.6.1", "7b904c8b42d0e08136a5c6aba024fd12fc79a1ed8856e7a3522b0917f7e75113", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21.0 or ~> 0.22.0", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "aaf11c9c80f2df2364630b3594e1857fe610d8ea7cb994e1ce3dcb55f204ff1c"}, + "rewrite": {:hex, :rewrite, "1.3.0", "67448ba7975690b35ba7e7f35717efcce317dbd5963cb0577aa7325c1923121a", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "d111ac7ff3a58a802ef4f193bbd1831e00a9c57b33276e5068e8390a212714a5"}, "sentry": {:hex, :sentry, "10.10.0", "d058b635f3796947545c8057a42996f6dbefd12152da947209b56d16af41b161", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7c7ddd3cfdd63fcee53b1e28f9a653037e6927b2b1dbd300b7aeee9687c7a8f6"}, + "sourceror": {:hex, :sourceror, "1.12.0", "da354c5f35aad3cc1132f5d5b0d8437d865e2661c263260480bab51b5eedb437", [:mix], [], "hexpm", "755703683bd014ebcd5de9acc24b68fb874a660a568d1d63f8f98cd8a6ef9cd0"}, + "spitfire": {:hex, :spitfire, "0.3.13", "edd207b065eaec57acc5484097d0aa3e97fe4246168c54e67a9af040b8dee4c1", [:mix], [], "hexpm", "3601be88ceed4967b584e96444de3e1d12d6555ae0864a7390b9cd5332d134b4"}, "sweet_xml": {:hex, :sweet_xml, "0.7.5", "803a563113981aaac202a1dbd39771562d0ad31004ddbfc9b5090bdcd5605277", [:mix], [], "hexpm", "193b28a9b12891cae351d81a0cead165ffe67df1b73fe5866d10629f4faefb12"}, "tailwind": {:hex, :tailwind, "0.4.1", "e7bcc222fe96a1e55f948e76d13dd84a1a7653fb051d2a167135db3b4b08d3e9", [:mix], [], "hexpm", "6249d4f9819052911120dbdbe9e532e6bd64ea23476056adb7f730aa25c220d1"}, - "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, + "telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"}, + "text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"}, "thousand_island": {:hex, :thousand_island, "1.5.0", "f50a213cac97262b6d5ebb85745aa2c00fec1413191e6e66834788d45425cecb", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "708923d40523e43cf99041ab37a0d4b0ec426ac6438fa3716ab23d919eaeb412"}, + "tidewave": {:hex, :tidewave, "0.5.6", "91f35540b5599640443f1d3a1c6166bf506e202840261a6344e384e8813c1f64", [:mix], [{:circular_buffer, "~> 0.4 or ~> 1.0", [hex: :circular_buffer, repo: "hexpm", optional: false]}, {:igniter, "~> 0.6", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_live_reload, ">= 1.6.1", [hex: :phoenix_live_reload, repo: "hexpm", optional: true]}, {:plug, "~> 1.17", [hex: :plug, repo: "hexpm", optional: false]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "dc82d52b8b6ffc04680544b17cd340c7d4166bb0d63999eb960850526866b533"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock_adapter": {:hex, :websock_adapter, "0.5.9", "43dc3ba6d89ef5dec5b1d0a39698436a1e856d000d84bf31a3149862b01a287f", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5534d5c9adad3c18a0f58a9371220d75a803bf0b9a3d87e6fe072faaeed76a08"}, } diff --git a/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs b/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs new file mode 100644 index 00000000..68976d1e --- /dev/null +++ b/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs @@ -0,0 +1,90 @@ +defmodule Bob.Repo.Migrations.AddDockerTagSearchMetadata do + use Ecto.Migration + + @disable_ddl_transaction true + @disable_migration_lock true + @version_regex "^[0-9]+(\\.[0-9]+)*(-[0-9A-Za-z][0-9A-Za-z.-]*)?$" + + def up do + execute("ALTER TABLE docker_tags ADD COLUMN search jsonb NOT NULL DEFAULT '{}'::jsonb") + + execute( + "ALTER TABLE docker_tags_staging ADD COLUMN search jsonb NOT NULL DEFAULT '{}'::jsonb" + ) + + execute(""" + UPDATE docker_tags d + SET search = jsonb_build_object( + 'erlang_version', (parsed.m)[1], + 'os', (parsed.m)[2], + 'os_version', (parsed.m)[3] + ) + FROM ( + SELECT id, regexp_match(tag, '^(.+)-(alpine|ubuntu|debian)-(.+)$') AS m + FROM docker_tags + WHERE repo IN ('hexpm/erlang', 'hexpm/erlang-amd64', 'hexpm/erlang-arm64') + ) AS parsed + WHERE d.id = parsed.id + AND parsed.m IS NOT NULL + AND (parsed.m)[1] ~ '#{@version_regex}' + """) + + execute(""" + UPDATE docker_tags d + SET search = jsonb_build_object( + 'elixir_version', (parsed.m)[1], + 'erlang_version', (parsed.m)[2], + 'os', (parsed.m)[3], + 'os_version', (parsed.m)[4] + ) + FROM ( + SELECT id, regexp_match(tag, '^(.+)-erlang-(.+)-(alpine|ubuntu|debian)-(.+)$') AS m + FROM docker_tags + WHERE repo IN ('hexpm/elixir', 'hexpm/elixir-amd64', 'hexpm/elixir-arm64') + ) AS parsed + WHERE d.id = parsed.id + AND parsed.m IS NOT NULL + AND (parsed.m)[1] ~ '#{@version_regex}' + AND (parsed.m)[2] ~ '#{@version_regex}' + """) + + execute( + "CREATE INDEX CONCURRENTLY docker_tags_repo_prefix_index ON docker_tags (repo text_pattern_ops)" + ) + + execute( + "CREATE INDEX CONCURRENTLY docker_tags_tag_prefix_index ON docker_tags (tag text_pattern_ops)" + ) + + execute(""" + CREATE INDEX CONCURRENTLY docker_tags_elixir_version_prefix_index + ON docker_tags ((search->>'elixir_version') text_pattern_ops) + """) + + execute(""" + CREATE INDEX CONCURRENTLY docker_tags_erlang_version_prefix_index + ON docker_tags ((search->>'erlang_version') text_pattern_ops) + """) + + execute(""" + CREATE INDEX CONCURRENTLY docker_tags_os_prefix_index + ON docker_tags ((search->>'os') text_pattern_ops) + """) + + execute(""" + CREATE INDEX CONCURRENTLY docker_tags_os_version_prefix_index + ON docker_tags ((search->>'os_version') text_pattern_ops) + """) + end + + def down do + execute("DROP INDEX CONCURRENTLY docker_tags_os_version_prefix_index") + execute("DROP INDEX CONCURRENTLY docker_tags_os_prefix_index") + execute("DROP INDEX CONCURRENTLY docker_tags_erlang_version_prefix_index") + execute("DROP INDEX CONCURRENTLY docker_tags_elixir_version_prefix_index") + execute("DROP INDEX CONCURRENTLY docker_tags_tag_prefix_index") + execute("DROP INDEX CONCURRENTLY docker_tags_repo_prefix_index") + execute("ALTER TABLE docker_tags_staging DROP COLUMN search") + execute("ALTER TABLE docker_tags DROP COLUMN search") + end +end diff --git a/priv/static/favicon.ico b/priv/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..4ad97cd97f7aa19a40b69cff604d4412551f3526 GIT binary patch literal 5430 zcmd^@e@t6d6vy8j$`WTX94*PrpfXhU1H(U>m~63wI$BzWLRzZEKh(q@(P`ZN+TtG! zP~)#{5a^F3%MufH&QKC!U@T&B44u43p|u^$a6bgv{pi4Lx;0Yacy8e~m&dz(E&mx` za&qoF_kGXj^wQpY9)hq!xJOvCMnJC<-pCS!M+HI9>E`c`Vf+BbiZO;md}2P1P7pAz zc6s$jR|U-9Z~QVz2ja!`N0(l|FRS~_D2 z`nk(ZTYn8ZwNsO=53QBwFqz;G>Veq%rb~Tteei{r{;*R6#3r4ZL#!Uz8&Nky^~MVL z^G8efIOdp6Sd}L_e(;g2RF6JB;m#|eIZ)S=)Xvus((7S0oxk3uS&f=eMo;QEN#;?v zQ>G=Kp@M3u4?FS3gU~?s4sU*&Gq4CQ#l8{_+L@YK8{j>Rpnp*Dcin zW5b61P))VeV{A$Nheex#(Jkb#n@Np?Nwo_;wBu8_pVoim^v(xRJGw|O+Pdkyp%FHs zZieP4YlLXQPjGF$1k=PeNqOE!A9sp%Td1CR)HYLn>DSPYI$-Th(b<>Oi**NC zEg5h92y###-Tonr=8G`PYROn9#s79lFJ8tRQ?0)|x8(ava-iN`d;)xOExoT1yH6h; zvf0S9ysKyovhxFwqhw@`r(15E>@zwvJsR1M5*OKc{$m#iutKUjo*yu`7iMBa~aZz=}@>NT`SCt3<_E#>1G>(cCES@QA1Ss&%_q1reT^jSP}scJaC`<3K* zu292t#Jw(8&ZYOrZRN3PyrnXD3i-hii$`J&V`oRIzY5}6I;+4<^cM^9Hp*jtWhIm# zBThLSe*@!>u{w4<*`_PSv-_qB|DOqm_HkB6#+X;$tI)qY>tC1aK6|+u8|Qy(88apNKJ3eD)%dth!`9=llI19k>%ICc%pFkUyM}C4tRDF%)oQ?X zdX3d6jop&{9W^%oZN8UlF?R{_<0>^wZEt|haxJ}giq~B#H&y(*s@&oc3o;U)1l%eLE#61HF{1EwV z@VIOo-&4yL@ta^ge-L77Tspr+j9x+h9a#+-y$2w_gVs>e0cU9Lbp0ObGcUu>sQ)Hw zVW@{f|l#CLcAbKZy7rl>8kRTyC(L2$iM9oAG5p9T05TcjS zUH^T!4|kn)&UYU6I%lo@?QcKqI86;jLVQ|$002O!tR$~}U-SRlFx>kye$0;dzTjG^ zD#`=y{#*GSrSAa%iUVbN86Cgu-5h@}a^183F08JSl58&v8%a1z87jQM8HA|EL%Vbf z;EBCiqakI1t%eKoVNivu;VAG!db`QPmgoI~ED(CC5I!D518V`6dZoxn2+VrlYv$&r zr$9DkucD?xpZL;~DDV-blRvcX5uiegLDig{|k!kfA$z z=79-m0MX>?VG7t0NDO2F^;*};>oB%f#iyK+V5;3ug21uh77C=qYyi1sEgyOZtDtVw zvX%1pdHr{x=p^2JX3QF?q|=rcec~l~Hy9?7M~VolG8aF$@IKz}U$@l&H#mvX>f^r} zOB5i{-3PRgYIV{REX?XRKT17dDY(>7dvYvCe^*?5r#EB&CDdywZ}<(iwFG4oJXm9m1k*Xv4j2KfOt}ysjNCXwR$bRB>tQC}T8Ef{kliFkjMRE;7mB^SVV}9~IRBKyE(di{# zx#B2hqi$i>PV!q6k-<&cLrDe>kN^t9J9{|VtQ0G!&N#K-iQ1owN>3wb+v8oSv%36> zc*6;prhpe6I)rM+1WPT2y87p6Ejl(%MV!pE;NFhF^j3Yl%s^kWl1aa|dHBKAH!Ohv z_S-AR#Oor$=?B{HTC*>C!PRPui@T4LEX$c9lsu7V3HCS}9BOo8)Pf|6S$oYI$pQc5 zcJi9X{q>`*B7kF4@d{p5!R{n6#lfY;sNr}_9ewcxeieb zf=V99GlCB4?geJLio_OB;F_nLei6e(i~CEwOydtlGGu)lU9Zc9n-iGrpyVekD443V zi$j)Q^Y=KKqOQpCPkTXK3daq1&mZjKB(4z+2*%t1msh4~(5;wkKfUj9OPiH5lT7tl zsUmnnY`jkd&)4|l-6w(mGAiV-F$32Y{@bcJvKdY5)0mcRkc2bYL2q8?xjsJ-IPC5N zmDIjs>h`%luuA?Iq=$~9S}CE=kuOl+keEVGX*3P`bck)BuGf>!EH2|+9(+*DJ@i=B zMpON9pIP*&>B(1g8y@zmy6$O(YnIvpgc>}e1f?}3WBT{xbqe-Fb zhH_Wn^TOQ+7xMbfZcTk>-fVU7L7c#Hb)}e58Mzi#VXTefw!5=0^2`rHeY~s#oE+6N z)%4x?9+&sLjcPR53Xjk#mu$-G>@H$!SOV!@Q;}FMEb_?3%UKF)5GTFEMY6jkBS3cf zZqVE+@UpX-XuuPPGD*K#n4v<#xzcX2UQEHUT1r#CUwS$ z?C>MldXog}D*CP{*(vzv==;W?D}>vroDZKx7Wn8Na}H1}pyY(kk+lYC8I;?2%DW89 zObzal3LKj3j{N(j<}Svi3vjlJQhNf5t^X0i@9dBTGhGlnG`Y4Ej96tKjy-Ewy4;%b zaP~mv`tNFHZ#grO!Qpk{9y!i5wwQ?K_D)5p-CI*o5B2-zki-3d{4TBFdOJ->9NMUXSVe*Qdq&`yqVZJCMD)_Rp>Be;3uE}616X839Y2|TKNqDY40g-oS1UQVe z-114D%dr=zo%$w^SOQH>eD?8*Z3!dKie+NOHODWy*&iz%{4A>;&Nj>7_KP~{v3yWm+>0*Q^^JdBj z`EwjKUtNAIyL`|M2Wo+`l7L|6<>0Y$m@^IGp;>L5stf1*7aEYc#3SE9b=y7RdkXC= z=(}HJ8me(6)C#N}i`opsA{QI~@Bn_>?C|50jj3N)hOJz`Sd*|&pWw(}oELefl&1zs z<7Fc;{8;4QBWc=9MCSFDJN{`l&~1z6tyBab>Sr_3r=-EsUf{>Mjw6R=VbLb988C@` z92d&z2J-T6z((HmELu22$>$`?HiKe5T`_#D?&U912WxT|N6V~kBO4OuNgBaNBcEnK zEsJ$*vm|3|V_Xx^;(EU?Gw1sNBOc=zkMq%!Z1&P06;84F^htt&!oU^wTiz;7z7{PrB>1fbeTcdTW<=1 zr{Svr5oFi4@GQ%}@K-@Ez!(nW7@1hZyd_Qjs7v4OBTNi%z!A@u5|=+!l3`}%Hj{lP zMVZ3lw$d5?sO7r-)MdYHKXIZnvMkGX%xyejY_3r1Kx|Wg83lUne;6ZjTqMfRP3I_K@cw3+e9#fYD1~crjTKu;0b1vFl6f4 z#K5+&G$Yf@rbsS+Sm{EW`>@DLC%|lD&@vSymSOAm_}wrC zehOQcHV2HL7GeOK+=;p?|TJNw#iOwS=7w(Xl!S z{@BL@ZlbsV^k=(gZHmn-WM7{Pb`E^xl@-}PX}gj`rDlB`5liD?Vd`w9MW$FwJ^HyY z5o096voV}z5k5RI^Q2P^b*(?BXBED%vanCZ!kWd0v;1F^swVhX>Z4a>dd2H0TH->@ zMQR>)Q_dn1SdbkM)O39mb+kjRGoEV%UR1p>byS!SsR7xb#h*^43LgVk3G=G-y<(4%Me_|{z*Jk@oXRTQ^Un|y7ULMLSo;RRxPE<9`m!X0 zv`NRFiO5Rr$iQ+F)A6c53G&L6j@x7lA9sP(P}i-O(zb=1N92Tvu}B`6=b{;~$5z^~b96uS3A!^T$K(D1vaO3nt? z*`L&%~@D@i>_k{cpcg|c*{6JF|+78X3I+)Px+|4L!D@pu?z zz6n0t!Eymk73Rr0y1&I#>dBHkb)jUif3O3KY!WIR2u-^b!y+ED@$dCtEEP&@>;Gv89=HAXMLx11REy z`i{J3I58?{Y8SIxe|l1GDm<%$V|Fr$YxnJ)Q(uMH_$;u+mmir`iZh#Vx&lwzU$!e@ zwoCyk_evwb*eTeY#42>$8GcCBB`oN|R1Q+|_0Ki=4pCattp`K!ZEMNwFF$c^P8!S3 z`Gs~Tv+4s|`iQhdUIV0;o}c{9m}2Jk(DLBO2{Qh)$kW=yPWB!bRkk>h+V`v`vW0m2 z2cIfZJ~AL?8+h4E0hg#qlQGdi0Xwv1{Fx=;Yr8u1N>lpG8sZwu?Xp*+p_=w%bM z>b=vKPgn8a)51P7%TS+!{%#Z73^u!1Nb;Md^%t8`)9BBysHVy+^6tiwR5)J9p;12I zIFFN%IP91(J0*q1SfQ*@yyXel;46(gPJV@SPa>_#`N#g4bz}~t zS*C5opEW}A7qdwYMmIVu@_lyi&04SeD9o@`3kYaqVYWB2ulo0XQ4Qcpf2n*N?0Z{sPHK*P2)b*4GNULu}tFRM@GuhbP!5)h@x_?!9u7>wypN%d%Dox}v_ zf#lP-`0iwQP-98ZaxaRijVR>b=HOs-7Jd3K{ok2=VUlu8j-#}>Z;sR0q|p-|`Vl6I z_M6ba?)nBJ#pTCV3{Ze7ZKmVD4JoosfdP-eE5Nm3h?r_G@3>^O3avw2fcLGO<0T$Du^Kp z7D7!T5<_yI7I@p`JnkKBa>-Yax2K|d=hi-46_)f&+8-U;ubV*OMqc>ZCoUw|W=E`t zBgd-qI^S5ZSOp&@bcIy-m7wVyncHb*d__;Lx`bu1-QgRb5gvsCzWM5&+Uu1vrc{3e zJbPIMyJ&fA4K32GbVQzLmif@jn^SqTyD#{1C=AE>+YB`hy(;e26XEl|x=@-=a-9xysI=fSiwL(+cTkW}?L-;r%arU)0M0>X93LyZ z=UiN+*QZLVB(#6KgW9=&dJE;+x*ONe$rp{T{9IZFQh_gJDJ3+uTm!G)DYOKg#kcd8|HqVK1lUamD6m^3thgYKz>Gw-MP*c+bAhpWi=PZPL z@LfbpTi3n&wpfL_EJbqNjn#W!gKntzD~&9gbcf;p4F=F%_ijT{pd?L(Pr?^Z>12Jr zKF>N{3@F$21S1s4iut7&rB`)M(5>i$5m6CuGBajtGvhLjp?S!CeG^C-Sj?f$f8gMt zaMbUEX|7Es9=}P->)bcx?kgAV{-d8@9$J*q$8+pATq@JBOZGzqTJ-N9V-HVLep_r? zb$PysiiAbvC{+SinF*^?FsMT(dwjYXme^4}Qc!S-?YxD#f!;_>h%jl8aX9PZVrY0|!<-D@*fzi~wPmkUq7&vT86yGjR_2~6~ z>B?ApLs1KM_v)-=B$enYv{Zq&Lkf|ZU@mEO-&0jV=i*k5v>}qiiO30jaU&hbNZhI(5UgfAXAofCj z1KvXHm9T$#Zw5>6pc7Nw5`slh*%?een?L~w>CE<8vr1$jmx7T#+ zI8k0u2*7?W0^k_l5fqQ@FJr8RJhQRs0d;xC8^6l$vs<=_{2$4`8~XO%!3Ls^s5;$k7^_ zja^zO?BwH$ z-xJK5dTT(oHd5jSC+4?;P^xeeF+FufZhbyTzt=2Zw6)y#u-RYvAP~dbN{Zk!J2o1` zx-V_&T7(g a2PWc~J$>)1FMXc|1C*a@$k)hPg#Qn`Eyt4p literal 0 HcmV?d00001 diff --git a/priv/static/images/favicon-64.png b/priv/static/images/favicon-64.png new file mode 100644 index 0000000000000000000000000000000000000000..def74c2ef186cd5ca9ffcc57c2074ae4c1e4176e GIT binary patch literal 2267 zcmV<12qgE3P)kGez`oreo=0F`2+jf6>CS%{alJ(9S1Uoj-E$Pj)AqY@zztr}TdJa1mnV}ETUM5?Sz|fnbiM0Au-cO(l?o0Ek~)UkXD93=az&*b~pIh7aqo>3M$kxdx@4c}S-`k+(e0L0`9 z>asVx(n*4)OlknqT`383@2-CFs#IdBcYukl0Mc9;2iVhR2pv|FYrXRj;i~P8^d99w zH65eRq!LOR09`z;1Ss}k98@l$CU=)7-7^%3{Tz38^GqO=OsZKuA(=?R0BE>09g&m~ zOp4}=F&y!JPk58Do7+gg#*YiO%8Caf2ijV>AAj~I1;{{)A!oJAil5FzG9ZT6?(tfrH> zFDg38w-3=Df!=eu#al3ecRX+?LYiK=qp9p^sz>iDQ zOxohECN2nohQ|#DrUhWM4YB5kc)uoZyeS-2%q*bOuQMXdERB>8Ie$DZ0ICQ^R-QlZ z4f>4yx^k~ymN$Mp{huJK{riI@=*sg4;}=>selqZr0E`_VBjoyOng~{U^hqFq1gMOg z7%9K=+_AF(&~Ql)gr$CsoFZd^JW_c)5H8^Lp|hJoo(zIZV0rQ9&z?P7{BH-CW7(ep-F;HoM$9mS;O?rM5K{haFCJiR;q<*IuLeM6Y}Gji z#dB394r0F_2#+IMd=Lzgjt;RY1QI}HD+msU*s%5XpzK)&k(wZwP`xD(9tRMSKx_%r z7+_TpWWWq9D#{6nDs^XuWdQ;gB~%Aw`{hz(O5?2Dvuljc2drQJSKwp6Mu0rJ zb$cuT9strMR7L=c2dWxp=EU7p;{qU{h|C3S-=;+7Yf;e^erYaU{q+w(X8868Y#VzX zB5^m>3sPTFQBjNPUji`L4Uv_;K8Rs8mg@7M?kiIl;?={m@-MilcAfi+MxOwV24M7d zii)1s;$qj;oj*_8+r4kUgXN$%2H;04cG}}zO(gv5XmRm;RG;>5Tbkds79Q>}nY9Yd zjx=ogA&h->Xx8VO@_YC`SBUcHq1ky|t|f70C@bq(T3hc2uJ&WR-rTUWLo&yrT;cd# zI4wANS8GmnZbnGjy;EuZEjW*!s8aX*5qGPqP$Zbo%YqWPUx$pM>?_ogNXC}`{$Gw?`feS+yV zjk9xHHB@-%7M~AXQ2FhYjGcQ-VWDe2_Xy32w6u0He$v9Y{>^~v07yl}e&GD>F?)-d z8c=~DHF~z&!*1Bu7I(7~Sk^Er=L@%7-a0|j(v|^x&O9EK{#A`K$X7d?TTI&3k`s#Q zsUxnkH)Ld)7amUmkag=$Ao4R#y$Z*xtZ9Q%=>(0CE%{S-wQdn;5~Ft=oRRA(tL?cL zNGd97F=qG|GV-+(^mg7z9USZt2ihAju~CO+4*0|?Ng(g+x{^qCr "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + end + + test "parses Erlang manifest tags" do + assert DockerTagSearch.metadata( + "hexpm/erlang", + "26.2-debian-bookworm-20250113-slim" + ) == %{ + "erlang_version" => "26.2", + "os" => "debian", + "os_version" => "bookworm-20250113-slim" + } + end + + test "parses major-only Erlang version tags" do + assert DockerTagSearch.metadata( + "hexpm/erlang", + "17-ubuntu-jammy-20250101" + ) == %{ + "erlang_version" => "17", + "os" => "ubuntu", + "os_version" => "jammy-20250101" + } + end + + test "parses Erlang prerelease version tags" do + assert DockerTagSearch.metadata( + "hexpm/erlang", + "26.0-rc1-ubuntu-noble-20250101" + ) == %{ + "erlang_version" => "26.0-rc1", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + end + + test "parses per-arch Elixir tags" do + assert DockerTagSearch.metadata( + "hexpm/elixir-arm64", + "1.18.0-erlang-27.0-ubuntu-noble-20250101" + ) == %{ + "elixir_version" => "1.18.0", + "erlang_version" => "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + end + + test "parses Elixir manifest tags" do + assert DockerTagSearch.metadata( + "hexpm/elixir", + "1.17.3-erlang-26.2-alpine-3.22.1" + ) == %{ + "elixir_version" => "1.17.3", + "erlang_version" => "26.2", + "os" => "alpine", + "os_version" => "3.22.1" + } + end + + test "parses Elixir prerelease version tags" do + assert DockerTagSearch.metadata( + "hexpm/elixir", + "1.18.0-rc.0-erlang-27.0-ubuntu-noble-20250101" + ) == %{ + "elixir_version" => "1.18.0-rc.0", + "erlang_version" => "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + end + + test "returns empty metadata for unknown repos and malformed tags" do + assert DockerTagSearch.metadata("library/alpine", "3.22.1") == %{} + assert DockerTagSearch.metadata("hexpm/erlang-amd64", "not-a-known-shape") == %{} + assert DockerTagSearch.metadata("hexpm/erlang", "not-ubuntu-shape") == %{} + assert DockerTagSearch.metadata("hexpm/elixir-amd64", "1.18.0-otp-27") == %{} + + assert DockerTagSearch.metadata("hexpm/elixir", "anything-erlang-anything-debian-shape") == + %{} + end +end diff --git a/test/bob/artifacts_test.exs b/test/bob/artifacts_test.exs index 2570ad2b..20e142ff 100644 --- a/test/bob/artifacts_test.exs +++ b/test/bob/artifacts_test.exs @@ -2,7 +2,7 @@ defmodule Bob.ArtifactsTest do use Bob.DataCase alias Bob.Artifacts - alias Bob.Artifacts.{Artifact, BaseImageTag, DockerTag} + alias Bob.Artifacts.{Artifact, BaseImageTag, DockerTag, DockerTagStaging} describe "Artifact.changeset/2" do test "casts a posted artifact, parsing the ISO8601 date" do @@ -185,6 +185,23 @@ defmodule Bob.ArtifactsTest do [{"27.0-ubuntu-noble-20250101", ["amd64"]}] end + test "stores parsed search metadata" do + Artifacts.add_docker_tag("hexpm/elixir-amd64", "1.18.0-erlang-27.0-ubuntu-noble-20250101", [ + "amd64" + ]) + + assert [ + %DockerTag{ + search: %{ + "elixir_version" => "1.18.0", + "erlang_version" => "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + } + ] = Repo.all(DockerTag) + end + test "unions archs on conflicting (repo, tag)" do Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", ["amd64"]) Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", ["arm64"]) @@ -214,6 +231,36 @@ defmodule Bob.ArtifactsTest do end describe "stage_docker_tags/3 + swap_docker_tags/2" do + test "stages and swaps parsed search metadata" do + token = Ecto.UUID.generate() + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + {"27.0-ubuntu-noble-20250101", ["amd64"]} + ]) + + assert [ + %DockerTagStaging{ + search: %{ + "erlang_version" => "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + } + ] = Repo.all(DockerTagStaging) + + assert Artifacts.swap_docker_tags(token, "hexpm/erlang-amd64") == :ok + + assert [ + %DockerTag{ + search: %{ + "erlang_version" => "27.0", + "os" => "ubuntu", + "os_version" => "noble-20250101" + } + } + ] = Repo.all(DockerTag) + end + test "inserts the staged tags with their arch lists" do assert replace("hexpm/erlang-amd64", [ {"27.0-ubuntu-noble-20250101", ["amd64"]}, @@ -469,19 +516,122 @@ defmodule Bob.ArtifactsTest do assert Bob.Artifacts.distinct_oses() == ["ubuntu-22.04", "ubuntu-24.04"] end - test "search_docker_tags/1 filters by repo and tag text" do - Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-alpine", ["amd64"]) - Bob.Artifacts.add_docker_tag("hexpm/elixir", "1.18.0-alpine", ["amd64"]) + test "distinct Docker value helpers" do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", [ + "amd64", + "arm64" + ]) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.17.3-erlang-26.2-debian-bookworm-20250113-slim", + ["amd64"] + ) - assert [%{repo: "hexpm/erlang"}] = Bob.Artifacts.search_docker_tags(%{repo: "hexpm/erlang"}) - assert [%{tag: "1.18.0-alpine"}] = Bob.Artifacts.search_docker_tags(%{query: "1.18"}) assert Bob.Artifacts.distinct_repos() == ["hexpm/elixir", "hexpm/erlang"] + assert Bob.Artifacts.distinct_docker_arches() == ["amd64", "arm64"] + assert Bob.Artifacts.distinct_docker_oses() == ["debian", "ubuntu"] + end + + test "search_docker_tags/1 filters by structured prefixes" do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", [ + "amd64", + "arm64" + ]) + + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.1-ubuntu-noble-20250101", [ + "amd64" + ]) + + Bob.Artifacts.add_docker_tag("hexpm/erlang", "26.2-debian-bookworm-20250113-slim", [ + "amd64" + ]) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.18.0-erlang-27.0-ubuntu-noble-20250101", + ["amd64", "arm64"] + ) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.17.3-erlang-26.2-debian-bookworm-20250113-slim", + ["amd64"] + ) + + assert [%{tag: "27.0-ubuntu-noble-20250101"}] = + Bob.Artifacts.search_docker_tags(%{ + repo: "hexpm/erl", + tag: "27", + arch: "arm", + erlang_version: "27", + os: "ub", + os_version: "noble" + }) + + assert [%{tag: "27.0-ubuntu-noble-20250101"}] = + Bob.Artifacts.search_docker_tags(%{ + repo: "hexpm/erl", + tag: "27", + arch: "arm", + os: "ub", + os_version: "noble" + }) + + assert [ + "1.17.3-erlang-26.2-debian-bookworm-20250113-slim", + "1.18.0-erlang-27.0-ubuntu-noble-20250101" + ] = + Bob.Artifacts.search_docker_tags(%{elixir_version: "1"}) + |> Enum.map(& &1.tag) + |> Enum.sort() + + assert [ + "1.18.0-erlang-27.0-ubuntu-noble-20250101", + "27.0-ubuntu-noble-20250101", + "27.1-ubuntu-noble-20250101" + ] = + Bob.Artifacts.search_docker_tags(%{os: "ub"}) + |> Enum.map(& &1.tag) + |> Enum.sort() + + assert [%{tag: "1.18.0-erlang-27.0-ubuntu-noble-20250101"}] = + Bob.Artifacts.search_docker_tags(%{ + elixir_version: "1", + os: "ub" + }) + + assert [%{tag: "1.18.0-erlang-27.0-ubuntu-noble-20250101"}] = + Bob.Artifacts.search_docker_tags(%{ + repo: "hexpm/elixir", + elixir_version: "1.18", + erlang_version: "27.0", + os: "ubuntu", + os_version: "noble-2025" + }) + + assert [%{tag: "1.17.3-erlang-26.2-debian-bookworm-20250113-slim"}] = + Bob.Artifacts.search_docker_tags(%{ + elixir_version: "1.17", + os: "deb", + os_version: "bookworm" + }) end test "search_artifacts/1 does not treat % as a LIKE wildcard" do assert Bob.Artifacts.search_artifacts(%{query: "%"}) == [] end + test "search_docker_tags/1 does not treat % or _ as LIKE wildcards" do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", ["amd64"]) + + assert Bob.Artifacts.search_docker_tags(%{tag: "%"}) == [] + assert Bob.Artifacts.search_docker_tags(%{repo: "hexpm/_"}) == [] + assert Bob.Artifacts.search_docker_tags(%{arch: "%"}) == [] + assert Bob.Artifacts.search_docker_tags(%{erlang_version: "%"}) == [] + assert Bob.Artifacts.search_docker_tags(%{erlang_version: "27_"}) == [] + end + test "search_artifacts/3 respects limit and offset" do assert [%{name: "OTP-26.2"}] = Bob.Artifacts.search_artifacts(%{}, 1, 0) assert [%{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{}, 1, 1) diff --git a/test/bob/mixfile_test.exs b/test/bob/mixfile_test.exs new file mode 100644 index 00000000..0896c371 --- /dev/null +++ b/test/bob/mixfile_test.exs @@ -0,0 +1,7 @@ +defmodule Bob.MixfileTest do + use ExUnit.Case, async: true + + test "configures Phoenix code reloader as a Mix listener" do + assert Phoenix.CodeReloader in Keyword.fetch!(Bob.Mixfile.project(), :listeners) + end +end diff --git a/test/bob_web/endpoint_config_test.exs b/test/bob_web/endpoint_config_test.exs new file mode 100644 index 00000000..eb89155f --- /dev/null +++ b/test/bob_web/endpoint_config_test.exs @@ -0,0 +1,25 @@ +defmodule BobWeb.EndpointConfigTest do + use ExUnit.Case, async: true + + @config_dir Path.expand("../../config", __DIR__) + + test "configured cookie session secret keys satisfy Plug's minimum length" do + for env <- [:dev, :test] do + endpoint_config = + @config_dir + |> Path.join("#{env}.exs") + |> Config.Reader.read!(env: env) + |> get_in([:bob, BobWeb.Endpoint]) + + secret_key_base = Keyword.fetch!(endpoint_config, :secret_key_base) + + assert byte_size(secret_key_base) >= 64 + end + end + + test "favicon assets are served as static paths" do + assert "favicon.ico" in BobWeb.static_paths() + assert "images/favicon-64.png" in BobWeb.static_paths() + assert "images/favicon-160.png" in BobWeb.static_paths() + end +end diff --git a/test/bob_web/live/docker_tags_live_test.exs b/test/bob_web/live/docker_tags_live_test.exs index e6deedcb..16b34eff 100644 --- a/test/bob_web/live/docker_tags_live_test.exs +++ b/test/bob_web/live/docker_tags_live_test.exs @@ -4,25 +4,133 @@ defmodule BobWeb.DockerTagsLiveTest do import Phoenix.LiveViewTest setup do - Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-alpine", ["amd64"]) - Bob.Artifacts.add_docker_tag("hexpm/elixir", "1.18.0-alpine", ["amd64", "arm64"]) + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", [ + "amd64", + "arm64" + ]) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.18.0-erlang-27.0-ubuntu-noble-20250101", + ["amd64", "arm64"] + ) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.18.1-erlang-27.0-ubuntu-noble-20250101", + ["arm64"] + ) + + Bob.Artifacts.add_docker_tag( + "hexpm/elixir", + "1.17.3-erlang-26.2-debian-bookworm-20250113-slim", + ["amd64"] + ) + :ok end - test "lists tags and filters by tag text", %{conn: conn} do + test "lists tags and filters by tag prefix", %{conn: conn} do {:ok, view, html} = live(conn, ~p"/docker") - assert html =~ "27.0-alpine" - assert html =~ "1.18.0-alpine" + assert html =~ "27.0-ubuntu-noble-20250101" + assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" - html = render_change(view, "search", %{"query" => "1.18", "repo" => ""}) - assert html =~ "1.18.0-alpine" - refute html =~ "27.0-alpine" + html = + render_change(view, "search", %{ + "repo" => "", + "tag" => "1.18", + "arch" => "", + "elixir_version" => "", + "erlang_version" => "", + "os" => "", + "os_version" => "" + }) + + assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" + refute html =~ "27.0-ubuntu-noble-20250101" end - test "filters by repo dropdown", %{conn: conn} do + test "filters by structured inputs", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/docker") - html = render_change(view, "search", %{"query" => "", "repo" => "hexpm/erlang"}) - assert html =~ "27.0-alpine" - refute html =~ "1.18.0-alpine" + + html = + render_change(view, "search", %{ + "repo" => "hexpm/elixir", + "tag" => "", + "arch" => "arm", + "elixir_version" => "1.18", + "erlang_version" => "27", + "os" => "ub", + "os_version" => "noble" + }) + + assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" + refute html =~ "1.17.3-erlang-26.2-debian-bookworm-20250113-slim" + refute html =~ "27.0-ubuntu-noble-20250101" + end + + test "tag prefix keeps arch filtering and disables parsed tag filters", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/docker") + + html = + render_change(view, "search", %{ + "repo" => "hexpm/elixir", + "tag" => "1.18", + "arch" => "amd64", + "elixir_version" => "1.17", + "erlang_version" => "26", + "os" => "debian", + "os_version" => "bookworm" + }) + + assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" + refute html =~ "1.18.1-erlang-27.0-ubuntu-noble-20250101" + refute html =~ "1.17.3-erlang-26.2-debian-bookworm-20250113-slim" + + refute control_html(html, "arch") =~ "disabled" + + for name <- ~w(elixir_version erlang_version os os_version) do + assert control_html(html, name) =~ "disabled" + end + end + + test "renders every Docker search input", %{conn: conn} do + {:ok, _view, html} = live(conn, ~p"/docker") + + assert control_html(html, "repo") =~ "hexpm/elixir) + assert html =~ ~s() + assert html =~ ~s() + assert html =~ ~s() + assert html =~ ~s() + assert html =~ ~s() + end + + test "renders arch filter after the parsed tag filters", %{conn: conn} do + {:ok, _view, html} = live(conn, ~p"/docker") + + assert control_position(html, "repo") < control_position(html, "tag") + assert control_position(html, "tag") < control_position(html, "elixir_version") + assert control_position(html, "elixir_version") < control_position(html, "erlang_version") + assert control_position(html, "erlang_version") < control_position(html, "os") + assert control_position(html, "os") < control_position(html, "os_version") + assert control_position(html, "os_version") < control_position(html, "arch") + end + + defp control_html(html, name) do + Regex.run(~r/<(?:input|select)[^>]*name="#{name}"[^>]*>/, html) + |> List.first() + end + + defp control_position(html, name) do + {position, _length} = :binary.match(html, ~s(name="#{name}")) + position end end diff --git a/test/bob_web/live/jobs_live_test.exs b/test/bob_web/live/jobs_live_test.exs index 455d0792..67fd16ec 100644 --- a/test/bob_web/live/jobs_live_test.exs +++ b/test/bob_web/live/jobs_live_test.exs @@ -24,6 +24,14 @@ defmodule BobWeb.JobsLiveTest do assert html =~ "done" end + test "root layout links favicon assets", %{conn: conn} do + {:ok, _view, html} = live(conn, ~p"/") + + assert html =~ ~s(href="/favicon.ico") + assert html =~ ~s(href="/images/favicon-64.png") + assert html =~ ~s(href="/images/favicon-160.png") + end + test "refreshes when a :jobs_changed broadcast arrives", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/") refute render(view) =~ ":refreshed" From 01a0f5ed51ebb742249442a5053fc0986d123a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 01:39:17 +0200 Subject: [PATCH 17/24] Match Bob dashboard design --- assets/css/app.css | 1012 +++++++++++++++++ lib/bob_web.ex | 2 +- lib/bob_web/components/core_components.ex | 260 ++++- lib/bob_web/components/layouts.ex | 12 + lib/bob_web/components/layouts/root.html.heex | 53 +- lib/bob_web/endpoint.ex | 2 +- lib/bob_web/live/artifacts_live.ex | 98 +- lib/bob_web/live/docker_tags_live.ex | 125 +- lib/bob_web/live/jobs_live.ex | 210 +++- test/bob_web/endpoint_config_test.exs | 3 +- 10 files changed, 1590 insertions(+), 187 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index b5c61c95..21f9f92b 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -1,3 +1,1015 @@ @tailwind base; @tailwind components; @tailwind utilities; + +:root { + --color-primary-50: #f7f5f9; + --color-primary-100: #f0edf4; + --color-primary-200: #e1d9e8; + --color-primary-300: #c3b4d1; + --color-primary-500: #8769a4; + --color-primary-600: #69438d; + --color-primary-700: #523079; + --color-primary-800: #3d2165; + --color-grey-50: #f0f5f9; + --color-grey-100: #e1e8f0; + --color-grey-200: #cad5e0; + --color-grey-300: #91a4b7; + --color-grey-400: #61758a; + --color-grey-500: #445668; + --color-grey-600: #304254; + --color-grey-700: #1c2a3a; + --color-grey-800: #0d1829; + --color-grey-900: #030913; + --color-green-50: #f3f8f5; + --color-green-200: #cfe3d8; + --color-green-500: #419164; + --color-green-600: #11753d; + --color-green-700: #0c643c; + --color-blue-50: #f3f6fd; + --color-blue-200: #cfdef7; + --color-blue-500: #3f7ae0; + --color-blue-600: #0f59d8; + --color-blue-700: #0a44b9; + --color-yellow-50: #fefbf5; + --color-yellow-200: #fcf0d8; + --color-yellow-700: #cd942a; + --color-red-50: #faf4f5; + --color-red-200: #eed5d9; + --color-red-500: #bb5665; + --color-red-600: #aa2c3f; + --color-red-700: #92203c; + --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif; + --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace; + --shadow-lg: 0 12px 32px rgba(13, 24, 41, 0.12); +} + +html, +body { + margin: 0; + min-height: 100%; + background: var(--color-grey-50); + color: var(--color-grey-700); + font-family: var(--font-sans); + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +*, +*::before, +*::after { + box-sizing: border-box; +} + +a { + text-decoration: none; +} + +code, +pre, +.mono { + font-family: var(--font-mono); +} + +.flash { + margin: 10px auto 0; + max-width: 1240px; + border-radius: 8px; + background: var(--color-grey-800); + color: #fff; + padding: 8px 12px; + font-size: 13px; +} + +.bob { + min-height: 100vh; + display: flex; + flex-direction: column; + color: var(--color-grey-700); + background: var(--color-grey-50); +} + +.bob-nav { + position: sticky; + top: 0; + z-index: 50; + height: 64px; + background: var(--color-grey-900); + border-bottom: 1px solid rgba(255, 255, 255, 0.06); +} + +.bob-nav__inner { + max-width: 1240px; + height: 100%; + margin: 0 auto; + padding: 0 28px; + display: flex; + align-items: center; + gap: 30px; +} + +.bob-brand { + display: flex; + align-items: center; + gap: 10px; + flex: none; +} + +.bob-brand img { + display: block; +} + +.bob-brand__name { + color: #fff; + font-size: 21px; + font-weight: 800; + letter-spacing: 0; +} + +.bob-brand__tag { + color: var(--color-grey-400); + font-size: 12px; + font-weight: 500; + padding-left: 11px; + border-left: 1px solid var(--color-grey-700); +} + +.bob-nav__tabs { + display: flex; + align-items: center; + gap: 4px; +} + +.bob-nav__tab { + display: inline-flex; + align-items: center; + gap: 8px; + height: 34px; + padding: 0 14px; + border-radius: 8px; + color: var(--color-grey-300); + font-size: 14px; + font-weight: 500; + transition: background 0.15s, color 0.15s; +} + +.bob-nav__tab:hover { + color: #fff; + background: rgba(255, 255, 255, 0.06); +} + +.bob-nav__tab svg { + color: var(--color-grey-400); + transition: color 0.15s; +} + +.bob-nav__tab:hover svg { + color: var(--color-grey-200); +} + +.bob-nav__tab--active { + color: #fff; + background: rgba(255, 255, 255, 0.1); +} + +.bob-nav__tab--active svg { + color: var(--color-primary-300); +} + +.bob-nav__right { + margin-left: auto; + display: flex; + align-items: center; + gap: 14px; +} + +.nav-ext { + display: inline-flex; + align-items: center; + gap: 7px; + height: 32px; + padding: 0 12px; + border-radius: 8px; + border: 1px solid rgba(255, 255, 255, 0.1); + color: var(--color-grey-300); + font-family: var(--font-mono); + font-size: 12.5px; + transition: background 0.15s, color 0.15s; +} + +.nav-ext:hover { + color: #fff; + background: rgba(255, 255, 255, 0.08); +} + +.nav-ext svg { + color: var(--color-grey-400); +} + +.bob-main { + flex: 1; +} + +.bob-wrap { + max-width: 1240px; + margin: 0 auto; + padding: 28px 28px 90px; +} + +.page-head { + display: flex; + align-items: flex-end; + gap: 16px; + margin-bottom: 22px; +} + +.page-head__main { + flex: 1; + min-width: 0; +} + +.page-head h1 { + margin: 0 0 6px; + color: var(--color-grey-700); + font-size: 26px; + font-weight: 700; + line-height: 1.1; + letter-spacing: 0; +} + +.page-head__sub { + color: var(--color-grey-500); + font-size: 14px; +} + +.page-head__live { + display: inline-flex; + align-items: center; + gap: 8px; + flex: none; + padding-bottom: 3px; + color: var(--color-grey-500); + font-size: 13px; +} + +.live-dot { + position: relative; + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--color-green-500); +} + +.live-dot::after { + content: ""; + position: absolute; + inset: -4px; + border-radius: 50%; + border: 1.5px solid var(--color-green-500); + opacity: 0; + animation: ping 2.4s ease-out infinite; +} + +@keyframes ping { + 0% { + transform: scale(0.55); + opacity: 0.8; + } + + 80%, + 100% { + transform: scale(1.9); + opacity: 0; + } +} + +.sec { + overflow: hidden; + margin-bottom: 18px; + border: 1px solid var(--color-grey-200); + border-radius: 14px; + background: #fff; +} + +.sec__head { + display: flex; + align-items: center; + gap: 12px; + padding: 15px 20px; + border-bottom: 1px solid var(--color-grey-100); +} + +.sec__title { + display: flex; + align-items: center; + gap: 9px; + color: var(--color-grey-700); + font-size: 15px; + font-weight: 600; +} + +.sec__count { + min-width: 22px; + border-radius: 999px; + background: var(--color-grey-100); + color: var(--color-grey-600); + padding: 1px 9px; + text-align: center; + font-size: 12px; + font-variant-numeric: tabular-nums; + font-weight: 600; +} + +.sec__count--live { + background: var(--color-blue-50); + color: var(--color-blue-700); +} + +.icon-blue { + color: var(--color-blue-600); +} + +.icon-muted { + color: var(--color-grey-400); +} + +.qsizes { + padding: 14px 20px 10px; +} + +.qsizes__label { + margin-bottom: 4px; + color: var(--color-grey-400); + font-size: 11px; + font-weight: 600; + letter-spacing: 0.06em; + text-transform: uppercase; +} + +.qsizes__grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 0 36px; +} + +.qsize { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + padding: 7px 0; + border-bottom: 1px dashed var(--color-grey-100); +} + +.qsize__l { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; +} + +.qsize__mod { + overflow: hidden; + color: var(--color-grey-600); + font-family: var(--font-mono); + font-size: 12.5px; + text-overflow: ellipsis; + white-space: nowrap; +} + +.qsize__count { + flex: none; + color: var(--color-grey-700); + font-size: 13px; + font-variant-numeric: tabular-nums; + font-weight: 700; +} + +.filter-bar { + display: flex; + align-items: center; + gap: 12px; + padding: 14px 20px; + border-bottom: 1px solid var(--color-grey-100); +} + +.filter-bar--wrap { + flex-wrap: wrap; +} + +.filter-bar__meta { + margin-left: auto; + color: var(--color-grey-400); + font-size: 13px; + white-space: nowrap; +} + +.search-wrap { + position: relative; + flex: 1; + min-width: 220px; + max-width: 380px; +} + +.search-box { + display: flex; + align-items: center; + gap: 8px; + width: 100%; + height: 36px; + padding: 0 10px 0 12px; + border: 1px solid var(--color-grey-200); + border-radius: 9px; + background: var(--color-grey-50); + transition: border-color 0.15s, box-shadow 0.15s, background 0.15s; +} + +.search-box:focus-within { + border-color: var(--color-blue-500); + background: #fff; + box-shadow: 0 0 0 3px rgba(15, 89, 216, 0.12); +} + +.search-box svg { + flex: none; + color: var(--color-grey-400); +} + +.search-box input { + flex: 1; + min-width: 0; + border: 0; + outline: 0; + background: transparent; + color: var(--color-grey-700); + padding: 0; + font: inherit; + font-size: 14px; +} + +.search-box input::placeholder { + color: var(--color-grey-400); +} + +.fsel { + position: relative; + display: inline-flex; + align-items: center; + gap: 7px; +} + +.fsel__label { + color: var(--color-grey-400); + font-size: 12px; +} + +.fsel select { + height: 36px; + appearance: none; + -webkit-appearance: none; + border: 1px solid var(--color-grey-200); + border-radius: 8px; + background: #fff; + color: var(--color-grey-700); + padding: 0 28px 0 11px; + font: inherit; + font-size: 13px; + cursor: pointer; + transition: border-color 0.15s; +} + +.fsel select:hover { + border-color: var(--color-grey-300); +} + +.fsel select:focus { + outline: none; + border-color: var(--color-blue-500); + box-shadow: 0 0 0 3px rgba(15, 89, 216, 0.12); +} + +.fsel svg { + position: absolute; + right: 10px; + color: var(--color-grey-400); + pointer-events: none; +} + +.fsel--off { + opacity: 0.5; +} + +.fsel--off select { + background: var(--color-grey-50); + cursor: not-allowed; +} + +.finput { + position: relative; + display: inline-flex; + align-items: center; +} + +.finput input { + width: 122px; + height: 36px; + border: 1px solid var(--color-grey-200); + border-radius: 8px; + background: #fff; + color: var(--color-grey-700); + padding: 0 11px; + font: inherit; + font-size: 13px; + transition: border-color 0.15s, box-shadow 0.15s; +} + +.finput input::placeholder { + color: var(--color-grey-400); +} + +.finput input:hover { + border-color: var(--color-grey-300); +} + +.finput input:focus { + outline: none; + border-color: var(--color-blue-500); + box-shadow: 0 0 0 3px rgba(15, 89, 216, 0.12); +} + +.finput--off input { + opacity: 0.5; + background: var(--color-grey-50); + cursor: not-allowed; +} + +.fgroup { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 5px; + border: 1px dashed var(--color-grey-200); + border-radius: 10px; + transition: opacity 0.15s; +} + +.fgroup--off { + opacity: 0.5; +} + +.f-or { + color: var(--color-grey-400); + padding: 0 1px; + font-size: 12px; + font-style: italic; +} + +.f-or--off { + opacity: 0.45; +} + +.chip-row { + display: flex; + align-items: center; + gap: 6px; +} + +.chip { + display: inline-flex; + align-items: center; + gap: 7px; + height: 32px; + padding: 0 12px; + border: 1px solid var(--color-grey-200); + border-radius: 999px; + background: #fff; + color: var(--color-grey-500); + font-family: inherit; + font-size: 13px; + font-weight: 500; +} + +.chip--active { + border-color: var(--color-grey-700); + background: var(--color-grey-700); + color: #fff; +} + +.chip__n { + font-size: 11px; + font-variant-numeric: tabular-nums; + font-weight: 600; + opacity: 0.75; +} + +.chip__dot { + width: 8px; + height: 8px; + border-radius: 50%; + flex: none; +} + +.chip__dot--done { + background: var(--color-green-600); +} + +.chip__dot--failed { + background: var(--color-red-600); +} + +.tbl-wrap { + overflow-x: auto; +} + +.jt { + width: 100%; + border-collapse: collapse; +} + +.jt thead th { + border-bottom: 1px solid var(--color-grey-200); + background: var(--color-grey-50); + color: var(--color-grey-400); + padding: 10px 16px; + text-align: left; + font-size: 11px; + font-weight: 600; + letter-spacing: 0.06em; + text-transform: uppercase; + white-space: nowrap; +} + +.jt thead th:first-child { + padding-left: 20px; +} + +.jt thead th:last-child { + padding-right: 20px; +} + +.jt tbody td { + border-bottom: 1px solid var(--color-grey-100); + color: var(--color-grey-600); + padding: 11px 16px; + vertical-align: middle; + font-size: 13px; +} + +.jt tbody td:first-child { + padding-left: 20px; +} + +.jt tbody td:last-child { + padding-right: 20px; +} + +.jt tbody tr:last-child td { + border-bottom: 0; +} + +.jt tbody tr:hover { + background: var(--color-grey-50); +} + +.jt tr.row--failed td:first-child { + box-shadow: inset 3px 0 0 var(--color-red-500); +} + +.col-state { + width: 1%; + white-space: nowrap; +} + +.col-time { + white-space: nowrap; +} + +.col-args { + width: 40%; +} + +.c-state { + display: flex; + align-items: center; + gap: 9px; +} + +.run-label { + color: var(--color-blue-700); + font-size: 12px; + font-weight: 600; +} + +.c-mod { + display: flex; + align-items: center; + gap: 9px; + min-width: 0; +} + +.mod-name { + color: var(--color-grey-700); + font-family: var(--font-mono); + font-size: 13px; + font-weight: 500; + white-space: nowrap; +} + +.c-args { + display: block; + overflow: hidden; + max-width: 460px; + color: var(--color-grey-400); + font-family: var(--font-mono); + font-size: 12px; + text-overflow: ellipsis; + white-space: nowrap; +} + +.c-time { + color: var(--color-grey-600); + font-size: 13px; + font-variant-numeric: tabular-nums; + white-space: nowrap; +} + +.c-dur { + color: var(--color-grey-500); + font-size: 13px; + font-variant-numeric: tabular-nums; + white-space: nowrap; +} + +.c-elapsed { + color: var(--color-blue-700); + font-size: 13px; + font-variant-numeric: tabular-nums; + font-weight: 600; +} + +.badge { + display: inline-flex; + align-items: center; + gap: 6px; + border: 1px solid transparent; + border-radius: 4px; + padding: 3px 8px; + font-size: 11px; + font-weight: 600; + letter-spacing: 0.01em; + white-space: nowrap; +} + +.badge--neutral { + border-color: var(--color-grey-200); + background: var(--color-grey-100); + color: var(--color-grey-600); +} + +.badge--success { + border-color: var(--color-green-200); + background: var(--color-green-50); + color: var(--color-green-700); +} + +.badge--danger { + border-color: var(--color-red-200); + background: var(--color-red-50); + color: var(--color-red-700); +} + +.badge--running { + border-color: var(--color-blue-200); + background: var(--color-blue-50); + color: var(--color-blue-700); +} + +.badge .badge__dot { + width: 6px; + height: 6px; + border-radius: 50%; + background: currentColor; + opacity: 0.9; +} + +.state-dot { + position: relative; + display: inline-block; + flex: none; + width: 9px; + height: 9px; + border-radius: 50%; +} + +.state-dot--running { + background: var(--color-blue-600); + color: var(--color-blue-600); +} + +.state-dot--done { + background: var(--color-green-600); + color: var(--color-green-600); +} + +.state-dot--failed { + background: var(--color-red-600); + color: var(--color-red-600); +} + +.state-dot--pulse::after { + content: ""; + position: absolute; + inset: -3px; + border: 1.5px solid currentColor; + border-radius: 50%; + opacity: 0; + animation: ping 1.8s ease-out infinite; +} + +.cat-glyph { + display: inline-flex; + align-items: center; + flex: none; +} + +.cat-glyph--check { + color: var(--color-grey-500); +} + +.cat-glyph--build { + color: var(--color-primary-600); +} + +.cat-glyph--docker { + color: var(--color-blue-600); +} + +.mono-cell { + color: var(--color-grey-600); + font-family: var(--font-mono); + font-size: 12.5px; + white-space: nowrap; +} + +.mono-cell--dim { + color: var(--color-grey-400); +} + +.mono-cell--name { + color: var(--color-grey-700); + font-weight: 500; +} + +.kind-badge { + border: 1px solid var(--color-primary-200); + border-radius: 5px; + background: var(--color-primary-50); + color: var(--color-primary-700); + padding: 1px 7px; + font-size: 11px; + font-weight: 700; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +.arch-tag { + border: 1px solid var(--color-grey-200); + border-radius: 5px; + background: var(--color-grey-100); + color: var(--color-grey-600); + padding: 1px 7px; + font-family: var(--font-mono); + font-size: 11.5px; + font-weight: 600; +} + +.os-cell { + color: var(--color-grey-600); + font-family: var(--font-mono); + font-size: 12.5px; + white-space: nowrap; +} + +.arch-list { + display: flex; + gap: 5px; +} + +.dk-repo { + display: flex; + align-items: center; + gap: 8px; +} + +.pager { + display: flex; + align-items: center; + justify-content: space-between; + padding: 14px 20px; + border-top: 1px solid var(--color-grey-100); +} + +.pager__info { + color: var(--color-grey-500); + font-size: 13px; + font-variant-numeric: tabular-nums; +} + +.pager__info b { + color: var(--color-grey-700); + font-weight: 600; +} + +.pager__btns { + display: flex; + gap: 8px; +} + +.pg-btn { + display: inline-flex; + align-items: center; + gap: 6px; + height: 34px; + border: 1px solid var(--color-grey-200); + border-radius: 8px; + background: #fff; + color: var(--color-grey-600); + padding: 0 13px; + font-family: inherit; + font-size: 13px; + font-weight: 500; + cursor: pointer; + transition: border-color 0.14s, color 0.14s; +} + +.pg-btn:hover:not(:disabled) { + border-color: var(--color-grey-400); + color: var(--color-grey-800); +} + +.pg-btn:disabled { + opacity: 0.45; + cursor: not-allowed; +} + +.empty-mini { + padding: 22px 20px; + color: var(--color-grey-400); + font-size: 13.5px; +} + +.empty-mini b { + color: var(--color-grey-600); + font-weight: 600; +} + +.fade-in { + animation: fade 0.25s ease; +} + +@keyframes fade { + from { + opacity: 0; + transform: translateY(4px); + } + + to { + opacity: 1; + transform: none; + } +} + +@media (max-width: 820px) { + .bob-brand__tag, + .nav-ext { + display: none; + } + + .bob-nav__inner { + gap: 16px; + padding: 0 16px; + } + + .bob-wrap { + padding: 20px 16px 80px; + } + + .page-head { + flex-direction: column; + align-items: flex-start; + gap: 8px; + } + + .c-args { + max-width: 200px; + } + + .filter-bar__meta { + width: 100%; + margin-left: 0; + } + + .qsizes__grid { + grid-template-columns: 1fr; + } +} diff --git a/lib/bob_web.ex b/lib/bob_web.ex index d299c214..c79bb7f9 100644 --- a/lib/bob_web.ex +++ b/lib/bob_web.ex @@ -1,5 +1,5 @@ defmodule BobWeb do - def static_paths, do: ~w(assets favicon.ico images/favicon-64.png images/favicon-160.png) + def static_paths, do: ~w(assets favicon.ico images) def router do quote do diff --git a/lib/bob_web/components/core_components.ex b/lib/bob_web/components/core_components.ex index 30ebcd0b..890dbc37 100644 --- a/lib/bob_web/components/core_components.ex +++ b/lib/bob_web/components/core_components.ex @@ -5,32 +5,266 @@ defmodule BobWeb.CoreComponents do def flash_group(assigns) do ~H""" -
+
<%= kind %>: <%= message %>
""" end + attr(:name, :string, required: true) + attr(:size, :integer, default: 16) + attr(:class, :any, default: nil) + + def icon(assigns) do + assigns = assign(assigns, :paths, icon_paths(assigns.name)) + + ~H""" + + """ + end + + attr(:title, :string, required: true) + attr(:count, :integer, default: nil) + attr(:icon, :string, default: nil) + attr(:icon_class, :string, default: nil) + attr(:live, :boolean, default: false) + slot(:inner_block, required: true) + + def section(assigns) do + ~H""" +
+
+
+ <.icon :if={@icon} name={@icon} class={@icon_class} /> + <%= @title %> +
+ + <%= @count %> + +
+ <%= render_slot(@inner_block) %> +
+ """ + end + attr(:rows, :list, required: true) + attr(:class, :string, default: nil) slot :col, required: true do attr(:label, :string) + attr(:class, :string) end def table(assigns) do ~H""" - - - - - - - - - - - -
<%= col[:label] %>
<%= render_slot(col, row) %>
+
+ + + + + + + + + + + +
<%= col[:label] %>
<%= render_slot(col, row) %>
+
+ """ + end + + attr(:event, :string, required: true) + attr(:offset, :integer, required: true) + attr(:count, :integer, required: true) + attr(:page, :integer, required: true) + attr(:unit, :string, default: nil) + + def pager(assigns) do + assigns = + assigns + |> assign(:from, if(assigns.count == 0, do: 0, else: assigns.offset + 1)) + |> assign(:to, assigns.offset + assigns.count) + + ~H""" +
+
+ Nothing to show + 0}> + Showing <%= @from %>-<%= @to %><%= if @unit, do: " " <> @unit %> + +
+
+ + +
+
+ """ + end + + attr(:state, :any, required: true) + + def state_badge(assigns) do + assigns = assign(assigns, :state_name, to_string(assigns.state)) + + ~H""" + + + <%= @state_name %> + + """ + end + + attr(:state, :any, required: true) + + def state_dot(assigns) do + assigns = assign(assigns, :state_name, to_string(assigns.state)) + + ~H""" + + """ end + + attr(:cat, :string, required: true) + attr(:size, :integer, default: 15) + + def cat_glyph(assigns) do + assigns = assign(assigns, :icon, cat_icon(assigns.cat)) + + ~H""" + + <.icon name={@icon} size={@size} /> + + """ + end + + attr(:cat, :string, required: true) + attr(:module, :string, required: true) + + def module_cell(assigns) do + ~H""" +
+ <.cat_glyph cat={@cat} /> + <%= @module %> +
+ """ + end + + attr(:name, :string, required: true) + attr(:value, :string, default: "") + attr(:placeholder, :string, required: true) + + def search_box(assigns) do + ~H""" +
+ +
+ """ + end + + attr(:name, :string, required: true) + attr(:label, :string, required: true) + attr(:value, :string, default: "") + attr(:options, :list, required: true) + attr(:disabled, :boolean, default: false) + + def filter_select(assigns) do + ~H""" + + """ + end + + attr(:name, :string, required: true) + attr(:value, :string, default: "") + attr(:placeholder, :string, required: true) + attr(:disabled, :boolean, default: false) + + def filter_text(assigns) do + ~H""" +
+ +
+ """ + end + + defp icon_paths("search"), do: ["M21 21l-4.34-4.34M19 11a8 8 0 11-16 0 8 8 0 0116 0z"] + defp icon_paths("check"), do: ["M4.5 12.75l6 6 9-13.5"] + defp icon_paths("x"), do: ["M6 18L18 6M6 6l12 12"] + defp icon_paths("bolt"), do: ["M3.75 13.5l10.5-11.25-1.5 9h6.75L9 22.5l1.5-9h-6.75z"] + defp icon_paths("clock"), do: ["M12 6v6l4 2m6-2a9 9 0 11-18 0 9 9 0 0118 0z"] + defp icon_paths("queue"), do: ["M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5"] + + defp icon_paths("box"), + do: [ + "M21 7.5l-9-5.25L3 7.5m18 0l-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l9 5.25m0-9v9" + ] + + defp icon_paths("cube"), do: icon_paths("box") + + defp icon_paths("docker"), + do: [ + "M3 13.5h18M5.25 13.5V9.75h3v3.75m1.5 0V6.75h3v6.75m1.5 0V9.75h3v3.75M3 13.5c0 4 3 6.75 7.5 6.75 6 0 9-3.75 9.75-6.75" + ] + + defp icon_paths("refresh"), + do: [ + "M16.023 9.348h4.992V4.356M3.75 9.348a8.25 8.25 0 0113.803-3.7L20.25 8.4M3.985 14.652a8.25 8.25 0 0013.803 3.7L20.25 15.6m0 4.8v-4.99h-4.992" + ] + + defp icon_paths("chevL"), do: ["M15.75 19.5L8.25 12l7.5-7.5"] + defp icon_paths("chevR"), do: ["M8.25 4.5l7.5 7.5-7.5 7.5"] + defp icon_paths("chevD"), do: ["M19.5 8.25l-7.5 7.5-7.5-7.5"] + + defp icon_paths("external"), + do: [ + "M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25" + ] + + defp icon_paths(_name), do: [] + + defp row_class(%{state: "failed"}), do: "row--failed" + defp row_class(_row), do: nil + + defp state_badge_class("done"), do: "badge--success" + defp state_badge_class("failed"), do: "badge--danger" + defp state_badge_class("running"), do: "badge--running" + defp state_badge_class(_state), do: "badge--neutral" + + defp cat_icon("build"), do: "cube" + defp cat_icon("docker"), do: "docker" + defp cat_icon(_cat), do: "refresh" end diff --git a/lib/bob_web/components/layouts.ex b/lib/bob_web/components/layouts.ex index c171f554..c129d41b 100644 --- a/lib/bob_web/components/layouts.ex +++ b/lib/bob_web/components/layouts.ex @@ -2,4 +2,16 @@ defmodule BobWeb.Layouts do use BobWeb, :html embed_templates("layouts/*") + + def nav_class(current_path, target_path) do + [ + "bob-nav__tab", + nav_active?(current_path, target_path) && "bob-nav__tab--active" + ] + end + + defp nav_active?("/", "/"), do: true + defp nav_active?("/artifacts", "/artifacts"), do: true + defp nav_active?("/docker", "/docker"), do: true + defp nav_active?(_current_path, _target_path), do: false end diff --git a/lib/bob_web/components/layouts/root.html.heex b/lib/bob_web/components/layouts/root.html.heex index c1e60501..df815e31 100644 --- a/lib/bob_web/components/layouts/root.html.heex +++ b/lib/bob_web/components/layouts/root.html.heex @@ -12,17 +12,46 @@ - - -
- <%= @inner_content %> -
+ +
+
+
+ <.link href={~p"/"} class="bob-brand"> + + Bob + Hex build server + + + + + +
+
+ +
+
+ <%= @inner_content %> +
+
+
diff --git a/lib/bob_web/endpoint.ex b/lib/bob_web/endpoint.ex index 4875bd96..a437b774 100644 --- a/lib/bob_web/endpoint.ex +++ b/lib/bob_web/endpoint.ex @@ -17,7 +17,7 @@ defmodule BobWeb.Endpoint do plug(Plug.Static, at: "/", from: :bob, - gzip: true, + gzip: Mix.env() != :dev, only: BobWeb.static_paths() ) diff --git a/lib/bob_web/live/artifacts_live.ex b/lib/bob_web/live/artifacts_live.ex index c02413fe..0197aa01 100644 --- a/lib/bob_web/live/artifacts_live.ex +++ b/lib/bob_web/live/artifacts_live.ex @@ -63,47 +63,69 @@ defmodule BobWeb.ArtifactsLive do defp fmt(nil), do: "—" defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + defp truncate(nil, _length), do: nil + + defp truncate(value, length) when byte_size(value) > length do + binary_part(value, 0, length) <> "..." + end + + defp truncate(value, _length), do: value + @impl true def render(assigns) do ~H""" -

Build artifacts

- -
- - - - -
- - <.table :if={@results != []} rows={@results}> - <:col :let={a} label="kind"><%= a.kind %> - <:col :let={a} label="arch"><%= a.arch %> - <:col :let={a} label="os"><%= a.os %> - <:col :let={a} label="name"><%= a.name %> - <:col :let={a} label="ref"><%= a.ref %> - <:col :let={a} label="sha256"><%= a.sha256 %> - <:col :let={a} label="built"><%= fmt(a.built_at) %> - -

No matching artifacts.

- -
- - +
+
+
+

Build artifacts

+
+
+ +
+
+ <.search_box name="query" value={@query} placeholder="Search name or ref..." /> + <.filter_select name="kind" label="kind" value={@kind} options={@kinds} /> + <.filter_select name="arch" label="arch" value={@arch} options={@arches} /> + <.filter_select name="os" label="os" value={@os} options={@oses} /> + <%= length(@results) %> artifacts +
+ + <.table :if={@results != []} rows={@results} class="jt--art"> + <:col :let={a} label="kind"> + <%= a.kind %> + + <:col :let={a} label="arch"> + <%= a.arch %> + + <:col :let={a} label="os"> + <%= a.os %> + + <:col :let={a} label="name"> + <%= a.name %> + + <:col :let={a} label="ref"> + <%= truncate(a.ref, 12) %> + + <:col :let={a} label="sha256"> + + <%= truncate(a.sha256, 14) %> + + — + + <:col :let={a} label="built" class="col-time"> + <%= fmt(a.built_at) %> + + +
No matching artifacts.
+ + <.pager + event="page" + offset={@offset} + count={length(@results)} + page={@page} + unit="artifacts" + /> +
""" end diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex index e3172177..64001bf1 100644 --- a/lib/bob_web/live/docker_tags_live.ex +++ b/lib/bob_web/live/docker_tags_live.ex @@ -94,65 +94,72 @@ defmodule BobWeb.DockerTagsLive do @impl true def render(assigns) do ~H""" -

Docker tags

- -
- - - - - - - -
- - <.table :if={@results != []} rows={@results}> - <:col :let={d} label="repo"><%= d.repo %> - <:col :let={d} label="tag"><%= d.tag %> - <:col :let={d} label="archs"><%= Enum.join(d.archs, ", ") %> - <:col :let={d} label="built"><%= fmt(d.built_at) %> - -

No matching tags.

- -
- - +
+
+
+

Docker tags

+
+
+ +
+
+ <.filter_select name="repo" label="repo" value={@repo} options={@repos} /> + <.filter_text name="tag" value={@tag} placeholder="tag prefix..." /> + or +
+ <.filter_text + name="elixir_version" + value={@elixir_version} + placeholder="Elixir" + disabled={@tag != ""} + /> + <.filter_text + name="erlang_version" + value={@erlang_version} + placeholder="Erlang" + disabled={@tag != ""} + /> + <.filter_select + name="os" + label="os" + value={@os} + options={@oses} + disabled={@tag != ""} + /> + <.filter_text + name="os_version" + value={@os_version} + placeholder="OS version" + disabled={@tag != ""} + /> +
+ <.filter_select name="arch" label="arch" value={@arch} options={@arches} /> + <%= length(@results) %> tags +
+ + <.table :if={@results != []} rows={@results} class="jt--dk"> + <:col :let={d} label="repo"> +
+ <.icon name="docker" class="icon-blue" /> + <%= d.repo %> +
+ + <:col :let={d} label="tag"> + <%= d.tag %> + + <:col :let={d} label="archs"> +
+ <%= arch %> +
+ + <:col :let={d} label="built" class="col-time"> + <%= fmt(d.built_at) %> + + +
No matching tags.
+ + <.pager event="page" offset={@offset} count={length(@results)} page={@page} unit="tags" /> +
""" end diff --git a/lib/bob_web/live/jobs_live.ex b/lib/bob_web/live/jobs_live.ex index 65e11494..f192ac8c 100644 --- a/lib/bob_web/live/jobs_live.ex +++ b/lib/bob_web/live/jobs_live.ex @@ -52,9 +52,14 @@ defmodule BobWeb.JobsLive do defp step("prev", page), do: -page defp load(socket) do + queue_sizes = + Bob.Queue.queue_sizes() + |> Enum.sort_by(fn {_mod, count} -> count end, :desc) + assign(socket, running: Bob.Queue.running(), - queue_sizes: Enum.sort(Bob.Queue.queue_sizes()), + queue_sizes: queue_sizes, + queue_total: Enum.sum(Enum.map(queue_sizes, fn {_mod, count} -> count end)), queued: Bob.Queue.queued_listing(@queued_page, socket.assigns.queued_offset), past: Bob.Queue.recent(@past_page, socket.assigns.past_offset) ) @@ -63,75 +68,158 @@ defmodule BobWeb.JobsLive do defp fmt(nil), do: "—" defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + defp fmt_duration(nil), do: "—" + + defp fmt_duration(seconds) when seconds < 60, do: "#{seconds}s" + + defp fmt_duration(seconds) when seconds < 3600 do + minutes = div(seconds, 60) + seconds = rem(seconds, 60) + "#{minutes}m #{seconds}s" + end + + defp fmt_duration(seconds) do + hours = div(seconds, 3600) + minutes = div(rem(seconds, 3600), 60) + "#{hours}h #{minutes}m" + end + + defp elapsed(datetime), do: duration(datetime, DateTime.utc_now()) + + defp duration(%{started_at: started_at, finished_at: finished_at}), + do: duration(started_at, finished_at) + + defp duration(nil, _finished_at), do: nil + defp duration(_started_at, nil), do: nil + + defp duration(started_at, finished_at) do + NaiveDateTime.diff(to_naive(finished_at), to_naive(started_at)) + |> max(0) + end + + defp to_naive(%DateTime{} = datetime), do: DateTime.to_naive(datetime) + defp to_naive(%NaiveDateTime{} = datetime), do: datetime + + defp module_name(module_key), do: inspect(module_key) + defp args_text(args), do: inspect(args) + + defp job_cat(module_key) do + module = inspect(module_key) + + cond do + String.contains?(module, "Docker") -> "docker" + String.contains?(module, "Build") -> "build" + true -> "check" + end + end + @impl true def render(assigns) do ~H""" -
-
-

Running (<%= length(@running) %>)

+
+
+
+

Jobs

+
+
+ + Live - updates automatically +
+
+ + <.section + title="Running" + count={length(@running)} + live={@running != []} + icon="bolt" + icon_class={if @running == [], do: "icon-muted", else: "icon-blue"} + > <.table :if={@running != []} rows={@running}> - <:col :let={j} label="Module"><%= inspect(j.module_key) %> - <:col :let={j} label="Args"><%= inspect(j.args) %> - <:col :let={j} label="Started"><%= fmt(j.started_at) %> + <:col :let={_j} label="State" class="col-state"> +
+ <.state_dot state="running" /> + running +
+ + <:col :let={j} label="Module"> + <.module_cell cat={job_cat(j.module_key)} module={module_name(j.module_key)} /> + + <:col :let={j} label="Args" class="col-args"> + <%= args_text(j.args) %> + + <:col :let={j} label="Started" class="col-time"> + <%= fmt(j.started_at) %> + + <:col :let={j} label="Elapsed" class="col-time"> + <%= fmt_duration(elapsed(j.started_at)) %> + -

Nothing running.

-
- -
-

Queue

-
    -
  • - <%= inspect(mod) %> — <%= count %> -
  • -
+
Nothing running.
+ + + <.section title="Queue" count={@queue_total} icon="queue"> +
+
Queued by job type
+
+
+ + <.cat_glyph cat={job_cat(mod)} size={14} /> + <%= module_name(mod) %> + + <%= count %> +
+
+
+
+ oldest first +
<.table :if={@queued != []} rows={@queued}> - <:col :let={j} label="Module"><%= inspect(j.module_key) %> - <:col :let={j} label="Args"><%= inspect(j.args) %> - <:col :let={j} label="Queued"><%= fmt(j.inserted_at) %> + <:col :let={j} label="Module"> + <.module_cell cat={job_cat(j.module_key)} module={module_name(j.module_key)} /> + + <:col :let={j} label="Args" class="col-args"> + <%= args_text(j.args) %> + + <:col :let={j} label="Queued" class="col-time"> + <%= fmt(j.inserted_at) %> + -

Queue is empty.

- <.pager event="queued_page" offset={@queued_offset} count={length(@queued)} page={@queued_page} /> -
- -
-

Past

+
Queue is empty.
+ <.pager + event="queued_page" + offset={@queued_offset} + count={length(@queued)} + page={@queued_page} + unit="queued" + /> + + + <.section title="Past" count={length(@past)} icon="clock"> <.table :if={@past != []} rows={@past}> - <:col :let={j} label="State"><%= j.state %> - <:col :let={j} label="Module"><%= inspect(j.module_key) %> - <:col :let={j} label="Args"><%= inspect(j.args) %> - <:col :let={j} label="Finished"><%= fmt(j.finished_at) %> + <:col :let={j} label="State" class="col-state"> + <.state_badge state={j.state} /> + + <:col :let={j} label="Module"> + <.module_cell cat={job_cat(j.module_key)} module={module_name(j.module_key)} /> + + <:col :let={j} label="Args" class="col-args"> + <%= args_text(j.args) %> + + <:col :let={j} label="Duration" class="col-time"> + <%= fmt_duration(duration(j)) %> + + <:col :let={j} label="Finished" class="col-time"> + <%= fmt(j.finished_at) %> + -

No finished jobs.

- <.pager event="past_page" offset={@past_offset} count={length(@past)} page={@past_page} /> -
-
- """ - end - - attr(:event, :string, required: true) - attr(:offset, :integer, required: true) - attr(:count, :integer, required: true) - attr(:page, :integer, required: true) - - defp pager(assigns) do - ~H""" -
- - +
No finished jobs.
+ <.pager + event="past_page" + offset={@past_offset} + count={length(@past)} + page={@past_page} + /> +
""" end diff --git a/test/bob_web/endpoint_config_test.exs b/test/bob_web/endpoint_config_test.exs index eb89155f..4295bfe3 100644 --- a/test/bob_web/endpoint_config_test.exs +++ b/test/bob_web/endpoint_config_test.exs @@ -19,7 +19,6 @@ defmodule BobWeb.EndpointConfigTest do test "favicon assets are served as static paths" do assert "favicon.ico" in BobWeb.static_paths() - assert "images/favicon-64.png" in BobWeb.static_paths() - assert "images/favicon-160.png" in BobWeb.static_paths() + assert "images" in BobWeb.static_paths() end end From 88bdb3a62eb6710246edab631f46f61f3c61b55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 10:05:42 +0200 Subject: [PATCH 18/24] Optimize paginated views and Docker tag metadata --- lib/bob/artifacts.ex | 102 ++++++++++---- lib/bob/artifacts/docker_tag_search.ex | 6 + lib/bob/artifacts/docker_tag_staging.ex | 1 + lib/bob/docker_hub.ex | 57 ++++++-- lib/bob/queue.ex | 4 + lib/bob/reconcile.ex | 4 +- lib/bob_web/components/core_components.ex | 41 +++++- lib/bob_web/live/artifacts_live.ex | 50 +++++-- lib/bob_web/live/docker_tags_live.ex | 75 ++++++---- lib/bob_web/live/jobs_live.ex | 43 ++++-- ...09014923_index_docker_tags_by_built_at.exs | 17 +++ ...20260609023000_index_docker_tags_archs.exs | 14 ++ ...00_add_built_at_to_docker_tags_staging.exs | 13 ++ test/bob/artifacts/docker_tag_search_test.exs | 14 ++ test/bob/artifacts_test.exs | 133 ++++++++++++++++-- test/bob/docker_hub_test.exs | 68 +++++++++ test/bob/queue_test.exs | 14 ++ test/bob/reconcile_test.exs | 57 ++++++-- test/bob_web/live/artifacts_live_test.exs | 4 + test/bob_web/live/docker_tags_live_test.exs | 2 + test/bob_web/live/jobs_live_test.exs | 2 + 21 files changed, 607 insertions(+), 114 deletions(-) create mode 100644 priv/repo/migrations/20260609014923_index_docker_tags_by_built_at.exs create mode 100644 priv/repo/migrations/20260609023000_index_docker_tags_archs.exs create mode 100644 priv/repo/migrations/20260609025000_add_built_at_to_docker_tags_staging.exs create mode 100644 test/bob/docker_hub_test.exs diff --git a/lib/bob/artifacts.ex b/lib/bob/artifacts.ex index eec34b23..76c46fa1 100644 --- a/lib/bob/artifacts.ex +++ b/lib/bob/artifacts.ex @@ -24,14 +24,15 @@ defmodule Bob.Artifacts do :ok end - def add_docker_tag(repo, tag, archs) do + def add_docker_tag(repo, tag, archs, built_at \\ DateTime.utc_now()) do now = NaiveDateTime.utc_now() + built_at = dump_utc_datetime(built_at) search = DockerTagSearch.metadata(repo, tag) Repo.query!( """ INSERT INTO docker_tags (repo, tag, archs, search, built_at, inserted_at, updated_at) - VALUES ($1, $2, $3, $4, $5, $5, $5) + VALUES ($1, $2, $3, $4, $5, $6, $6) ON CONFLICT (repo, tag) DO UPDATE SET archs = ( @@ -42,14 +43,14 @@ defmodule Bob.Artifacts do built_at = EXCLUDED.built_at, updated_at = EXCLUDED.updated_at """, - [repo, tag, archs, search, now] + [repo, tag, archs, search, built_at, now] ) :ok end @doc """ - Inserts a page of `{tag, archs}` pairs into the staging table under `token`. + Inserts a page of `{tag, archs, built_at}` tuples into the staging table under `token`. Reconcile streams Docker Hub a page at a time into staging so the full tag list (up to ~1M for hexpm/elixir) is never held in memory and no connection is @@ -59,17 +60,18 @@ defmodule Bob.Artifacts do """ def stage_docker_tags(_token, _repo, []), do: :ok - def stage_docker_tags(token, repo, tag_archs) do + def stage_docker_tags(token, repo, tag_archs_built_at) do now = NaiveDateTime.utc_now() - tag_archs - |> Enum.map(fn {tag, archs} -> + tag_archs_built_at + |> Enum.map(fn {tag, archs, built_at} -> %{ token: token, repo: repo, tag: tag, archs: archs, search: DockerTagSearch.metadata(repo, tag), + built_at: built_at, inserted_at: now } end) @@ -96,10 +98,10 @@ defmodule Bob.Artifacts do Repo.query!( """ INSERT INTO docker_tags (repo, tag, archs, search, built_at, inserted_at, updated_at) - SELECT DISTINCT ON (repo, tag) repo, tag, archs, search, $3, $3, $3 + SELECT DISTINCT ON (repo, tag) repo, tag, archs, search, built_at, $3, $3 FROM docker_tags_staging WHERE token = $1 AND repo = $2 - ORDER BY repo, tag + ORDER BY repo, tag, built_at DESC ON CONFLICT (repo, tag) DO UPDATE SET archs = EXCLUDED.archs, @@ -108,6 +110,8 @@ defmodule Bob.Artifacts do updated_at = EXCLUDED.updated_at WHERE docker_tags.archs IS DISTINCT FROM EXCLUDED.archs OR docker_tags.search IS DISTINCT FROM EXCLUDED.search + -- TODO: Remove this built_at comparison after production Docker tag rows are corrected. + OR docker_tags.built_at IS DISTINCT FROM EXCLUDED.built_at """, [token, repo, now], timeout: @long_query_timeout @@ -205,33 +209,48 @@ defmodule Bob.Artifacts do end def search_artifacts(filters \\ %{}, limit \\ 100, offset \\ 0) do - query = blank_to_nil(Map.get(filters, :query)) - - from(a in Artifact, order_by: [desc: a.built_at, desc: a.id], limit: ^limit, offset: ^offset) - |> text_filter(query, [:name, :ref]) - |> eq_filter(:kind, Map.get(filters, :kind)) - |> eq_filter(:arch, Map.get(filters, :arch)) - |> eq_filter(:os, Map.get(filters, :os)) + filters + |> artifact_search_query() + |> order_by([a], desc: a.built_at, desc: a.id) + |> limit(^limit) + |> offset(^offset) |> Repo.all() end + def count_artifacts(filters \\ %{}) do + filters + |> artifact_search_query() + |> Repo.aggregate(:count, :id) + end + def search_docker_tags(filters \\ %{}, limit \\ 100, offset \\ 0) do - from(d in DockerTag, order_by: [desc: d.built_at, desc: d.id], limit: ^limit, offset: ^offset) - |> prefix_filter(:repo, Map.get(filters, :repo)) - |> prefix_filter(:tag, Map.get(filters, :tag)) - |> arch_prefix_filter(Map.get(filters, :arch)) - |> search_metadata_prefix_filter(:elixir_version, Map.get(filters, :elixir_version)) - |> search_metadata_prefix_filter(:erlang_version, Map.get(filters, :erlang_version)) - |> search_metadata_prefix_filter(:os, Map.get(filters, :os)) - |> search_metadata_prefix_filter(:os_version, Map.get(filters, :os_version)) + filters + |> docker_tag_search_query() + |> order_by([d], desc: d.built_at, desc: d.id) + |> limit(^limit) + |> offset(^offset) |> Repo.all() end + def count_docker_tags(filters \\ %{}) do + filters + |> docker_tag_search_query() + |> Repo.aggregate(:count, :id) + end + def distinct_kinds(), do: distinct_values(Artifact, :kind) def distinct_arches(), do: distinct_values(Artifact, :arch) def distinct_oses(), do: distinct_values(Artifact, :os) def distinct_repos(), do: distinct_values(DockerTag, :repo) + def docker_tag_filter_options() do + %{ + repos: DockerTagSearch.repos(), + arches: DockerTagSearch.arches(), + oses: DockerTagSearch.oses() + } + end + def distinct_docker_arches() do %{rows: rows} = Repo.query!(""" @@ -262,10 +281,41 @@ defmodule Bob.Artifacts do ) end + defp artifact_search_query(filters) do + query = blank_to_nil(Map.get(filters, :query)) + + Artifact + |> text_filter(query, [:name, :ref]) + |> eq_filter(:kind, Map.get(filters, :kind)) + |> eq_filter(:arch, Map.get(filters, :arch)) + |> eq_filter(:os, Map.get(filters, :os)) + end + + defp docker_tag_search_query(filters) do + DockerTag + |> prefix_filter(:repo, Map.get(filters, :repo)) + |> prefix_filter(:tag, Map.get(filters, :tag)) + |> arch_prefix_filter(Map.get(filters, :arch)) + |> search_metadata_prefix_filter(:elixir_version, Map.get(filters, :elixir_version)) + |> search_metadata_prefix_filter(:erlang_version, Map.get(filters, :erlang_version)) + |> search_metadata_prefix_filter(:os, Map.get(filters, :os)) + |> search_metadata_prefix_filter(:os_version, Map.get(filters, :os_version)) + end + defp blank_to_nil(nil), do: nil defp blank_to_nil(""), do: nil defp blank_to_nil(value), do: value + defp dump_utc_datetime(%DateTime{} = datetime) do + datetime + |> DateTime.to_naive() + |> NaiveDateTime.truncate(:microsecond) + end + + defp dump_utc_datetime(%NaiveDateTime{} = datetime) do + NaiveDateTime.truncate(datetime, :microsecond) + end + defp eq_filter(query, _field, nil), do: query defp eq_filter(query, _field, ""), do: query defp eq_filter(query, field, value), do: from(s in query, where: field(s, ^field) == ^value) @@ -281,6 +331,10 @@ defmodule Bob.Artifacts do defp arch_prefix_filter(query, nil), do: query defp arch_prefix_filter(query, ""), do: query + defp arch_prefix_filter(query, value) when value in ["amd64", "arm64"] do + from(d in query, where: fragment("? @> ?", d.archs, ^[value])) + end + defp arch_prefix_filter(query, value) do pattern = prefix_pattern(value) diff --git a/lib/bob/artifacts/docker_tag_search.ex b/lib/bob/artifacts/docker_tag_search.ex index 1fef00ef..ddda1c9f 100644 --- a/lib/bob/artifacts/docker_tag_search.ex +++ b/lib/bob/artifacts/docker_tag_search.ex @@ -1,11 +1,17 @@ defmodule Bob.Artifacts.DockerTagSearch do + @archs ~w(amd64 arm64) @erlang_repos ~w(hexpm/erlang hexpm/erlang-amd64 hexpm/erlang-arm64) @elixir_repos ~w(hexpm/elixir hexpm/elixir-amd64 hexpm/elixir-arm64) + @oses ~w(alpine debian ubuntu) @erlang_tag_regex ~r/^(.+)-(alpine|ubuntu|debian)-(.+)$/ @elixir_tag_regex ~r/^(.+)-erlang-(.+)-(alpine|ubuntu|debian)-(.+)$/ @version_regex ~r/^\d+(?:\.\d+)*(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?$/ + def repos(), do: Enum.sort(@erlang_repos ++ @elixir_repos) + def arches(), do: @archs + def oses(), do: @oses + def metadata(repo, tag) when repo in @erlang_repos do case Regex.run(@erlang_tag_regex, tag, capture: :all_but_first) do [erlang_version, os, os_version] -> diff --git a/lib/bob/artifacts/docker_tag_staging.ex b/lib/bob/artifacts/docker_tag_staging.ex index 91aeb482..a096f283 100644 --- a/lib/bob/artifacts/docker_tag_staging.ex +++ b/lib/bob/artifacts/docker_tag_staging.ex @@ -8,6 +8,7 @@ defmodule Bob.Artifacts.DockerTagStaging do field(:tag, :string) field(:archs, {:array, :string}) field(:search, :map, default: %{}) + field(:built_at, :utc_datetime_usec) field(:inserted_at, :naive_datetime_usec) end end diff --git a/lib/bob/docker_hub.ex b/lib/bob/docker_hub.ex index 968f9f3e..553cdb41 100644 --- a/lib/bob/docker_hub.ex +++ b/lib/bob/docker_hub.ex @@ -18,10 +18,10 @@ defmodule Bob.DockerHub do @doc """ Pages every tag of `repo` from Docker Hub, invoking `on_page` with each page's - `{tag, archs}` list as it arrives. Returns `:ok` once the full set is fetched - or `:error` if any page failed, so the caller can avoid applying a partial set. - Pages stream through `on_page` rather than accumulating, so the response set is - never held in memory in full. + `{tag, archs, built_at}` list as it arrives. Returns `:ok` once the full set + is fetched or `:error` if any page failed, so the caller can avoid applying a + partial set. Pages stream through `on_page` rather than accumulating, so the + response set is never held in memory in full. """ def stream_repo_tags(repo, on_page) do url = @dockerhub_url <> "v2/repositories/#{repo}/tags?page=${page}&page_size=100" @@ -78,14 +78,55 @@ defmodule Bob.DockerHub do def parse(result) do # Reject corrupt images - images = Enum.reject(result["images"], &(&1["digest"] in [nil, ""])) + images = + Enum.reject(result["images"] || [], fn image -> + image["digest"] in [nil, ""] or image["architecture"] in [nil, ""] + end) + + built_at = docker_hub_timestamp(result, images) - if images == [] do + if images == [] or is_nil(built_at) do nil else # DockerHub returns dupes sometimes? - archs = result["images"] |> Enum.map(&:binary.copy(&1["architecture"])) |> Enum.uniq() - {:binary.copy(result["name"]), archs} + archs = images |> Enum.map(&:binary.copy(&1["architecture"])) |> Enum.uniq() + {:binary.copy(result["name"]), archs, built_at} + end + end + + defp docker_hub_timestamp(result, images) do + parse_timestamp(result["last_updated"]) || + images + |> Enum.map(&parse_timestamp(&1["last_pushed"])) + |> Enum.reject(&is_nil/1) + |> Enum.max_by(&DateTime.to_unix(&1, :microsecond), fn -> nil end) + end + + defp parse_timestamp(value) when is_binary(value) do + case DateTime.from_iso8601(value) do + {:ok, datetime, _offset} -> + force_microsecond_precision(datetime) + + {:error, _reason} -> + parse_naive_timestamp(value) end end + + defp parse_timestamp(_value), do: nil + + defp parse_naive_timestamp(value) do + case NaiveDateTime.from_iso8601(value) do + {:ok, datetime} -> + datetime + |> DateTime.from_naive!("Etc/UTC") + |> force_microsecond_precision() + + {:error, _reason} -> + nil + end + end + + defp force_microsecond_precision(%DateTime{} = datetime) do + %{datetime | microsecond: {elem(datetime.microsecond, 0), 6}} + end end diff --git a/lib/bob/queue.ex b/lib/bob/queue.ex index 090766c3..946c8f2b 100644 --- a/lib/bob/queue.ex +++ b/lib/bob/queue.ex @@ -174,6 +174,10 @@ defmodule Bob.Queue do ) end + def finished_count() do + Repo.aggregate(from(j in Job, where: j.state in ["done", "failed"]), :count, :id) + end + def recent(limit \\ 50, offset \\ 0) do Repo.all( from(j in Job, diff --git a/lib/bob/reconcile.ex b/lib/bob/reconcile.ex index 625a89ca..0259ba54 100644 --- a/lib/bob/reconcile.ex +++ b/lib/bob/reconcile.ex @@ -71,7 +71,7 @@ defmodule Bob.Reconcile do defp sync_per_arch_repos(stream) do Enum.each(@per_arch_repos, fn {repo, arch} -> swap_docker_tags(stream, repo, fn page -> - Enum.map(page, fn {tag, _archs} -> {tag, [arch]} end) + Enum.map(page, fn {tag, _archs, built_at} -> {tag, [arch], built_at} end) end) end) end @@ -79,7 +79,7 @@ defmodule Bob.Reconcile do defp sync_manifest_repos(stream) do Enum.each(@manifest_repos, fn repo -> swap_docker_tags(stream, repo, fn page -> - Enum.map(page, fn {tag, archs} -> {tag, known_archs(archs)} end) + Enum.map(page, fn {tag, archs, built_at} -> {tag, known_archs(archs), built_at} end) end) end) end diff --git a/lib/bob_web/components/core_components.ex b/lib/bob_web/components/core_components.ex index 890dbc37..beb6feb2 100644 --- a/lib/bob_web/components/core_components.ex +++ b/lib/bob_web/components/core_components.ex @@ -92,26 +92,31 @@ defmodule BobWeb.CoreComponents do attr(:count, :integer, required: true) attr(:page, :integer, required: true) attr(:unit, :string, default: nil) + attr(:total, :integer, default: nil) def pager(assigns) do assigns = assigns |> assign(:from, if(assigns.count == 0, do: 0, else: assigns.offset + 1)) |> assign(:to, assigns.offset + assigns.count) + |> assign(:range_unit, format_unit(assigns.unit, assigns.count)) + |> assign(:next_disabled, next_disabled?(assigns)) ~H"""
Nothing to show 0}> - Showing <%= @from %>-<%= @to %><%= if @unit, do: " " <> @unit %> + Showing <%= @from %>-<%= @to %><%= if @range_unit, + do: " " <> @range_unit %> + <%= total_text(@total, @unit) %>
-
@@ -119,6 +124,38 @@ defmodule BobWeb.CoreComponents do """ end + def format_count(count) do + count + |> Integer.to_string() + |> String.replace(~r/\B(?=(\d{3})+(?!\d))/, ",") + end + + def format_unit(nil, _count), do: nil + def format_unit(unit, 1), do: singular_unit(unit) + def format_unit(unit, _count), do: unit + + defp next_disabled?(%{count: count, page: page}) when count < page, do: true + + defp next_disabled?(%{total: total, offset: offset, count: count}) when not is_nil(total), + do: offset + count >= total + + defp next_disabled?(_assigns), do: false + + defp total_text(nil, _unit), do: nil + + defp total_text(total, unit) do + unit = if unit, do: " " <> format_unit(unit, total), else: "" + " of #{format_count(total)}#{unit}" + end + + defp singular_unit(unit) do + if String.ends_with?(unit, "s") do + String.trim_trailing(unit, "s") + else + unit + end + end + attr(:state, :any, required: true) def state_badge(assigns) do diff --git a/lib/bob_web/live/artifacts_live.ex b/lib/bob_web/live/artifacts_live.ex index 0197aa01..656c52df 100644 --- a/lib/bob_web/live/artifacts_live.ex +++ b/lib/bob_web/live/artifacts_live.ex @@ -14,11 +14,15 @@ defmodule BobWeb.ArtifactsLive do os: "", offset: 0, page: @page, - kinds: Bob.Artifacts.distinct_kinds(), - arches: Bob.Artifacts.distinct_arches(), - oses: Bob.Artifacts.distinct_oses() + kinds: [], + arches: [], + oses: [], + total: nil, + loading: true, + results: [] ) - |> load() + + socket = if connected?(socket), do: socket |> load_options() |> load(), else: socket {:ok, socket} end @@ -47,17 +51,27 @@ defmodule BobWeb.ArtifactsLive do defp step("next"), do: @page defp step("prev"), do: -@page + defp load_options(socket) do + assign(socket, + kinds: Bob.Artifacts.distinct_kinds(), + arches: Bob.Artifacts.distinct_arches(), + oses: Bob.Artifacts.distinct_oses() + ) + end + defp load(socket) do %{query: q, kind: kind, arch: arch, os: os, offset: offset} = socket.assigns + filters = %{query: q, kind: kind, arch: arch, os: os} + results = - Bob.Artifacts.search_artifacts( - %{query: q, kind: kind, arch: arch, os: os}, - @page, - offset - ) + Bob.Artifacts.search_artifacts(filters, @page, offset) - assign(socket, results: results) + assign(socket, + results: results, + total: Bob.Artifacts.count_artifacts(filters), + loading: false + ) end defp fmt(nil), do: "—" @@ -87,10 +101,12 @@ defmodule BobWeb.ArtifactsLive do <.filter_select name="kind" label="kind" value={@kind} options={@kinds} /> <.filter_select name="arch" label="arch" value={@arch} options={@arches} /> <.filter_select name="os" label="os" value={@os} options={@oses} /> - <%= length(@results) %> artifacts + <%= artifact_count_label(@total) %> - <.table :if={@results != []} rows={@results} class="jt--art"> +
Loading artifacts...
+ + <.table :if={!@loading and @results != []} rows={@results} class="jt--art"> <:col :let={a} label="kind"> <%= a.kind %> @@ -116,17 +132,25 @@ defmodule BobWeb.ArtifactsLive do <%= fmt(a.built_at) %> -
No matching artifacts.
+
No matching artifacts.
<.pager + :if={!@loading} event="page" offset={@offset} count={length(@results)} page={@page} unit="artifacts" + total={@total} />
""" end + + defp artifact_count_label(nil), do: "Loading artifacts" + + defp artifact_count_label(count) do + "#{format_count(count)} #{format_unit("artifacts", count)}" + end end diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex index 64001bf1..bc560d05 100644 --- a/lib/bob_web/live/docker_tags_live.ex +++ b/lib/bob_web/live/docker_tags_live.ex @@ -5,6 +5,8 @@ defmodule BobWeb.DockerTagsLive do @impl true def mount(_params, _session, socket) do + options = Bob.Artifacts.docker_tag_filter_options() + socket = socket |> assign( @@ -17,11 +19,15 @@ defmodule BobWeb.DockerTagsLive do os_version: "", offset: 0, page: @page, - repos: Bob.Artifacts.distinct_repos(), - arches: Bob.Artifacts.distinct_docker_arches(), - oses: Bob.Artifacts.distinct_docker_oses() + repos: options.repos, + arches: options.arches, + oses: options.oses, + total: nil, + loading: true, + results: [] ) - |> load() + + socket = if connected?(socket), do: load(socket), else: socket {:ok, socket} end @@ -70,27 +76,38 @@ defmodule BobWeb.DockerTagsLive do offset: offset } = socket.assigns - results = - Bob.Artifacts.search_docker_tags( - %{ - repo: repo, - tag: tag, - arch: arch, - elixir_version: elixir_version, - erlang_version: erlang_version, - os: os, - os_version: os_version - }, - @page, - offset - ) + filters = %{ + repo: repo, + tag: tag, + arch: arch, + elixir_version: elixir_version, + erlang_version: erlang_version, + os: os, + os_version: os_version + } - assign(socket, results: results) + results = + Bob.Artifacts.search_docker_tags(filters, @page, offset) + + total = + if offset == 0 and results == [] do + 0 + else + filters + |> Bob.Artifacts.count_docker_tags() + |> max(offset + length(results)) + end + + assign(socket, results: results, total: total, loading: false) end defp fmt(nil), do: "—" defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") + defp count_label(nil), do: "Loading tags" + defp count_label(0), do: "0 tags" + defp count_label(count), do: "#{format_count(count)} #{format_unit("tags", count)}" + @impl true def render(assigns) do ~H""" @@ -134,10 +151,12 @@ defmodule BobWeb.DockerTagsLive do />
<.filter_select name="arch" label="arch" value={@arch} options={@arches} /> - <%= length(@results) %> tags + <%= count_label(@total) %> - <.table :if={@results != []} rows={@results} class="jt--dk"> +
Loading tags...
+ + <.table :if={!@loading and @results != []} rows={@results} class="jt--dk"> <:col :let={d} label="repo">
<.icon name="docker" class="icon-blue" /> @@ -156,9 +175,17 @@ defmodule BobWeb.DockerTagsLive do <%= fmt(d.built_at) %> -
No matching tags.
- - <.pager event="page" offset={@offset} count={length(@results)} page={@page} unit="tags" /> +
No matching tags.
+ + <.pager + :if={!@loading} + event="page" + offset={@offset} + count={length(@results)} + page={@page} + unit="tags" + total={@total} + />
""" diff --git a/lib/bob_web/live/jobs_live.ex b/lib/bob_web/live/jobs_live.ex index f192ac8c..8ffffe2b 100644 --- a/lib/bob_web/live/jobs_live.ex +++ b/lib/bob_web/live/jobs_live.ex @@ -16,9 +16,17 @@ defmodule BobWeb.JobsLive do past_offset: 0, refresh_scheduled: false, queued_page: @queued_page, - past_page: @past_page + past_page: @past_page, + loading: true, + running: [], + queue_sizes: [], + queue_total: 0, + queued: [], + past: [], + past_total: 0 ) - |> load() + + socket = if connected?(socket), do: load(socket), else: socket {:ok, socket} end @@ -61,7 +69,9 @@ defmodule BobWeb.JobsLive do queue_sizes: queue_sizes, queue_total: Enum.sum(Enum.map(queue_sizes, fn {_mod, count} -> count end)), queued: Bob.Queue.queued_listing(@queued_page, socket.assigns.queued_offset), - past: Bob.Queue.recent(@past_page, socket.assigns.past_offset) + past: Bob.Queue.recent(@past_page, socket.assigns.past_offset), + past_total: Bob.Queue.finished_count(), + loading: false ) end @@ -134,7 +144,9 @@ defmodule BobWeb.JobsLive do icon="bolt" icon_class={if @running == [], do: "icon-muted", else: "icon-blue"} > - <.table :if={@running != []} rows={@running}> +
Loading jobs...
+ + <.table :if={!@loading and @running != []} rows={@running}> <:col :let={_j} label="State" class="col-state">
<.state_dot state="running" /> @@ -154,11 +166,13 @@ defmodule BobWeb.JobsLive do <%= fmt_duration(elapsed(j.started_at)) %> -
Nothing running.
+
Nothing running.
<.section title="Queue" count={@queue_total} icon="queue"> -
+
Loading queue...
+ +
Queued by job type
@@ -173,7 +187,7 @@ defmodule BobWeb.JobsLive do
oldest first
- <.table :if={@queued != []} rows={@queued}> + <.table :if={!@loading and @queued != []} rows={@queued}> <:col :let={j} label="Module"> <.module_cell cat={job_cat(j.module_key)} module={module_name(j.module_key)} /> @@ -184,18 +198,22 @@ defmodule BobWeb.JobsLive do <%= fmt(j.inserted_at) %> -
Queue is empty.
+
Queue is empty.
<.pager + :if={!@loading} event="queued_page" offset={@queued_offset} count={length(@queued)} page={@queued_page} unit="queued" + total={@queue_total} /> - <.section title="Past" count={length(@past)} icon="clock"> - <.table :if={@past != []} rows={@past}> + <.section title="Past" count={@past_total} icon="clock"> +
Loading finished jobs...
+ + <.table :if={!@loading and @past != []} rows={@past}> <:col :let={j} label="State" class="col-state"> <.state_badge state={j.state} /> @@ -212,12 +230,15 @@ defmodule BobWeb.JobsLive do <%= fmt(j.finished_at) %> -
No finished jobs.
+
No finished jobs.
<.pager + :if={!@loading} event="past_page" offset={@past_offset} count={length(@past)} page={@past_page} + unit="jobs" + total={@past_total} />
diff --git a/priv/repo/migrations/20260609014923_index_docker_tags_by_built_at.exs b/priv/repo/migrations/20260609014923_index_docker_tags_by_built_at.exs new file mode 100644 index 00000000..018ee3b9 --- /dev/null +++ b/priv/repo/migrations/20260609014923_index_docker_tags_by_built_at.exs @@ -0,0 +1,17 @@ +defmodule Bob.Repo.Migrations.IndexDockerTagsByBuiltAt do + use Ecto.Migration + + @disable_ddl_transaction true + @disable_migration_lock true + + def up do + execute(""" + CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_built_at_id_desc_index + ON docker_tags (built_at DESC, id DESC) + """) + end + + def down do + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_built_at_id_desc_index") + end +end diff --git a/priv/repo/migrations/20260609023000_index_docker_tags_archs.exs b/priv/repo/migrations/20260609023000_index_docker_tags_archs.exs new file mode 100644 index 00000000..1f509a2f --- /dev/null +++ b/priv/repo/migrations/20260609023000_index_docker_tags_archs.exs @@ -0,0 +1,14 @@ +defmodule Bob.Repo.Migrations.IndexDockerTagsArchs do + use Ecto.Migration + + @disable_ddl_transaction true + @disable_migration_lock true + + def up do + execute("CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_archs_gin_index ON docker_tags USING GIN (archs)") + end + + def down do + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_archs_gin_index") + end +end diff --git a/priv/repo/migrations/20260609025000_add_built_at_to_docker_tags_staging.exs b/priv/repo/migrations/20260609025000_add_built_at_to_docker_tags_staging.exs new file mode 100644 index 00000000..bd3e1625 --- /dev/null +++ b/priv/repo/migrations/20260609025000_add_built_at_to_docker_tags_staging.exs @@ -0,0 +1,13 @@ +defmodule Bob.Repo.Migrations.AddBuiltAtToDockerTagsStaging do + use Ecto.Migration + + def up do + execute("ALTER TABLE docker_tags_staging ADD COLUMN built_at timestamp") + execute("UPDATE docker_tags_staging SET built_at = inserted_at") + execute("ALTER TABLE docker_tags_staging ALTER COLUMN built_at SET NOT NULL") + end + + def down do + execute("ALTER TABLE docker_tags_staging DROP COLUMN built_at") + end +end diff --git a/test/bob/artifacts/docker_tag_search_test.exs b/test/bob/artifacts/docker_tag_search_test.exs index ea4ddd8e..21f9f272 100644 --- a/test/bob/artifacts/docker_tag_search_test.exs +++ b/test/bob/artifacts/docker_tag_search_test.exs @@ -3,6 +3,20 @@ defmodule Bob.Artifacts.DockerTagSearchTest do alias Bob.Artifacts.DockerTagSearch + test "returns known Docker tag dimensions" do + assert DockerTagSearch.repos() == [ + "hexpm/elixir", + "hexpm/elixir-amd64", + "hexpm/elixir-arm64", + "hexpm/erlang", + "hexpm/erlang-amd64", + "hexpm/erlang-arm64" + ] + + assert DockerTagSearch.arches() == ["amd64", "arm64"] + assert DockerTagSearch.oses() == ["alpine", "debian", "ubuntu"] + end + test "parses per-arch Erlang tags" do assert DockerTagSearch.metadata( "hexpm/erlang-amd64", diff --git a/test/bob/artifacts_test.exs b/test/bob/artifacts_test.exs index 20e142ff..0ff08043 100644 --- a/test/bob/artifacts_test.exs +++ b/test/bob/artifacts_test.exs @@ -4,6 +4,9 @@ defmodule Bob.ArtifactsTest do alias Bob.Artifacts alias Bob.Artifacts.{Artifact, BaseImageTag, DockerTag, DockerTagStaging} + @docker_built_at ~U[2025-01-02 03:04:05.000000Z] + @newer_docker_built_at ~U[2025-02-03 04:05:06.000000Z] + describe "Artifact.changeset/2" do test "casts a posted artifact, parsing the ISO8601 date" do changeset = @@ -202,6 +205,17 @@ defmodule Bob.ArtifactsTest do ] = Repo.all(DockerTag) end + test "stores the supplied Docker Hub timestamp as built_at" do + Artifacts.add_docker_tag( + "hexpm/erlang-amd64", + "27.0-ubuntu-noble-20250101", + ["amd64"], + @docker_built_at + ) + + assert [%DockerTag{built_at: @docker_built_at}] = Repo.all(DockerTag) + end + test "unions archs on conflicting (repo, tag)" do Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", ["amd64"]) Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", ["arm64"]) @@ -235,11 +249,12 @@ defmodule Bob.ArtifactsTest do token = Ecto.UUID.generate() Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ - {"27.0-ubuntu-noble-20250101", ["amd64"]} + docker_tag("27.0-ubuntu-noble-20250101", ["amd64"]) ]) assert [ %DockerTagStaging{ + built_at: @docker_built_at, search: %{ "erlang_version" => "27.0", "os" => "ubuntu", @@ -261,6 +276,33 @@ defmodule Bob.ArtifactsTest do ] = Repo.all(DockerTag) end + test "swaps the staged Docker Hub timestamp into built_at" do + replace("hexpm/erlang-amd64", [ + docker_tag("27.0-ubuntu-noble-20250101", ["amd64"], @docker_built_at) + ]) + + assert [%DockerTag{built_at: @docker_built_at}] = Repo.all(DockerTag) + end + + test "updates built_at for otherwise unchanged rows" do + Artifacts.add_docker_tag( + "hexpm/erlang-amd64", + "27.0-ubuntu-noble-20250101", + ["amd64"], + @docker_built_at + ) + + inserted = Repo.one(DockerTag) + + replace("hexpm/erlang-amd64", [ + docker_tag("27.0-ubuntu-noble-20250101", ["amd64"], @newer_docker_built_at) + ]) + + updated = Repo.one(DockerTag) + assert updated.built_at == @newer_docker_built_at + assert DateTime.compare(updated.updated_at, inserted.updated_at) == :gt + end + test "inserts the staged tags with their arch lists" do assert replace("hexpm/erlang-amd64", [ {"27.0-ubuntu-noble-20250101", ["amd64"]}, @@ -302,11 +344,19 @@ defmodule Bob.ArtifactsTest do test "collapses duplicate tags staged across pages (Docker Hub returns dupes)" do token = Ecto.UUID.generate() - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"27.0", ["amd64"]}]) - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"27.0", ["amd64"]}]) + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("27.0", ["amd64"], @docker_built_at) + ]) + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("27.0", ["amd64"], @newer_docker_built_at) + ]) + assert Artifacts.swap_docker_tags(token, "hexpm/erlang-amd64") == :ok assert Artifacts.docker_tags("hexpm/erlang-amd64") == [{"27.0", ["amd64"]}] + assert [%DockerTag{built_at: @newer_docker_built_at}] = Repo.all(DockerTag) end test "streams more tags than fit in a single statement's parameter limit" do @@ -316,7 +366,7 @@ defmodule Bob.ArtifactsTest do Artifacts.stage_docker_tags( token, "hexpm/erlang-amd64", - Enum.map(page, &{"tag-#{&1}", ["amd64"]}) + Enum.map(page, &docker_tag("tag-#{&1}", ["amd64"])) ) end @@ -328,8 +378,13 @@ defmodule Bob.ArtifactsTest do a = Ecto.UUID.generate() b = Ecto.UUID.generate() - Artifacts.stage_docker_tags(a, "hexpm/erlang-amd64", [{"from-a", ["amd64"]}]) - Artifacts.stage_docker_tags(b, "hexpm/erlang-amd64", [{"from-b", ["amd64"]}]) + Artifacts.stage_docker_tags(a, "hexpm/erlang-amd64", [ + docker_tag("from-a", ["amd64"]) + ]) + + Artifacts.stage_docker_tags(b, "hexpm/erlang-amd64", [ + docker_tag("from-b", ["amd64"]) + ]) assert Artifacts.staged_tag_count(a, "hexpm/erlang-amd64") == 1 assert Artifacts.swap_docker_tags(a, "hexpm/erlang-amd64") == :ok @@ -343,7 +398,10 @@ defmodule Bob.ArtifactsTest do describe "staged_any?/2" do test "is true only when a tag is staged for the token and repo" do token = Ecto.UUID.generate() - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"a", ["amd64"]}]) + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("a", ["amd64"]) + ]) assert Artifacts.staged_any?(token, "hexpm/erlang-amd64") refute Artifacts.staged_any?(token, "hexpm/elixir-amd64") @@ -356,11 +414,13 @@ defmodule Bob.ArtifactsTest do token = Ecto.UUID.generate() Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ - {"a", ["amd64"]}, - {"b", ["amd64"]} + docker_tag("a", ["amd64"]), + docker_tag("b", ["amd64"]) ]) - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"a", ["amd64"]}]) + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("a", ["amd64"]) + ]) assert Artifacts.staged_tag_count(token, "hexpm/erlang-amd64") == 2 assert Artifacts.staged_tag_count(token, "hexpm/elixir-amd64") == 0 @@ -372,8 +432,8 @@ defmodule Bob.ArtifactsTest do token = Ecto.UUID.generate() Artifacts.stage_docker_tags(token, "library/alpine", [ - {"3.23.5", ["amd64", "arm64", "386"]}, - {"3.22.1", ["amd64"]} + docker_tag("3.23.5", ["amd64", "arm64", "386"]), + docker_tag("3.22.1", ["amd64"]) ]) assert Artifacts.staged_multi_arch_tags(token, "library/alpine", ["amd64", "arm64"]) == @@ -384,7 +444,10 @@ defmodule Bob.ArtifactsTest do describe "discard_staging/1" do test "drops every row for the token" do token = Ecto.UUID.generate() - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"a", ["amd64"]}]) + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("a", ["amd64"]) + ]) assert Artifacts.discard_staging(token) == :ok assert Artifacts.staged_tag_count(token, "hexpm/erlang-amd64") == 0 @@ -394,7 +457,10 @@ defmodule Bob.ArtifactsTest do describe "prune_staging/1" do test "deletes rows older than the threshold and keeps fresh ones" do token = Ecto.UUID.generate() - Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [{"fresh", ["amd64"]}]) + + Artifacts.stage_docker_tags(token, "hexpm/erlang-amd64", [ + docker_tag("fresh", ["amd64"]) + ]) stale = Ecto.UUID.generate() @@ -404,6 +470,7 @@ defmodule Bob.ArtifactsTest do repo: "hexpm/erlang-amd64", tag: "stale", archs: ["amd64"], + built_at: @docker_built_at, inserted_at: NaiveDateTime.add(NaiveDateTime.utc_now(), -7 * 60 * 60, :second) } ]) @@ -510,6 +577,13 @@ defmodule Bob.ArtifactsTest do assert [%{arch: "arm64"}] = Bob.Artifacts.search_artifacts(%{arch: "arm64"}) end + test "count_artifacts/1 counts exact matching artifacts" do + assert Bob.Artifacts.count_artifacts(%{}) == 2 + assert Bob.Artifacts.count_artifacts(%{query: "27.0"}) == 1 + assert Bob.Artifacts.count_artifacts(%{arch: "arm64"}) == 1 + assert Bob.Artifacts.count_artifacts(%{os: "missing"}) == 0 + end + test "distinct value helpers" do assert Bob.Artifacts.distinct_kinds() == ["otp"] assert Bob.Artifacts.distinct_arches() == ["amd64", "arm64"] @@ -618,6 +692,30 @@ defmodule Bob.ArtifactsTest do }) end + test "count_docker_tags/1 counts exact matching tags" do + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", [ + "amd64", + "arm64" + ]) + + Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.1-ubuntu-noble-20250101", ["arm64"]) + + count = + Bob.Artifacts.count_docker_tags(%{ + repo: "hexpm/erl", + tag: "27", + arch: "arm", + erlang_version: "27", + os: "ub", + os_version: "noble" + }) + + assert count == 2 + assert Bob.Artifacts.count_docker_tags(%{arch: "amd64"}) == 1 + assert Bob.Artifacts.count_docker_tags(%{arch: "arm64"}) == 2 + assert Bob.Artifacts.count_docker_tags(%{tag: "missing"}) == 0 + end + test "search_artifacts/1 does not treat % as a LIKE wildcard" do assert Bob.Artifacts.search_artifacts(%{query: "%"}) == [] end @@ -640,10 +738,15 @@ defmodule Bob.ArtifactsTest do defp replace(repo, tag_archs) do token = Ecto.UUID.generate() - Artifacts.stage_docker_tags(token, repo, tag_archs) + Artifacts.stage_docker_tags(token, repo, Enum.map(tag_archs, &docker_tag_tuple/1)) Artifacts.swap_docker_tags(token, repo) end + defp docker_tag(tag, archs, built_at \\ @docker_built_at), do: {tag, archs, built_at} + + defp docker_tag_tuple({tag, archs}), do: docker_tag(tag, archs) + defp docker_tag_tuple({tag, archs, built_at}), do: docker_tag(tag, archs, built_at) + defp attrs() do %{ kind: "otp", diff --git a/test/bob/docker_hub_test.exs b/test/bob/docker_hub_test.exs new file mode 100644 index 00000000..56af27ec --- /dev/null +++ b/test/bob/docker_hub_test.exs @@ -0,0 +1,68 @@ +defmodule Bob.DockerHubTest do + use ExUnit.Case, async: true + + alias Bob.DockerHub + + @built_at ~U[2025-01-02 03:04:05.123456Z] + @image_pushed_at ~U[2025-02-03 04:05:06.000000Z] + + describe "parse/1" do + test "returns tag, archs, and Docker Hub last_updated timestamp" do + assert DockerHub.parse( + tag_payload(%{ + "last_updated" => "2025-01-02T03:04:05.123456Z", + "images" => [ + image("amd64", "sha256:amd64", "2025-02-03T04:05:06Z"), + image("arm64", "sha256:arm64", "2025-02-03T04:05:06Z") + ] + }) + ) == {"27.0", ["amd64", "arm64"], @built_at} + end + + test "falls back to image last_pushed when the tag timestamp is absent" do + assert DockerHub.parse( + tag_payload(%{ + "images" => [ + image("amd64", "sha256:amd64", "2025-01-03T04:05:06Z"), + image("arm64", "sha256:arm64", "2025-02-03T04:05:06Z") + ] + }) + ) == {"27.0", ["amd64", "arm64"], @image_pushed_at} + end + + test "rejects images without a digest" do + assert DockerHub.parse( + tag_payload(%{ + "last_updated" => "2025-01-02T03:04:05.123456Z", + "images" => [image("amd64", nil, "2025-02-03T04:05:06Z")] + }) + ) == nil + end + + test "rejects tags without a Docker Hub timestamp" do + assert DockerHub.parse( + tag_payload(%{ + "images" => [%{"architecture" => "amd64", "digest" => "sha256:amd64"}] + }) + ) == nil + end + end + + defp tag_payload(attrs) do + Map.merge( + %{ + "name" => "27.0", + "images" => [] + }, + attrs + ) + end + + defp image(arch, digest, last_pushed) do + %{ + "architecture" => arch, + "digest" => digest, + "last_pushed" => last_pushed + } + end +end diff --git a/test/bob/queue_test.exs b/test/bob/queue_test.exs index 4699320c..26295e61 100644 --- a/test/bob/queue_test.exs +++ b/test/bob/queue_test.exs @@ -274,5 +274,19 @@ defmodule Bob.QueueTest do assert Enum.map(recent, & &1.state) |> Enum.sort() == ["done", "failed"] assert hd(recent).finished_at >= List.last(recent).finished_at end + + test "finished_count/0 counts done and failed jobs" do + Bob.Queue.add(Bob.Job.OTPChecker, [:done]) + {:ok, {done_id, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + Bob.Queue.success(done_id) + + Bob.Queue.add(Bob.Job.OTPChecker, [:failed]) + {:ok, {failed_id, _}} = Bob.Queue.start(Bob.Job.OTPChecker) + Bob.Queue.failure(failed_id) + + Bob.Queue.add(Bob.Job.OTPChecker, [:queued]) + + assert Bob.Queue.finished_count() == 2 + end end end diff --git a/test/bob/reconcile_test.exs b/test/bob/reconcile_test.exs index dc0f51e0..1cc4a076 100644 --- a/test/bob/reconcile_test.exs +++ b/test/bob/reconcile_test.exs @@ -3,7 +3,10 @@ defmodule Bob.ReconcileTest do alias Bob.{Artifacts, Reconcile} - # Streamer stub: invokes on_page once with the canned {tag, archs} list for the + @docker_built_at ~U[2025-01-02 03:04:05.000000Z] + @newer_docker_built_at ~U[2025-02-03 04:05:06.000000Z] + + # Streamer stub: invokes on_page once with the canned {tag, archs, built_at} list for the # repo (mimicking a single Docker Hub page), or nothing for an empty repo. defp streamer(map) do fn repo, on_page -> @@ -20,8 +23,16 @@ defmodule Bob.ReconcileTest do test "stores per-arch erlang/elixir tags with the arch forced from the repo name" do stream = streamer(%{ - "hexpm/erlang-amd64" => [{"27.0-ubuntu-noble-20250101", ["amd64", "arm64"]}], - "hexpm/elixir-arm64" => [{"1.18.0-erlang-27.0-ubuntu-noble-20250101", ["amd64"]}] + "hexpm/erlang-amd64" => [ + docker_tag("27.0-ubuntu-noble-20250101", ["amd64", "arm64"], @docker_built_at) + ], + "hexpm/elixir-arm64" => [ + docker_tag( + "1.18.0-erlang-27.0-ubuntu-noble-20250101", + ["amd64"], + @newer_docker_built_at + ) + ] }) Reconcile.reconcile(stream) @@ -31,12 +42,26 @@ defmodule Bob.ReconcileTest do assert Artifacts.docker_tags("hexpm/elixir-arm64") == [{"1.18.0-erlang-27.0-ubuntu-noble-20250101", ["arm64"]}] + + assert %Bob.Artifacts.DockerTag{built_at: @docker_built_at} = + Repo.get_by!(Bob.Artifacts.DockerTag, + repo: "hexpm/erlang-amd64", + tag: "27.0-ubuntu-noble-20250101" + ) + + assert %Bob.Artifacts.DockerTag{built_at: @newer_docker_built_at} = + Repo.get_by!(Bob.Artifacts.DockerTag, + repo: "hexpm/elixir-arm64", + tag: "1.18.0-erlang-27.0-ubuntu-noble-20250101" + ) end test "stores manifest tags with the upstream archs intersected with known archs, sorted" do stream = streamer(%{ - "hexpm/erlang" => [{"27.0-ubuntu-noble-20250101", ["arm64", "amd64", "ppc64le"]}] + "hexpm/erlang" => [ + docker_tag("27.0-ubuntu-noble-20250101", ["arm64", "amd64", "ppc64le"]) + ] }) Reconcile.reconcile(stream) @@ -49,8 +74,8 @@ defmodule Bob.ReconcileTest do stream = streamer(%{ "library/alpine" => [ - {"3.23.5", ["amd64", "arm64", "386"]}, - {"3.22.1", ["amd64"]} + docker_tag("3.23.5", ["amd64", "arm64", "386"]), + docker_tag("3.22.1", ["amd64"]) ] }) @@ -62,7 +87,7 @@ defmodule Bob.ReconcileTest do test "keeps existing base image tags when no upstream tag is fully multi-arch" do Artifacts.replace_base_image_tags("library/alpine", ["3.23.5"]) - stream = streamer(%{"library/alpine" => [{"3.24.0", ["amd64"]}]}) + stream = streamer(%{"library/alpine" => [docker_tag("3.24.0", ["amd64"])]}) Reconcile.reconcile(stream) @@ -72,7 +97,7 @@ defmodule Bob.ReconcileTest do test "prunes docker tags that vanished upstream" do Artifacts.add_docker_tag("hexpm/erlang-amd64", "stale-tag", ["amd64"]) - stream = streamer(%{"hexpm/erlang-amd64" => [{"fresh-tag", ["amd64"]}]}) + stream = streamer(%{"hexpm/erlang-amd64" => [docker_tag("fresh-tag", ["amd64"])]}) Reconcile.reconcile(stream) @@ -92,7 +117,7 @@ defmodule Bob.ReconcileTest do stream = fn "hexpm/erlang-amd64", _on_page -> :error - "hexpm/elixir-arm64", on_page -> on_page.([{"fresh-tag", ["arm64"]}]) + "hexpm/elixir-arm64", on_page -> on_page.([docker_tag("fresh-tag", ["arm64"])]) _repo, _on_page -> :ok end @@ -107,7 +132,7 @@ defmodule Bob.ReconcileTest do stream = fn "hexpm/erlang-amd64", _on_page -> raise "DockerHub paging blew up" - "hexpm/elixir-arm64", on_page -> on_page.([{"fresh-tag", ["arm64"]}]) + "hexpm/elixir-arm64", on_page -> on_page.([docker_tag("fresh-tag", ["arm64"])]) _repo, _on_page -> :ok end @@ -120,8 +145,8 @@ defmodule Bob.ReconcileTest do test "leaves no staging rows behind after a run" do stream = streamer(%{ - "hexpm/erlang-amd64" => [{"27.0", ["amd64"]}], - "library/alpine" => [{"3.23.5", ["amd64", "arm64"]}] + "hexpm/erlang-amd64" => [docker_tag("27.0", ["amd64"])], + "library/alpine" => [docker_tag("3.23.5", ["amd64", "arm64"])] }) Reconcile.reconcile(stream) @@ -134,7 +159,7 @@ defmodule Bob.ReconcileTest do test "reconciles the per-arch repos only" do Artifacts.add_docker_tag("hexpm/erlang", "untouched", ["amd64"]) - stream = streamer(%{"hexpm/erlang-amd64" => [{"27.0", ["amd64", "arm64"]}]}) + stream = streamer(%{"hexpm/erlang-amd64" => [docker_tag("27.0", ["amd64", "arm64"])]}) Reconcile.reconcile_per_arch_repos(stream) @@ -147,7 +172,7 @@ defmodule Bob.ReconcileTest do test "reconciles the manifest repos only" do Artifacts.add_docker_tag("hexpm/erlang-amd64", "untouched", ["amd64"]) - stream = streamer(%{"hexpm/erlang" => [{"27.0", ["arm64", "amd64", "ppc64le"]}]}) + stream = streamer(%{"hexpm/erlang" => [docker_tag("27.0", ["arm64", "amd64", "ppc64le"])]}) Reconcile.reconcile_manifest_repos(stream) @@ -160,7 +185,7 @@ defmodule Bob.ReconcileTest do test "reconciles the base image repos only" do Artifacts.add_docker_tag("hexpm/erlang-amd64", "untouched", ["amd64"]) - stream = streamer(%{"library/alpine" => [{"3.23.5", ["amd64", "arm64"]}]}) + stream = streamer(%{"library/alpine" => [docker_tag("3.23.5", ["amd64", "arm64"])]}) Reconcile.reconcile_base_images(stream) @@ -223,4 +248,6 @@ defmodule Bob.ReconcileTest do assert Artifacts.built_otp_refs("amd64", "ubuntu-24.04") == %{"OTP-27.0" => "ref27"} end end + + defp docker_tag(tag, archs, built_at \\ @docker_built_at), do: {tag, archs, built_at} end diff --git a/test/bob_web/live/artifacts_live_test.exs b/test/bob_web/live/artifacts_live_test.exs index b00b5414..6f59a3e0 100644 --- a/test/bob_web/live/artifacts_live_test.exs +++ b/test/bob_web/live/artifacts_live_test.exs @@ -29,12 +29,16 @@ defmodule BobWeb.ArtifactsLiveTest do {:ok, view, html} = live(conn, ~p"/artifacts") assert html =~ "OTP-27.0" assert html =~ "OTP-26.2" + assert html =~ "2 artifacts" + assert html =~ ~r/Showing\s*1<\/b>\s*-\s*2<\/b>\s*artifacts\s*of\s*2 artifacts/ html = render_change(view, "search", %{"query" => "27.0", "kind" => "", "arch" => "", "os" => ""}) assert html =~ "OTP-27.0" refute html =~ "OTP-26.2" + assert html =~ "1 artifact" + assert html =~ ~r/Showing\s*1<\/b>\s*-\s*1<\/b>\s*artifact\s*of\s*1 artifact/ end test "filters by arch dropdown", %{conn: conn} do diff --git a/test/bob_web/live/docker_tags_live_test.exs b/test/bob_web/live/docker_tags_live_test.exs index 16b34eff..d64306ba 100644 --- a/test/bob_web/live/docker_tags_live_test.exs +++ b/test/bob_web/live/docker_tags_live_test.exs @@ -34,6 +34,8 @@ defmodule BobWeb.DockerTagsLiveTest do {:ok, view, html} = live(conn, ~p"/docker") assert html =~ "27.0-ubuntu-noble-20250101" assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" + assert html =~ "4 tags" + assert html =~ ~r/Showing\s*1<\/b>\s*-\s*4<\/b>\s*tags\s*of\s*4 tags/ html = render_change(view, "search", %{ diff --git a/test/bob_web/live/jobs_live_test.exs b/test/bob_web/live/jobs_live_test.exs index 67fd16ec..ace60f24 100644 --- a/test/bob_web/live/jobs_live_test.exs +++ b/test/bob_web/live/jobs_live_test.exs @@ -22,6 +22,8 @@ defmodule BobWeb.JobsLiveTest do assert html =~ "Past" assert html =~ "OTPChecker" assert html =~ "done" + assert html =~ ~r/Showing\s*1<\/b>\s*-\s*1<\/b>\s*queued\s*of\s*1 queued/ + assert html =~ ~r/Showing\s*1<\/b>\s*-\s*1<\/b>\s*job\s*of\s*1 job/ end test "root layout links favicon assets", %{conn: conn} do From 55446c43d2746a6c7f9fda4163d0bb7b7e7b97d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 11:35:33 +0200 Subject: [PATCH 19/24] Add Docker tag ordering coverage --- lib/bob/artifacts.ex | 1 - test/bob/artifacts_test.exs | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/bob/artifacts.ex b/lib/bob/artifacts.ex index 76c46fa1..64dc3557 100644 --- a/lib/bob/artifacts.ex +++ b/lib/bob/artifacts.ex @@ -110,7 +110,6 @@ defmodule Bob.Artifacts do updated_at = EXCLUDED.updated_at WHERE docker_tags.archs IS DISTINCT FROM EXCLUDED.archs OR docker_tags.search IS DISTINCT FROM EXCLUDED.search - -- TODO: Remove this built_at comparison after production Docker tag rows are corrected. OR docker_tags.built_at IS DISTINCT FROM EXCLUDED.built_at """, [token, repo, now], diff --git a/test/bob/artifacts_test.exs b/test/bob/artifacts_test.exs index 0ff08043..eab79537 100644 --- a/test/bob/artifacts_test.exs +++ b/test/bob/artifacts_test.exs @@ -569,6 +569,25 @@ defmodule Bob.ArtifactsTest do assert [%{name: "OTP-26.2"}, %{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{}) end + test "search_docker_tags/1 with blank filters returns newest first" do + Bob.Artifacts.add_docker_tag( + "hexpm/erlang", + "old-ubuntu-noble-20250101", + ["amd64"], + ~U[2025-01-01 00:00:00Z] + ) + + Bob.Artifacts.add_docker_tag( + "hexpm/erlang", + "new-ubuntu-noble-20250101", + ["amd64"], + ~U[2025-02-01 00:00:00Z] + ) + + assert [%{tag: "new-ubuntu-noble-20250101"}, %{tag: "old-ubuntu-noble-20250101"}] = + Bob.Artifacts.search_docker_tags(%{}) + end + test "search_artifacts/1 filters by free-text on name" do assert [%{name: "OTP-27.0"}] = Bob.Artifacts.search_artifacts(%{query: "27.0"}) end From c641ddca3c2b0545eb491f31f1db623c8aa02bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 11:52:53 +0200 Subject: [PATCH 20/24] Tick running job elapsed times --- lib/bob_web/live/jobs_live.ex | 28 +++++++++++++++++++++++++--- test/bob_web/live/jobs_live_test.exs | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/bob_web/live/jobs_live.ex b/lib/bob_web/live/jobs_live.ex index 8ffffe2b..3751a481 100644 --- a/lib/bob_web/live/jobs_live.ex +++ b/lib/bob_web/live/jobs_live.ex @@ -4,6 +4,7 @@ defmodule BobWeb.JobsLive do @queued_page 100 @past_page 50 @debounce_ms 250 + @tick_ms 1000 @impl true def mount(_params, _session, socket) do @@ -18,6 +19,8 @@ defmodule BobWeb.JobsLive do queued_page: @queued_page, past_page: @past_page, loading: true, + now: DateTime.utc_now(), + tick_scheduled: false, running: [], queue_sizes: [], queue_total: 0, @@ -27,6 +30,7 @@ defmodule BobWeb.JobsLive do ) socket = if connected?(socket), do: load(socket), else: socket + socket = if connected?(socket), do: schedule_tick(socket), else: socket {:ok, socket} end @@ -42,7 +46,16 @@ defmodule BobWeb.JobsLive do end def handle_info(:refresh, socket) do - {:noreply, socket |> assign(refresh_scheduled: false) |> load()} + {:noreply, socket |> assign(refresh_scheduled: false) |> load() |> schedule_tick()} + end + + def handle_info(:tick, socket) do + socket = + socket + |> assign(now: DateTime.utc_now(), tick_scheduled: false) + |> schedule_tick() + + {:noreply, socket} end @impl true @@ -66,6 +79,7 @@ defmodule BobWeb.JobsLive do assign(socket, running: Bob.Queue.running(), + now: DateTime.utc_now(), queue_sizes: queue_sizes, queue_total: Enum.sum(Enum.map(queue_sizes, fn {_mod, count} -> count end)), queued: Bob.Queue.queued_listing(@queued_page, socket.assigns.queued_offset), @@ -75,6 +89,14 @@ defmodule BobWeb.JobsLive do ) end + defp schedule_tick(%{assigns: %{running: [], tick_scheduled: false}} = socket), do: socket + defp schedule_tick(%{assigns: %{tick_scheduled: true}} = socket), do: socket + + defp schedule_tick(socket) do + Process.send_after(self(), :tick, @tick_ms) + assign(socket, tick_scheduled: true) + end + defp fmt(nil), do: "—" defp fmt(datetime), do: Calendar.strftime(datetime, "%Y-%m-%d %H:%M:%S") @@ -94,7 +116,7 @@ defmodule BobWeb.JobsLive do "#{hours}h #{minutes}m" end - defp elapsed(datetime), do: duration(datetime, DateTime.utc_now()) + defp elapsed(datetime, now), do: duration(datetime, now) defp duration(%{started_at: started_at, finished_at: finished_at}), do: duration(started_at, finished_at) @@ -163,7 +185,7 @@ defmodule BobWeb.JobsLive do <%= fmt(j.started_at) %> <:col :let={j} label="Elapsed" class="col-time"> - <%= fmt_duration(elapsed(j.started_at)) %> + <%= fmt_duration(elapsed(j.started_at, @now)) %>
Nothing running.
diff --git a/test/bob_web/live/jobs_live_test.exs b/test/bob_web/live/jobs_live_test.exs index ace60f24..436c2b22 100644 --- a/test/bob_web/live/jobs_live_test.exs +++ b/test/bob_web/live/jobs_live_test.exs @@ -1,6 +1,7 @@ defmodule BobWeb.JobsLiveTest do use BobWeb.ConnCase + import Ecto.Query import Phoenix.LiveViewTest @debounce_pause 400 @@ -45,4 +46,21 @@ defmodule BobWeb.JobsLiveTest do Process.sleep(@debounce_pause) assert render(view) =~ ":refreshed" end + + test "ticks elapsed time for running jobs", %{conn: conn} do + Bob.Queue.add(Bob.Job.OTPChecker, [:elapsed_tick]) + {:ok, {id, _args}} = Bob.Queue.start(Bob.Job.OTPChecker) + + started_at = DateTime.add(DateTime.utc_now(), -10, :second) + + Bob.Repo.update_all( + from(j in Bob.Queue.Job, where: j.id == ^id), + set: [started_at: started_at, updated_at: started_at] + ) + + {:ok, view, _html} = live(conn, ~p"/") + + Process.sleep(1600) + assert render(view) =~ ~r/1[1-3]s/ + end end From 6f0d180d6112c9c65ba8c0c2115173afecd2edd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 11:59:15 +0200 Subject: [PATCH 21/24] Remove queue ordering hint --- lib/bob_web/live/jobs_live.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/bob_web/live/jobs_live.ex b/lib/bob_web/live/jobs_live.ex index 3751a481..e81e7fe6 100644 --- a/lib/bob_web/live/jobs_live.ex +++ b/lib/bob_web/live/jobs_live.ex @@ -206,9 +206,6 @@ defmodule BobWeb.JobsLive do
-
- oldest first -
<.table :if={!@loading and @queued != []} rows={@queued}> <:col :let={j} label="Module"> <.module_cell cat={job_cat(j.module_key)} module={module_name(j.module_key)} /> From 2522c190b3c972a3c15bf9c9c1f41e4dda3e762c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 12:25:16 +0200 Subject: [PATCH 22/24] Remove unused vendor placeholder --- assets/vendor/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 assets/vendor/.gitkeep diff --git a/assets/vendor/.gitkeep b/assets/vendor/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 65a9cdc17de304ef8356becba85ef21c7a6be5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 12:59:13 +0200 Subject: [PATCH 23/24] Improve read-only web UI on mobile --- assets/css/app.css | 206 ++++++++++++++++++ lib/bob/artifacts.ex | 24 +- lib/bob_web/components/core_components.ex | 1 + lib/bob_web/components/layouts.ex | 11 +- lib/bob_web/components/layouts/root.html.heex | 26 +++ lib/bob_web/live/docker_tags_live.ex | 8 +- test/bob/artifacts_test.exs | 9 +- test/bob_web/live/docker_tags_live_test.exs | 21 +- 8 files changed, 267 insertions(+), 39 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 21f9f92b..0abcd742 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -183,6 +183,87 @@ pre, gap: 14px; } +.bob-menu { + display: none; + position: relative; + margin-left: auto; +} + +.bob-menu__button { + display: inline-flex; + align-items: center; + gap: 8px; + height: 36px; + border: 1px solid rgba(255, 255, 255, 0.12); + border-radius: 8px; + background: rgba(255, 255, 255, 0.06); + color: #fff; + padding: 0 12px; + font-size: 14px; + font-weight: 600; + cursor: pointer; + list-style: none; +} + +.bob-menu__button::-webkit-details-marker { + display: none; +} + +.bob-menu__button::marker { + content: ""; +} + +.bob-menu__button:hover, +.bob-menu[open] .bob-menu__button { + background: rgba(255, 255, 255, 0.1); +} + +.bob-menu__panel { + position: absolute; + top: calc(100% + 10px); + right: 0; + z-index: 80; + display: grid; + min-width: 220px; + padding: 8px; + border: 1px solid var(--color-grey-200); + border-radius: 8px; + background: #fff; + box-shadow: 0 18px 40px rgba(12, 20, 33, 0.2); +} + +.bob-menu__item { + display: flex; + align-items: center; + gap: 10px; + min-height: 38px; + border-radius: 6px; + color: var(--color-grey-600); + padding: 0 10px; + font-size: 14px; + font-weight: 600; +} + +.bob-menu__item svg { + color: var(--color-grey-400); +} + +.bob-menu__item:hover, +.bob-menu__item--active { + background: var(--color-grey-100); + color: var(--color-grey-800); +} + +.bob-menu__item--active svg { + color: var(--color-primary-600); +} + +.bob-menu__item--external { + margin-top: 6px; + border-top: 1px solid var(--color-grey-100); + padding-top: 6px; +} + .nav-ext { display: inline-flex; align-items: center; @@ -568,6 +649,10 @@ pre, opacity: 0.45; } +.dk-filters { + align-items: stretch; +} + .chip-row { display: flex; align-items: center; @@ -618,10 +703,12 @@ pre, } .tbl-wrap { + max-width: 100%; overflow-x: auto; } .jt { + min-width: 720px; width: 100%; border-collapse: collapse; } @@ -681,6 +768,8 @@ pre, } .col-time { + width: 190px; + min-width: 190px; white-space: nowrap; } @@ -727,24 +816,34 @@ pre, } .c-time { + display: block; + overflow: hidden; color: var(--color-grey-600); font-size: 13px; font-variant-numeric: tabular-nums; + text-overflow: ellipsis; white-space: nowrap; } .c-dur { + display: block; + overflow: hidden; color: var(--color-grey-500); font-size: 13px; font-variant-numeric: tabular-nums; + text-overflow: ellipsis; white-space: nowrap; } .c-elapsed { + display: block; + overflow: hidden; color: var(--color-blue-700); font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; } .badge { @@ -901,6 +1000,34 @@ pre, gap: 8px; } +.jt--dk { + min-width: 1040px; + table-layout: fixed; +} + +.col-dk-repo { + width: 180px; +} + +.col-dk-tag { + width: 510px; +} + +.col-dk-archs { + width: 130px; +} + +.dk-tag-code { + display: block; + overflow: hidden; + width: 100%; + color: var(--color-grey-600); + font-family: var(--font-mono); + font-size: 12.5px; + text-overflow: ellipsis; + white-space: nowrap; +} + .pager { display: flex; align-items: center; @@ -986,10 +1113,25 @@ pre, } .bob-nav__inner { + max-width: none; + width: 100%; + margin: 0; gap: 16px; padding: 0 16px; } + .bob-nav__tabs { + display: none; + } + + .bob-nav__right { + display: none; + } + + .bob-menu { + display: block; + } + .bob-wrap { padding: 20px 16px 80px; } @@ -1009,6 +1151,70 @@ pre, margin-left: 0; } + .filter-bar.dk-filters { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + align-items: stretch; + gap: 10px; + padding: 12px; + } + + .dk-filters > .finput, + .dk-filters > .fgroup, + .dk-filters > .f-or { + grid-column: 1 / -1; + } + + .dk-filters > .fsel:first-child { + grid-column: 1 / -1; + } + + .dk-filters .fgroup { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 8px; + padding: 8px; + } + + .dk-filters .fsel, + .dk-filters .finput { + width: 100%; + min-width: 0; + } + + .dk-filters .fsel { + display: grid; + grid-template-columns: auto minmax(0, 1fr); + } + + .dk-filters .fsel select, + .dk-filters .finput input { + width: 100%; + min-width: 0; + } + + .dk-filters .f-or { + display: flex; + align-items: center; + gap: 8px; + padding: 0; + } + + .dk-filters .f-or::before, + .dk-filters .f-or::after { + content: ""; + height: 1px; + flex: 1; + background: var(--color-grey-200); + } + + .dk-filters .filter-bar__meta { + align-self: center; + justify-self: end; + width: auto; + text-align: right; + } + .qsizes__grid { grid-template-columns: 1fr; } diff --git a/lib/bob/artifacts.ex b/lib/bob/artifacts.ex index 64dc3557..cfec31f3 100644 --- a/lib/bob/artifacts.ex +++ b/lib/bob/artifacts.ex @@ -250,29 +250,9 @@ defmodule Bob.Artifacts do } end - def distinct_docker_arches() do - %{rows: rows} = - Repo.query!(""" - SELECT DISTINCT arches.arch - FROM docker_tags - CROSS JOIN LATERAL unnest(archs) AS arches(arch) - ORDER BY arches.arch - """) - - Enum.map(rows, fn [arch] -> arch end) - end + def distinct_docker_arches(), do: DockerTagSearch.arches() - def distinct_docker_oses() do - %{rows: rows} = - Repo.query!(""" - SELECT DISTINCT search->>'os' AS os - FROM docker_tags - WHERE search->>'os' IS NOT NULL - ORDER BY os - """) - - Enum.map(rows, fn [os] -> os end) - end + def distinct_docker_oses(), do: DockerTagSearch.oses() defp distinct_values(schema, field) do Repo.all( diff --git a/lib/bob_web/components/core_components.ex b/lib/bob_web/components/core_components.ex index beb6feb2..9c0c8355 100644 --- a/lib/bob_web/components/core_components.ex +++ b/lib/bob_web/components/core_components.ex @@ -263,6 +263,7 @@ defmodule BobWeb.CoreComponents do defp icon_paths("x"), do: ["M6 18L18 6M6 6l12 12"] defp icon_paths("bolt"), do: ["M3.75 13.5l10.5-11.25-1.5 9h6.75L9 22.5l1.5-9h-6.75z"] defp icon_paths("clock"), do: ["M12 6v6l4 2m6-2a9 9 0 11-18 0 9 9 0 0118 0z"] + defp icon_paths("menu"), do: icon_paths("queue") defp icon_paths("queue"), do: ["M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5"] defp icon_paths("box"), diff --git a/lib/bob_web/components/layouts.ex b/lib/bob_web/components/layouts.ex index c129d41b..d15516c1 100644 --- a/lib/bob_web/components/layouts.ex +++ b/lib/bob_web/components/layouts.ex @@ -1,8 +1,6 @@ defmodule BobWeb.Layouts do use BobWeb, :html - embed_templates("layouts/*") - def nav_class(current_path, target_path) do [ "bob-nav__tab", @@ -10,8 +8,17 @@ defmodule BobWeb.Layouts do ] end + def menu_class(current_path, target_path) do + [ + "bob-menu__item", + nav_active?(current_path, target_path) && "bob-menu__item--active" + ] + end + defp nav_active?("/", "/"), do: true defp nav_active?("/artifacts", "/artifacts"), do: true defp nav_active?("/docker", "/docker"), do: true defp nav_active?(_current_path, _target_path), do: false + + embed_templates("layouts/*") end diff --git a/lib/bob_web/components/layouts/root.html.heex b/lib/bob_web/components/layouts/root.html.heex index df815e31..2c16711c 100644 --- a/lib/bob_web/components/layouts/root.html.heex +++ b/lib/bob_web/components/layouts/root.html.heex @@ -44,6 +44,32 @@ <.icon name="external" /> hexpm/bob
+ +
+ + <.icon name="menu" /> + Menu + + +
diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex index bc560d05..17747483 100644 --- a/lib/bob_web/live/docker_tags_live.ex +++ b/lib/bob_web/live/docker_tags_live.ex @@ -157,16 +157,16 @@ defmodule BobWeb.DockerTagsLive do
Loading tags...
<.table :if={!@loading and @results != []} rows={@results} class="jt--dk"> - <:col :let={d} label="repo"> + <:col :let={d} label="repo" class="col-dk-repo">
<.icon name="docker" class="icon-blue" /> <%= d.repo %>
- <:col :let={d} label="tag"> - <%= d.tag %> + <:col :let={d} label="tag" class="col-dk-tag"> + <%= d.tag %> - <:col :let={d} label="archs"> + <:col :let={d} label="archs" class="col-dk-archs">
<%= arch %>
diff --git a/test/bob/artifacts_test.exs b/test/bob/artifacts_test.exs index eab79537..847312a2 100644 --- a/test/bob/artifacts_test.exs +++ b/test/bob/artifacts_test.exs @@ -609,7 +609,12 @@ defmodule Bob.ArtifactsTest do assert Bob.Artifacts.distinct_oses() == ["ubuntu-22.04", "ubuntu-24.04"] end - test "distinct Docker value helpers" do + test "distinct Docker filter helpers" do + assert Bob.Artifacts.distinct_docker_arches() == ["amd64", "arm64"] + assert Bob.Artifacts.distinct_docker_oses() == ["alpine", "debian", "ubuntu"] + end + + test "distinct Docker repositories" do Bob.Artifacts.add_docker_tag("hexpm/erlang", "27.0-ubuntu-noble-20250101", [ "amd64", "arm64" @@ -622,8 +627,6 @@ defmodule Bob.ArtifactsTest do ) assert Bob.Artifacts.distinct_repos() == ["hexpm/elixir", "hexpm/erlang"] - assert Bob.Artifacts.distinct_docker_arches() == ["amd64", "arm64"] - assert Bob.Artifacts.distinct_docker_oses() == ["debian", "ubuntu"] end test "search_docker_tags/1 filters by structured prefixes" do diff --git a/test/bob_web/live/docker_tags_live_test.exs b/test/bob_web/live/docker_tags_live_test.exs index d64306ba..5035809c 100644 --- a/test/bob_web/live/docker_tags_live_test.exs +++ b/test/bob_web/live/docker_tags_live_test.exs @@ -48,8 +48,8 @@ defmodule BobWeb.DockerTagsLiveTest do "os_version" => "" }) - assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" - refute html =~ "27.0-ubuntu-noble-20250101" + assert docker_tag?(html, "1.18.0-erlang-27.0-ubuntu-noble-20250101") + refute docker_tag?(html, "27.0-ubuntu-noble-20250101") end test "filters by structured inputs", %{conn: conn} do @@ -66,9 +66,9 @@ defmodule BobWeb.DockerTagsLiveTest do "os_version" => "noble" }) - assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" - refute html =~ "1.17.3-erlang-26.2-debian-bookworm-20250113-slim" - refute html =~ "27.0-ubuntu-noble-20250101" + assert docker_tag?(html, "1.18.0-erlang-27.0-ubuntu-noble-20250101") + refute docker_tag?(html, "1.17.3-erlang-26.2-debian-bookworm-20250113-slim") + refute docker_tag?(html, "27.0-ubuntu-noble-20250101") end test "tag prefix keeps arch filtering and disables parsed tag filters", %{conn: conn} do @@ -85,9 +85,9 @@ defmodule BobWeb.DockerTagsLiveTest do "os_version" => "bookworm" }) - assert html =~ "1.18.0-erlang-27.0-ubuntu-noble-20250101" - refute html =~ "1.18.1-erlang-27.0-ubuntu-noble-20250101" - refute html =~ "1.17.3-erlang-26.2-debian-bookworm-20250113-slim" + assert docker_tag?(html, "1.18.0-erlang-27.0-ubuntu-noble-20250101") + refute docker_tag?(html, "1.18.1-erlang-27.0-ubuntu-noble-20250101") + refute docker_tag?(html, "1.17.3-erlang-26.2-debian-bookworm-20250113-slim") refute control_html(html, "arch") =~ "disabled" @@ -135,4 +135,9 @@ defmodule BobWeb.DockerTagsLiveTest do {position, _length} = :binary.match(html, ~s(name="#{name}")) position end + + defp docker_tag?(html, tag) do + html =~ + ~r/]*>#{Regex.escape(tag)}<\/code><\/td>/ + end end From 9d5423ab388c5dfc000d317815f6914d2fb2960d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 9 Jun 2026 17:14:00 +0200 Subject: [PATCH 24/24] Fix production runtime checks --- config/runtime.exs | 6 ++- lib/bob_web/endpoint.ex | 1 + lib/bob_web/live/docker_tags_live.ex | 2 + lib/bob_web/plugs/secret.ex | 24 ++++++++- lib/bob_web/router.ex | 6 --- ...8120000_add_docker_tag_search_metadata.exs | 32 ++++++------ test/bob_web/controllers/api_test.exs | 11 ++++ test/bob_web/endpoint_config_test.exs | 50 ++++++++++++++++++- 8 files changed, 105 insertions(+), 27 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 1fce7eae..3566302d 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -30,10 +30,12 @@ if config_env() == :prod do bob_hostname: System.fetch_env!("BOB_HOSTNAME") } + bob_host = System.fetch_env!("BOB_HOST") + config :bob, BobWeb.Endpoint, server: true, - url: [host: System.fetch_env!("BOB_HOST"), port: 443, scheme: "https"], + url: [host: bob_host, port: 443, scheme: "https"], http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("BOB_PORT") || "4003")], secret_key_base: System.fetch_env!("SECRET_KEY_BASE"), - check_origin: [System.fetch_env!("BOB_HOST")] + check_origin: ["https://#{bob_host}"] end diff --git a/lib/bob_web/endpoint.ex b/lib/bob_web/endpoint.ex index a437b774..ccc55703 100644 --- a/lib/bob_web/endpoint.ex +++ b/lib/bob_web/endpoint.ex @@ -33,6 +33,7 @@ defmodule BobWeb.Endpoint do plug(Plug.RequestId) plug(Logster.Plugs.Logger, excludes: [:params]) + plug(BobWeb.Plugs.Secret, api_only: true) plug(Plug.Parsers, parsers: [:json, Bob.Plug.Parser], diff --git a/lib/bob_web/live/docker_tags_live.ex b/lib/bob_web/live/docker_tags_live.ex index 17747483..adf865c1 100644 --- a/lib/bob_web/live/docker_tags_live.ex +++ b/lib/bob_web/live/docker_tags_live.ex @@ -95,6 +95,8 @@ defmodule BobWeb.DockerTagsLive do else filters |> Bob.Artifacts.count_docker_tags() + # The page and count are separate queries, so keep the pager coherent if + # tags change between them. |> max(offset + length(results)) end diff --git a/lib/bob_web/plugs/secret.ex b/lib/bob_web/plugs/secret.ex index 6a5dd673..58fb79f1 100644 --- a/lib/bob_web/plugs/secret.ex +++ b/lib/bob_web/plugs/secret.ex @@ -3,10 +3,22 @@ defmodule BobWeb.Plugs.Secret do def init(opts), do: opts - def call(conn, _opts) do + def call(%{path_info: ["api" | _]} = conn, _opts) do + authenticate(conn) + end + + def call(conn, opts) when is_list(opts) do + if Keyword.get(opts, :api_only, false) do + conn + else + authenticate(conn) + end + end + + defp authenticate(conn) do secret = Application.get_env(:bob, :agent_secret) - if get_req_header(conn, "authorization") == [secret] do + if authorized?(get_req_header(conn, "authorization"), secret) do conn else conn @@ -14,4 +26,12 @@ defmodule BobWeb.Plugs.Secret do |> halt() end end + + defp authorized?([authorization], secret) + when is_binary(authorization) and is_binary(secret) and byte_size(secret) > 0 and + byte_size(authorization) == byte_size(secret) do + Plug.Crypto.secure_compare(authorization, secret) + end + + defp authorized?(_headers, _secret), do: false end diff --git a/lib/bob_web/router.ex b/lib/bob_web/router.ex index 1a802849..075c92c3 100644 --- a/lib/bob_web/router.ex +++ b/lib/bob_web/router.ex @@ -10,13 +10,7 @@ defmodule BobWeb.Router do plug(:put_secure_browser_headers) end - pipeline :api do - plug(BobWeb.Plugs.Secret) - end - scope "/api", BobWeb do - pipe_through(:api) - post("/queue/start", QueueController, :start) post("/queue/success", QueueController, :success) post("/queue/failure", QueueController, :failure) diff --git a/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs b/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs index 68976d1e..3c0be36b 100644 --- a/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs +++ b/priv/repo/migrations/20260608120000_add_docker_tag_search_metadata.exs @@ -6,10 +6,10 @@ defmodule Bob.Repo.Migrations.AddDockerTagSearchMetadata do @version_regex "^[0-9]+(\\.[0-9]+)*(-[0-9A-Za-z][0-9A-Za-z.-]*)?$" def up do - execute("ALTER TABLE docker_tags ADD COLUMN search jsonb NOT NULL DEFAULT '{}'::jsonb") + execute("ALTER TABLE docker_tags ADD COLUMN IF NOT EXISTS search jsonb NOT NULL DEFAULT '{}'::jsonb") execute( - "ALTER TABLE docker_tags_staging ADD COLUMN search jsonb NOT NULL DEFAULT '{}'::jsonb" + "ALTER TABLE docker_tags_staging ADD COLUMN IF NOT EXISTS search jsonb NOT NULL DEFAULT '{}'::jsonb" ) execute(""" @@ -49,42 +49,42 @@ defmodule Bob.Repo.Migrations.AddDockerTagSearchMetadata do """) execute( - "CREATE INDEX CONCURRENTLY docker_tags_repo_prefix_index ON docker_tags (repo text_pattern_ops)" + "CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_repo_prefix_index ON docker_tags (repo text_pattern_ops)" ) execute( - "CREATE INDEX CONCURRENTLY docker_tags_tag_prefix_index ON docker_tags (tag text_pattern_ops)" + "CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_tag_prefix_index ON docker_tags (tag text_pattern_ops)" ) execute(""" - CREATE INDEX CONCURRENTLY docker_tags_elixir_version_prefix_index + CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_elixir_version_prefix_index ON docker_tags ((search->>'elixir_version') text_pattern_ops) """) execute(""" - CREATE INDEX CONCURRENTLY docker_tags_erlang_version_prefix_index + CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_erlang_version_prefix_index ON docker_tags ((search->>'erlang_version') text_pattern_ops) """) execute(""" - CREATE INDEX CONCURRENTLY docker_tags_os_prefix_index + CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_os_prefix_index ON docker_tags ((search->>'os') text_pattern_ops) """) execute(""" - CREATE INDEX CONCURRENTLY docker_tags_os_version_prefix_index + CREATE INDEX CONCURRENTLY IF NOT EXISTS docker_tags_os_version_prefix_index ON docker_tags ((search->>'os_version') text_pattern_ops) """) end def down do - execute("DROP INDEX CONCURRENTLY docker_tags_os_version_prefix_index") - execute("DROP INDEX CONCURRENTLY docker_tags_os_prefix_index") - execute("DROP INDEX CONCURRENTLY docker_tags_erlang_version_prefix_index") - execute("DROP INDEX CONCURRENTLY docker_tags_elixir_version_prefix_index") - execute("DROP INDEX CONCURRENTLY docker_tags_tag_prefix_index") - execute("DROP INDEX CONCURRENTLY docker_tags_repo_prefix_index") - execute("ALTER TABLE docker_tags_staging DROP COLUMN search") - execute("ALTER TABLE docker_tags DROP COLUMN search") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_os_version_prefix_index") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_os_prefix_index") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_erlang_version_prefix_index") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_elixir_version_prefix_index") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_tag_prefix_index") + execute("DROP INDEX CONCURRENTLY IF EXISTS docker_tags_repo_prefix_index") + execute("ALTER TABLE docker_tags_staging DROP COLUMN IF EXISTS search") + execute("ALTER TABLE docker_tags DROP COLUMN IF EXISTS search") end end diff --git a/test/bob_web/controllers/api_test.exs b/test/bob_web/controllers/api_test.exs index 5333f26b..72a24a10 100644 --- a/test/bob_web/controllers/api_test.exs +++ b/test/bob_web/controllers/api_test.exs @@ -53,6 +53,17 @@ defmodule BobWeb.ApiTest do assert Repo.all(Artifact) == [] end + test "POST /api/artifacts/add rejects an invalid secret before parsing the body", %{conn: conn} do + conn = + conn + |> put_req_header("content-type", "application/json") + |> put_req_header("authorization", "public") + |> post(~p"/api/artifacts/add", "{") + + assert conn.status == 401 + assert Repo.all(Artifact) == [] + end + test "POST /api/docker/add upserts a docker tag and returns 204", %{conn: conn} do body = Bob.Plug.ErlangFormat.encode_to_iodata!(%{ diff --git a/test/bob_web/endpoint_config_test.exs b/test/bob_web/endpoint_config_test.exs index 4295bfe3..e94ec2f3 100644 --- a/test/bob_web/endpoint_config_test.exs +++ b/test/bob_web/endpoint_config_test.exs @@ -1,7 +1,25 @@ defmodule BobWeb.EndpointConfigTest do - use ExUnit.Case, async: true + use ExUnit.Case, async: false @config_dir Path.expand("../../config", __DIR__) + @prod_runtime_env %{ + "BOB_AGENT_SECRET" => "secret", + "BOB_ENV" => "prod", + "BOB_GITHUB_TOKEN" => "github-token", + "BOB_GITHUB_USER" => "hexbob", + "BOB_HOST" => "bob.hex.pm", + "BOB_HOSTNAME" => "gce", + "BOB_LOCAL_JOBS" => "[]", + "BOB_MASTER_URL" => "https://bob.hex.pm", + "BOB_PARALLEL_JOBS" => "10", + "BOB_PORT" => "4003", + "BOB_REMOTE_JOBS" => "[]", + "BOB_S3_ACCESS_KEY" => "s3-key", + "BOB_S3_SECRET_KEY" => "s3-secret", + "BOB_SENTRY_DSN" => "https://public@example.com/1", + "BOB_WHO" => "master", + "SECRET_KEY_BASE" => String.duplicate("a", 64) + } test "configured cookie session secret keys satisfy Plug's minimum length" do for env <- [:dev, :test] do @@ -21,4 +39,34 @@ defmodule BobWeb.EndpointConfigTest do assert "favicon.ico" in BobWeb.static_paths() assert "images" in BobWeb.static_paths() end + + test "prod runtime endpoint config uses a schemed LiveView origin" do + with_env(@prod_runtime_env, fn -> + endpoint_config = + @config_dir + |> Path.join("runtime.exs") + |> Config.Reader.read!(env: :prod) + |> get_in([:bob, BobWeb.Endpoint]) + + assert Keyword.fetch!(endpoint_config, :url)[:host] == "bob.hex.pm" + assert Keyword.fetch!(endpoint_config, :check_origin) == ["https://bob.hex.pm"] + end) + end + + defp with_env(env, fun) do + previous = Map.new(Map.keys(env), &{&1, System.get_env(&1)}) + + try do + System.put_env(env) + fun.() + after + for {key, value} <- previous do + if value do + System.put_env(key, value) + else + System.delete_env(key) + end + end + end + end end