Skip to content

Commit e89a6bb

Browse files
committedFeb 3, 2022
create status page #176
1 parent 7ab46b5 commit e89a6bb

File tree

13 files changed

+104
-14
lines changed

13 files changed

+104
-14
lines changed
 

‎Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ RUN mix local.hex --force && \
3030

3131
# set build ENV
3232
ENV MIX_ENV="prod"
33+
34+
# copy the .env_sample file to read environment variable keys:
35+
COPY .env_sample ./
36+
3337
ENV AUTH_API_KEY=$AUTH_API_KEY
3438
# install mix dependencies
3539
COPY mix.exs mix.lock ./

‎README.md

+35
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,41 @@ Phoenix has a built-in mechanism for sessions:
275275

276276
This project _uses_ and _extends_ it to support several 3rd party auth services.
277277

278+
<br /><br />
279+
280+
### Troubleshooting
281+
282+
If you see the following error error
283+
when visiting the status (_or any other page_):
284+
http://localhost:4000/status
285+
![image](https://user-images.githubusercontent.com/194400/152191803-e7127118-7107-40aa-aaa7-a4618726b689.png)
286+
287+
You forgot to create and export the
288+
`SECRET_KEY_BASE`
289+
environment variable.
290+
291+
Create a [secret](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Secret.html)
292+
by running the following command in your terminal:
293+
294+
```sh
295+
mix phx.gen.secret
296+
```
297+
298+
Copy the output and export it, e.g:
299+
300+
```sh
301+
export SECRET_KEY_BASE=mAfe8fGd3CgpiwKCnnulAhO2RjcSxuFlw6BGjBhRJCYo2Mthtmu/cdIvO3Mz1QU8
302+
```
303+
304+
Where the long string
305+
is whatever was generated above.
306+
Once the
307+
`SECRET_KEY_BASE`
308+
environment variable is exported
309+
and you restart the app,
310+
it should work as expected.
311+
312+
278313

279314
## Background Reading
280315

‎assets/static/images/false.png

3.82 KB
Loading

‎assets/static/images/true.png

4.59 KB
Loading

‎lib/auth/init/init.ex

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule Auth.Init do
2323

2424
def main do
2525
Logger.info("Initialising the Auth Database ...")
26-
Auth.Application.start(:type, :args)
2726
# check required environment variables:
2827
Envar.is_set_all?(~w/ADMIN_EMAIL AUTH_URL ENCRYPTION_KEYS SECRET_KEY_BASE/)
2928

‎lib/auth/release.ex

-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ defmodule Auth.Release do
1111
for repo <- repos() do
1212
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
1313
end
14-
15-
# Run Seeds in Prod: https://github.com/dwyl/auth/issues/172#issuecomment-1005194147
16-
IO.inspect(File.cwd!(), label: "cwd")
17-
# IO.inspect(File.ls!(File.cwd!()), label: "File.ls!(cwd)")
18-
# IO.inspect(__ENV__.file, label: "__ENV__.file")
19-
20-
IO.puts(" - - - - - - - - - - - - - - - - - - - - - - - ")
21-
IO.inspect("attempting to run Auth.Init.main() ... ")
22-
Auth.Init.main()
23-
24-
IO.puts(" - - - - - - - - - - - - - - - - - - - - - - - ")
2514
end
2615

2716
def rollback(repo, version) do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule AuthWeb.StatusController do
2+
use AuthWeb, :controller
3+
4+
def index(conn, _params) do
5+
conn
6+
# |> assign(:env, check_env())
7+
|> render(:index,
8+
layout: {AuthWeb.StatusView, "status_layout.html"},
9+
env: check_env()
10+
)
11+
end
12+
13+
defp check_env() do
14+
Enum.reduce(Envar.keys(".env_sample"), %{}, fn key, acc ->
15+
Map.put(acc, key, Envar.is_set?(key))
16+
end)
17+
end
18+
end

‎lib/auth_web/router.ex

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ defmodule AuthWeb.Router do
3030
post "/auth/password/verify", AuthController, :password_prompt
3131
# https://github.com/dwyl/ping
3232
get "/ping", PingController, :ping
33+
get "/status", StatusController, :index
3334
end
3435

3536
pipeline :auth do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h1 class="tc">Status</h1>
2+
3+
<table class="w-80 mw5 mw7-ns center">
4+
<thead>
5+
<tr class="bb b--silver">
6+
<th class="tl pv3 f3">Environment Variable</th>
7+
<th class="tl pv3 f3">Defined?</th>
8+
</tr>
9+
</thead>
10+
<tbody>
11+
12+
<%= for {key, value} <- @env do %>
13+
<tr class="bb b--moon-gray">
14+
<td class=""><pre class="mono"><%= key %></pre></td>
15+
<td class="center pl4"><img width="40px" src="/images/<%=value%>.png"></td>
16+
</tr>
17+
<% end %>
18+
</tbody>
19+
</table>
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7+
<title><%= assigns[:page_title] || "Auth App" %></title>
8+
<%= csrf_meta_tag() %>
9+
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/assets/app.css") %>"/>
10+
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css"/>
11+
</head>
12+
<body class="w-100 helvetica dark-gray">
13+
<main role="main" class="container pt1">
14+
<p class="alert alert-info f4 mh3"
15+
role="alert"><%= get_flash(@conn, :info) %></p>
16+
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
17+
<%= @inner_content %>
18+
</main>
19+
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/assets/app.js") %>"></script>
20+
</body>
21+
</html>

‎lib/auth_web/views/status_view.ex

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
defmodule AuthWeb.StatusView do
2+
use AuthWeb, :view
3+
end

‎mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ defmodule Auth.Mixfile do
7171
{:elixir_auth_google, "~> 1.6.2"},
7272

7373
# Check/get Environment Variables: https://github.com/dwyl/envar
74-
{:envar, "~> 1.0.4"},
74+
{:envar, "~> 1.0.5"},
7575

7676
# https://github.com/dwyl/auth_plug
7777
{:auth_plug, "~> 1.4.11"},

‎mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"elixir_auth_github": {:hex, :elixir_auth_github, "1.6.0", "f100dd3917b2395219d533e5a834eb450abff3e0a53eab36632d53335e1beb92", [:mix], [{:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "abc700b484bc5dfd4d6a2aa2acbbe79a7fd8ce112ca28d2c864ede169790ab1f"},
2121
"elixir_auth_google": {:hex, :elixir_auth_google, "1.6.2", "bef167fc8b32d3e30bf39217a40508af538f5f1cca987239e3a67f4efa74d7a3", [:mix], [{:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "deafaf9ca84bd900ab55a192c0cd0ca2301107c7cbcc9c35a0c89083bb7d2ef4"},
2222
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
23-
"envar": {:hex, :envar, "1.0.4", "3264a6b13d5f9bca9a16e82ed2311c0efd08f3371d3c6b42dc5abe9d01da59aa", [:mix], [], "hexpm", "d7856849080745b907e39b33b825448810bc2348e3f5982ee32f8007d9b3226e"},
23+
"envar": {:hex, :envar, "1.0.5", "64ed87d6ccd6b4a73d9c4907bd84b6e8073c253bab138ead20a64362675c5c11", [:mix], [], "hexpm", "79408fed523c9f7ba9508529047fd464498d09050454e8b092a0233ee2d02a7e"},
2424
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
2525
"esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"},
2626
"ex_doc": {:hex, :ex_doc, "0.25.5", "ac3c5425a80b4b7c4dfecdf51fa9c23a44877124dd8ca34ee45ff608b1c6deb9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "688cfa538cdc146bc4291607764a7f1fcfa4cce8009ecd62de03b27197528350"},

0 commit comments

Comments
 (0)
Please sign in to comment.