From 6d099495d5ff721106a8754b1da1846ddcbf22f8 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 08:30:24 +0100 Subject: [PATCH 1/6] better version tag --- lib/lightning_web/live/components/common.ex | 57 ++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/lightning_web/live/components/common.ex b/lib/lightning_web/live/components/common.ex index efd8306ed5..c88e96a562 100644 --- a/lib/lightning_web/live/components/common.ex +++ b/lib/lightning_web/live/components/common.ex @@ -4,6 +4,39 @@ defmodule LightningWeb.Components.Common do alias Phoenix.LiveView.JS + @spec version_tuple(any, any, any, any) :: + {any, <<_::64, _::_*8>>, :edge | :no_docker | :release | :warn} + def version_tuple(image, branch, commit, vsn) do + cond do + # If running in docker on edge, display commit SHA. + image == "edge" -> + {commit, + "Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}", + :edge} + + # If running in docker and tag matches :vsn, display :vsn and standard message. + image == vsn -> + {vsn, + "Docker image tag found: '#{image}' tagged release build from #{commit}", + :release} + + # If running in docker and tag doesn't match :vsn, display image tag. + image != nil and image != vsn and image != "edge" -> + {image, + "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", + :warn} + + # If running in docker and tag doesn't match :vsn, display commit. + image != nil and image != vsn -> + {commit, + "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", + :warn} + + true -> + {vsn, "Lightning #{vsn}", :no_docker} + end + end + def version_chip(assigns) do image_info = Application.get_env(:lightning, :image_info) image = image_info[:image_tag] @@ -11,29 +44,7 @@ defmodule LightningWeb.Components.Common do commit = image_info[:commit] vsn = "v#{elem(:application.get_key(:lightning, :vsn), 1)}" - {display, message, type} = - cond do - # If running in docker on edge, display commit SHA. - image == "edge" -> - {commit, - "Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}", - :edge} - - # If running in docker and tag matches :vsn, display :vsn and standard message. - image == vsn -> - {vsn, - "Docker image tag found: '#{image}' tagged release build from #{commit}", - :release} - - # If running in docker and tag doesn't match :vsn, display :vsn and warning. - image != nil and image != vsn -> - {commit, - "Warning: detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", - :warn} - - true -> - {vsn, "Lightning #{vsn}", :no_docker} - end + {display, message, type} = version_tuple(image, branch, commit, vsn) icon_classes = "h-4 w-4 inline-block mr-1" From cda17f323b72498af9c35e445fad18dea5f33ba0 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 11:09:24 +0100 Subject: [PATCH 2/6] send release info to sentry to help debugging --- config/runtime.exs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index 27edf6cea6..a6dfb67913 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -108,11 +108,24 @@ config :lightning, |> String.to_atom() # If you've booted up with a SENTRY_DSN environment variable, use Sentry! +release = + case Application.get_env(:lightning, :image_info) do + [image_tag: nil, branch: nil, commit: nil] -> + "mix-v#{elem(:application.get_key(:lightning, :vsn), 1)}" + + [image_tag: image_tag, branch: _branch, commit: commit] -> + if Enum.member?(["edge", "latest"], image_tag), do: commit, else: image_tag + + _other -> + nil + end + config :sentry, filter: Lightning.SentryEventFilter, environment_name: config_env(), included_environments: - if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []) + if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []), + release: release # To actually send emails you need to configure the mailer to use a real # adapter. You may configure the swoosh api client of your choice. We From 256ce344d0ec31a85082664bbb40f0c17da218cb Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 11:29:41 +0100 Subject: [PATCH 3/6] add host to sentry --- config/runtime.exs | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index a6dfb67913..94d614a0bb 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -107,26 +107,6 @@ config :lightning, System.get_env("INIT_PROJECT_FOR_NEW_USER", "false") |> String.to_atom() -# If you've booted up with a SENTRY_DSN environment variable, use Sentry! -release = - case Application.get_env(:lightning, :image_info) do - [image_tag: nil, branch: nil, commit: nil] -> - "mix-v#{elem(:application.get_key(:lightning, :vsn), 1)}" - - [image_tag: image_tag, branch: _branch, commit: commit] -> - if Enum.member?(["edge", "latest"], image_tag), do: commit, else: image_tag - - _other -> - nil - end - -config :sentry, - filter: Lightning.SentryEventFilter, - environment_name: config_env(), - included_environments: - if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []), - release: release - # To actually send emails you need to configure the mailer to use a real # adapter. You may configure the swoosh api client of your choice. We # automatically configure Mailgun if an API key has been provided. See @@ -261,3 +241,27 @@ if config_env() == :test do config :lightning, Lightning.Repo, pool_size: :erlang.system_info(:schedulers_online) + 4 end + +# If you've booted up with a SENTRY_DSN environment variable, use Sentry! +release = + case Application.get_env(:lightning, :image_info) do + [image_tag: image_tag, branch: _branch, commit: commit] -> + if Enum.member?(["edge", "latest"], image_tag), + do: commit, + else: image_tag + + _other -> + "mix-v#{elem(:application.get_key(:lightning, :vsn), 1)}" + end + +config :sentry, + filter: Lightning.SentryEventFilter, + environment_name: config_env(), + tags: %{ + host: Application.get_env(:lightning, LightningWeb.Endpoint)[:url][:host] + }, + included_environments: + if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []), + release: release, + enable_source_code_context: true, + root_source_code_path: File.cwd!() From b934a2789e3c6b3f7b38cb33d6c0cf1bf0c709f8 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 11:57:03 +0100 Subject: [PATCH 4/6] fix version chip test --- test/lightning_web/live/components/common_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lightning_web/live/components/common_test.exs b/test/lightning_web/live/components/common_test.exs index fbe9cda3dc..623ef03891 100644 --- a/test/lightning_web/live/components/common_test.exs +++ b/test/lightning_web/live/components/common_test.exs @@ -82,7 +82,7 @@ defmodule LightningWeb.Components.CommonTest do "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" assert html =~ - "Warning: detected image tag that does not match application version" + "Detected image tag that does not match application version" assert html =~ "v#{elem(:application.get_key(:lightning, :vsn), 1)}" end From 6183d56bd2d743efdadc2be1b812ef391ffc3df5 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 14:16:21 +0100 Subject: [PATCH 5/6] move if/comment down to included env --- config/runtime.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index 94d614a0bb..b085b3b5b1 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -242,7 +242,6 @@ if config_env() == :test do pool_size: :erlang.system_info(:schedulers_online) + 4 end -# If you've booted up with a SENTRY_DSN environment variable, use Sentry! release = case Application.get_env(:lightning, :image_info) do [image_tag: image_tag, branch: _branch, commit: commit] -> @@ -260,6 +259,7 @@ config :sentry, tags: %{ host: Application.get_env(:lightning, LightningWeb.Endpoint)[:url][:host] }, + # If you've booted up with a SENTRY_DSN environment variable, use Sentry! included_environments: if(System.get_env("SENTRY_DSN"), do: [config_env()], else: []), release: release, From 6e150a765340c979d12d023ee9317a8632ec68ba Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Thu, 27 Jul 2023 14:19:02 +0100 Subject: [PATCH 6/6] put back the version tuple thing --- lib/lightning_web/live/components/common.ex | 63 ++++++++++----------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/lightning_web/live/components/common.ex b/lib/lightning_web/live/components/common.ex index c88e96a562..291c10974f 100644 --- a/lib/lightning_web/live/components/common.ex +++ b/lib/lightning_web/live/components/common.ex @@ -4,39 +4,6 @@ defmodule LightningWeb.Components.Common do alias Phoenix.LiveView.JS - @spec version_tuple(any, any, any, any) :: - {any, <<_::64, _::_*8>>, :edge | :no_docker | :release | :warn} - def version_tuple(image, branch, commit, vsn) do - cond do - # If running in docker on edge, display commit SHA. - image == "edge" -> - {commit, - "Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}", - :edge} - - # If running in docker and tag matches :vsn, display :vsn and standard message. - image == vsn -> - {vsn, - "Docker image tag found: '#{image}' tagged release build from #{commit}", - :release} - - # If running in docker and tag doesn't match :vsn, display image tag. - image != nil and image != vsn and image != "edge" -> - {image, - "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", - :warn} - - # If running in docker and tag doesn't match :vsn, display commit. - image != nil and image != vsn -> - {commit, - "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", - :warn} - - true -> - {vsn, "Lightning #{vsn}", :no_docker} - end - end - def version_chip(assigns) do image_info = Application.get_env(:lightning, :image_info) image = image_info[:image_tag] @@ -44,7 +11,35 @@ defmodule LightningWeb.Components.Common do commit = image_info[:commit] vsn = "v#{elem(:application.get_key(:lightning, :vsn), 1)}" - {display, message, type} = version_tuple(image, branch, commit, vsn) + {display, message, type} = + cond do + # If running in docker on edge, display commit SHA. + image == "edge" -> + {commit, + "Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}", + :edge} + + # If running in docker and tag matches :vsn, display :vsn and standard message. + image == vsn -> + {vsn, + "Docker image tag found: '#{image}' tagged release build from #{commit}", + :release} + + # If running in docker and tag doesn't match :vsn, display image tag. + image != nil and image != vsn and image != "edge" -> + {image, + "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", + :warn} + + # If running in docker and tag doesn't match :vsn, display commit. + image != nil and image != vsn -> + {commit, + "Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}", + :warn} + + true -> + {vsn, "Lightning #{vsn}", :no_docker} + end icon_classes = "h-4 w-4 inline-block mr-1"