From ec1e490f39c4fdd841fd1a77e906e7f147770936 Mon Sep 17 00:00:00 2001 From: prichier Date: Tue, 27 Oct 2020 16:40:14 +0100 Subject: [PATCH] Fix Mix.env use in prod app & MR threads --- docker/production/README.md | 5 +++-- docker/production/docker-compose.yml | 11 +++++++---- docker/production/env | 20 +++++++------------- lib/federation/activity_pub/federator.ex | 2 +- lib/mobilizon.ex | 2 +- lib/mobilizon/cli.ex | 4 ++-- lib/web/router.ex | 2 +- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/docker/production/README.md b/docker/production/README.md index 68055e518..12bc88510 100644 --- a/docker/production/README.md +++ b/docker/production/README.md @@ -17,6 +17,7 @@ You will need to : cp env.example .env Edit the `.env` content with your own settings. +More settings can be added in .env, see all in docker-compose.yml file. You can generate `MOBILIZON_INSTANCE_SECRET_KEY_BASE` and `MOBILIZON_INSTANCE_SECRET_KEY` with: @@ -37,7 +38,7 @@ Instanciate required Postgres extensions: Then run migrations: - docker-compose run --rm mobilizon eval Mobilizon.Cli.migrate + docker-compose run --rm mobilizon eval Mobilizon.CLI.migrate Finally, run the application: @@ -48,7 +49,7 @@ Finally, run the application: Pull the latest image, then run the migrations: docker-compose pull mobilizon - docker-compose run --rm mobilizon eval Mobilizon.Cli.migrate + docker-compose run --rm mobilizon eval Mobilizon.CLI.migrate Finally, update the service: diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index c3b521624..029a82871 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -8,19 +8,22 @@ services: - MOBILIZON_INSTANCE_HOST - MOBILIZON_INSTANCE_EMAIL - MOBILIZON_REPLY_EMAIL - - MOBILIZON_INSTANCE_REGISTRATIONS_OPEN=true + - MOBILIZON_ADMIN_EMAIL + - MOBILIZON_INSTANCE_REGISTRATIONS_OPEN - MOBILIZON_DATABASE_USERNAME=${POSTGRES_USER} - MOBILIZON_DATABASE_PASSWORD=${POSTGRES_PASSWORD} - MOBILIZON_DATABASE_DBNAME=${POSTGRES_DB} - MOBILIZON_DATABASE_HOST=db - MOBILIZON_INSTANCE_SECRET_KEY_BASE - MOBILIZON_INSTANCE_SECRET_KEY - - MOBILIZON_SMTP_SERVER=yoursmtpserver - - MOBILIZON_SMTP_HOSTNAME=your.smtp.domain + - MOBILIZON_SMTP_SERVER + - MOBILIZON_SMTP_HOSTNAME + - MOBILIZON_SMTP_PORT + - MOBILIZON_SMTP_SSL - MOBILIZON_SMTP_USERNAME - MOBILIZON_SMTP_PASSWORD volumes: - - ./public/upload:/app/upload + - ./public/uploads:/app/uploads ports: - "4000:4000" diff --git a/docker/production/env b/docker/production/env index 3b003dd38..6b08ab62b 100644 --- a/docker/production/env +++ b/docker/production/env @@ -1,27 +1,21 @@ -# Copy this file to env, then update it with your own settings +# Copy this file to .env, then update it with your own settings + +hostname=mobilizon.lan # Database settings POSTGRES_USER=mobilizon POSTGRES_PASSWORD=changethis POSTGRES_DB=mobilizon -# Application config -MOBILIZON_INSTANCE_SECRET_KEY_BASE=changethis -MOBILIZON_INSTANCE_SECRET_KEY=changethis -MOBILIZON_SMTP_USERNAME=username -MOBILIZON_SMPT_PASSWORD=password -POSTGRES_PASSWORD=postgres - # Instance configuration MOBILIZON_INSTANCE_NAME=My Mobilizon Instance -MOBILIZON_INSTANCE_HOST=mobilizon.lan MOBILIZON_INSTANCE_SECRET_KEY_BASE=changethis MOBILIZON_INSTANCE_SECRET_KEY=changethis MOBILIZON_INSTANCE_EMAIL=noreply@mobilizon.lan MOBILIZON_REPLY_EMAIL=contact@mobilizon.lan # Email settings -MOBILIZON_SMPT_SERVER=localhost -MOBILIZON_SMPT_HOSTNAME=localhost -MOBILIZON_SMPT_USERNAME=noreply@mobilizon.lan -MOBILIZON_SMPT_PASSWORD=password +MOBILIZON_SMTP_SERVER=localhost +MOBILIZON_SMTP_HOSTNAME=localhost +MOBILIZON_SMTP_USERNAME=noreply@mobilizon.lan +MOBILIZON_SMTP_PASSWORD=password diff --git a/lib/federation/activity_pub/federator.ex b/lib/federation/activity_pub/federator.ex index 74b947afe..d9027084f 100644 --- a/lib/federation/activity_pub/federator.ex +++ b/lib/federation/activity_pub/federator.ex @@ -79,7 +79,7 @@ defmodule Mobilizon.Federation.ActivityPub.Federator do def enqueue(type, payload, priority \\ 1) do Logger.debug("enqueue something with type #{inspect(type)}") - if Mix.env() == :test do + if Application.fetch_env!(:mobilizon, :env) == :test do handle(type, payload) else GenServer.cast(__MODULE__, {:enqueue, type, payload, priority}) diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index 496deb893..378584b51 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -21,7 +21,7 @@ defmodule Mobilizon do @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] - @env Mix.env() + @env Application.fetch_env!(:mobilizon, :env) @spec named_version :: String.t() def named_version, do: "#{@name} #{@version}" diff --git a/lib/mobilizon/cli.ex b/lib/mobilizon/cli.ex index 88f5bda2d..969c125f0 100644 --- a/lib/mobilizon/cli.ex +++ b/lib/mobilizon/cli.ex @@ -1,4 +1,4 @@ -defmodule Mobilizon.Cli do +defmodule Mobilizon.CLI do @app :mobilizon def migrate do @@ -8,4 +8,4 @@ defmodule Mobilizon.Cli do {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) end end -end \ No newline at end of file +end diff --git a/lib/web/router.ex b/lib/web/router.ex index 37d5e4ab4..80f75d63f 100644 --- a/lib/web/router.ex +++ b/lib/web/router.ex @@ -169,7 +169,7 @@ defmodule Mobilizon.Web.Router do get("/:sig/:url/:filename", MediaProxyController, :remote) end - if Mix.env() in [:dev, :e2e] do + if Application.fetch_env!(:mobilizon, :env) in [:dev, :e2e] do # If using Phoenix forward("/sent_emails", Bamboo.SentEmailViewerPlug) end