Merge pull request 'Fix prod admin initialisation' (#410) from fix/admin_init into main
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #410
This commit is contained in:
commit
cc02748cc6
1 changed files with 8 additions and 1 deletions
|
|
@ -34,6 +34,9 @@ defmodule Mv.Release do
|
||||||
@doc """
|
@doc """
|
||||||
Ensures an admin user exists from ENV (ADMIN_EMAIL, ADMIN_PASSWORD or ADMIN_PASSWORD_FILE).
|
Ensures an admin user exists from ENV (ADMIN_EMAIL, ADMIN_PASSWORD or ADMIN_PASSWORD_FILE).
|
||||||
|
|
||||||
|
Starts the application if not already running (required when called via `bin/mv eval`;
|
||||||
|
Ash/Telemetry need the running app). Idempotent.
|
||||||
|
|
||||||
- If ADMIN_EMAIL is unset: no-op (idempotent).
|
- If ADMIN_EMAIL is unset: no-op (idempotent).
|
||||||
- If ADMIN_PASSWORD (and ADMIN_PASSWORD_FILE) are unset and the user does not exist:
|
- If ADMIN_PASSWORD (and ADMIN_PASSWORD_FILE) are unset and the user does not exist:
|
||||||
no user is created (no fallback password in production).
|
no user is created (no fallback password in production).
|
||||||
|
|
@ -42,7 +45,11 @@ defmodule Mv.Release do
|
||||||
`bin/mv eval "Mv.Release.seed_admin()"` to change the admin password without redeploying.
|
`bin/mv eval "Mv.Release.seed_admin()"` to change the admin password without redeploying.
|
||||||
"""
|
"""
|
||||||
def seed_admin do
|
def seed_admin do
|
||||||
load_app()
|
# Ensure app (and Telemetry/Ash deps) are started when run via bin/mv eval
|
||||||
|
case Application.ensure_all_started(@app) do
|
||||||
|
{:ok, _} -> :ok
|
||||||
|
{:error, {app, reason}} -> raise "Failed to start #{inspect(app)}: #{inspect(reason)}"
|
||||||
|
end
|
||||||
|
|
||||||
admin_email = get_env("ADMIN_EMAIL", nil)
|
admin_email = get_env("ADMIN_EMAIL", nil)
|
||||||
admin_password = get_env_or_file("ADMIN_PASSWORD", nil)
|
admin_password = get_env_or_file("ADMIN_PASSWORD", nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue