Skip to content

Commit

Permalink
Add Phoenix Live Dashboard, bump to 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mreishus committed Apr 16, 2020
1 parent c5df8f6 commit 7cb6131
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apps/demon_spirit_web/lib/demon_spirit_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ defmodule DemonSpiritWeb.Endpoint do
plug(Phoenix.CodeReloader)
end

## LiveDashboard Plugins
plug(Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"
)

plug(Plug.RequestId)
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])

Expand Down
19 changes: 19 additions & 0 deletions apps/demon_spirit_web/lib/demon_spirit_web/router.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule DemonSpiritWeb.Router do
use DemonSpiritWeb, :router
import Plug.BasicAuth
import Phoenix.LiveDashboard.Router

pipeline :browser do
plug(:accepts, ["html"])
Expand All @@ -14,6 +16,23 @@ defmodule DemonSpiritWeb.Router do
plug(:accepts, ["json"])
end

## BEGIN Phoenix LiveDashboard ###
scope "/" do
if Mix.env() == :dev do
pipe_through([:browser])
else
pipe_through([:browser, :dash_admins_only])
end

live_dashboard("/dashboard")
end

pipeline :dash_admins_only do
plug(:basic_auth, Application.get_env(:demon_spirit_web, :dash_basic_auth))
end

## END Phoenix LiveDashboard ###

scope "/", DemonSpiritWeb do
pipe_through(:browser)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="flex items-center justify-between py-1">
<!-- Left Side -->
<div class="flex items-center">
<%= link "Demon Spirit", to: Routes.game_path(@conn, :index), class: "underline hover:text-blue-300" %> <span class="ml-1 text-xs text-gray-300">(1.3.2)</span>
<%= link "Demon Spirit", to: Routes.game_path(@conn, :index), class: "underline hover:text-blue-300" %> <span class="ml-1 text-xs text-gray-300">(1.5.0)</span>
</div>

<!-- Right Side -->
Expand Down
1 change: 1 addition & 0 deletions apps/demon_spirit_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule DemonSpiritWeb.MixProject do
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:phoenix_live_view, "~> 0.12.0"},
{:phoenix_live_dashboard, "~> 0.1"},
{:accessible, "~> 0.2.1"},
{:sobelow, ">= 0.0.0", only: :dev, runtime: false}
]
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION=1.3.2 # Bump in layout/app.html.eex too
VERSION=1.5.0 # Bump in layout/app.html.eex too
# ^ Todo: Make this one source of truth

# exit when any command fails
Expand Down
5 changes: 5 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Basic Auth for /dashboard - :dash_basic_auth - set during runtime in releases.exs
config :demon_spirit_web, :dash_basic_auth,
username: "admin",
password: "EyAU6Ax8cyDkVcNA"

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
22 changes: 22 additions & 0 deletions config/releases.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ config :demon_spirit_web, DemonSpiritWeb.Endpoint,
http: [:inet6, port: String.to_integer(System.get_env("PORT") || "4000")],
secret_key_base: secret_key_base

### Begin Dashboard Auth ###
# Set Username/Password for Dashboard Basic Auth (/dashboard)
#
# Read from env variables DASH_BASIC_USER and DASH_BASIC_PASS
# If none is set, instead of refusing to run, simply set to random strings.
defmodule ReleaseUtil do
def random_string(length) do
:crypto.strong_rand_bytes(length) |> Base.url_encode64() |> binary_part(0, length)
end
end

# Note: This doesn't actually work.
# Spent a lot of time on it and I'm stuck..
dash_basic_username = System.get_env("DASH_BASIC_USER") || ReleaseUtil.random_string(32)
dash_basic_password = System.get_env("DASH_BASIC_PASS") || ReleaseUtil.random_string(32)

config :demon_spirit_web, :dash_basic_auth,
username: dash_basic_username,
password: dash_basic_password

### End Dashboard Auth ###

# ## Using releases (Elixir v1.9+)
#
# If you are doing OTP releases, you need to instruct Phoenix
Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"phoenix": {:hex, :phoenix, "1.4.16", "2cbbe0c81e6601567c44cc380c33aa42a1372ac1426e3de3d93ac448a7ec4308", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "856cc1a032fa53822737413cf51aa60e750525d7ece7d1c0576d90d7c0f05c24"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"},
"phoenix_html": {:hex, :phoenix_html, "2.14.1", "7dabafadedb552db142aacbd1f11de1c0bbaa247f90c449ca549d5e30bbc66b4", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "536d5200ad37fecfe55b3241d90b7a8c3a2ca60cd012fc065f776324fa9ab0a9"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.1.0", "e5af08a2a283a419616c45f8fbd23463a206708c3d41dee77046e288ec1db799", [:mix], [{:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.12.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "764e7c18511a4b9edae46430e1edcf1d4e5c35bbe1b7cd7fa4f86092e0b3c656"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.1", "274a4b07c4adbdd7785d45a8b0bb57634d0b4f45b18d2c508b26c0344bd59b8f", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "41b4103a2fa282cfd747d377233baf213c648fdcc7928f432937676532490eee"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.12.0", "57e831ea4807178c95279d20b8f79487c6fc05016ca4c802a7f6f2665060e8f3", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.16 or ~> 1.5.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "8490691d21c27ec6b84c42e0c97d5ebb2986b210669b95460b84b41760c4e9ea"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm", "1f13f9f0f3e769a667a6b6828d29dec37497a082d195cc52dbef401a9b69bf38"},
Expand All @@ -38,5 +39,6 @@
"sobelow": {:hex, :sobelow, "0.10.1", "7ddd72eacd3cff0d8ebaaa7825a11718652d264a8c1b97fe802d09634c955db5", [:mix], [], "hexpm", "6d4d3407a7e3cd4d04673b195ac19342400c7300a4f5f212273418271c47b660"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"},
"telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.4.2", "1de986fad9aa6bf81f8a33ddfd16e5d8ab0dec6272e624eb517c1a92a44d41a9", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e56ffed2dbe293ab6cf7c94980faeb368cb360662c1927f54fc634a4ca55362e"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
}

0 comments on commit 7cb6131

Please sign in to comment.