Change configuration and docker compose

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-01-03 11:33:52 +01:00
parent 511c2b7f6a
commit eef4b8403c
9 changed files with 60 additions and 28 deletions

View File

@ -10,13 +10,13 @@ GRAPHQL_API_FULL_PATH=""
# APP # APP
MIX_ENV=prod MIX_ENV=prod
PORT=4002 MOBILIZON_INSTANCE_PORT=4002
MOBILIZON_LOGLEVEL="info" MOBILIZON_LOGLEVEL="info"
MOBILIZON_SECRET="<%= instance_secret %>" MOBILIZON_SECRET="<%= instance_secret %>"
# Database # Database
MOBILIZON_DATABASE_USERNAME="mobilizon" MOBILIZON_DATABASE_USERNAME="<%= database_username %>"
MOBILIZON_DATABASE_PASSWORD="<%= database_password %>" MOBILIZON_DATABASE_PASSWORD="<%= database_password %>"
MOBILIZON_DATABASE_DBNAME="mobilizon_prod" MOBILIZON_DATABASE_DBNAME="<%= database_name %>"
MOBILIZON_DATABASE_HOST="localhost" MOBILIZON_DATABASE_HOST="<%= database_host %>"
MOBILIZON_DATABASE_PORT=5432 MOBILIZON_DATABASE_PORT=<%= database_port %>

View File

@ -6,10 +6,16 @@ stages:
variables: variables:
MIX_ENV: "test" MIX_ENV: "test"
# DB Variables for Postgres / Postgis
POSTGRES_DB: mobilizon_test POSTGRES_DB: mobilizon_test
POSTGRES_USER: postgres POSTGRES_USER: postgres
POSTGRES_PASSWORD: "" POSTGRES_PASSWORD: ""
POSTGRES_HOST: postgres POSTGRES_HOST: postgres
# DB Variables for Mobilizon
MOBILIZON_DATABASE_USERNAME: $POSTGRES_USER
MOBILIZON_DATABASE_PASSWORD: $POSTGRES_PASSWORD
MOBILIZON_DATABASE_DBNAME: $POSTGRES_DB
MOBILIZON_DATABASE_HOST: $POSTGRES_HOST
GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb" GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb"
js: js:

View File

@ -1,4 +1,4 @@
FROM elixir:1.6 FROM elixir:1.7
RUN apt-get update && apt-get install -y build-essential inotify-tools postgresql-client RUN apt-get update && apt-get install -y build-essential inotify-tools postgresql-client
@ -8,4 +8,4 @@ COPY docker/entrypoint.sh /bin/entrypoint
WORKDIR /app WORKDIR /app
EXPOSE 4000 EXPOSE 4000 4001 4002

View File

@ -7,7 +7,13 @@ use Mix.Config
# watchers to your application. For example, we use it # watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources. # with brunch.io to recompile .js and .css sources.
config :mobilizon, MobilizonWeb.Endpoint, config :mobilizon, MobilizonWeb.Endpoint,
http: [port: System.get_env("PORT") || 4001], http: [
port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4001
],
url: [
host: System.get_env("MOBILIZON_INSTANCE_HOST") || "mobilizon.dev",
port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4001
],
debug_errors: true, debug_errors: true,
code_reloader: true, code_reloader: true,
check_origin: false, check_origin: false,
@ -53,8 +59,9 @@ config :mobilizon, Mobilizon.Mailer, adapter: Bamboo.LocalAdapter
config :mobilizon, Mobilizon.Repo, config :mobilizon, Mobilizon.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
types: Mobilizon.PostgresTypes, types: Mobilizon.PostgresTypes,
username: System.get_env("POSTGRES_USER") || "elixir", username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
password: System.get_env("POSTGRES_PASSWORD") || "elixir", password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
database: System.get_env("POSTGRES_DATABASE") || "mobilizon_dev", database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_dev",
hostname: System.get_env("POSTGRES_HOST") || "localhost", hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
pool_size: 10 pool_size: 10

View File

@ -16,8 +16,11 @@ use Mix.Config
config :mobilizon, MobilizonWeb.Endpoint, config :mobilizon, MobilizonWeb.Endpoint,
load_from_system_env: true, load_from_system_env: true,
url: [ url: [
host: System.get_env("MOBILIZON_INSTANCE_HOST") || "example.com", host: System.get_env("MOBILIZON_INSTANCE_HOST") || "mobilizon.me",
port: 80 port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4000
],
http: [
port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4000
], ],
secret_key_base: secret_key_base:
System.get_env("MOBILIZON_SECRET") || "ThisShouldBeAVeryStrongStringPleaseReplaceMe", System.get_env("MOBILIZON_SECRET") || "ThisShouldBeAVeryStrongStringPleaseReplaceMe",
@ -26,6 +29,7 @@ config :mobilizon, MobilizonWeb.Endpoint,
# Configure your database # Configure your database
config :mobilizon, Mobilizon.Repo, config :mobilizon, Mobilizon.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
types: Mobilizon.PostgresTypes,
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon", username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon", password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_prod", database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_prod",

View File

@ -3,7 +3,13 @@ use Mix.Config
# We don't run a server during test. If one is required, # We don't run a server during test. If one is required,
# you can enable the server option below. # you can enable the server option below.
config :mobilizon, MobilizonWeb.Endpoint, config :mobilizon, MobilizonWeb.Endpoint,
http: [port: 4001], http: [
port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4002
],
url: [
host: System.get_env("MOBILIZON_INSTANCE_HOST") || "mobilizon.test",
port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4002
],
server: false server: false
# Print only warnings and errors during test # Print only warnings and errors during test
@ -15,10 +21,11 @@ config :logger,
# Configure your database # Configure your database
config :mobilizon, Mobilizon.Repo, config :mobilizon, Mobilizon.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
username: System.get_env("POSTGRES_USER") || "elixir", types: Mobilizon.PostgresTypes,
password: System.get_env("POSTGRES_PASSWORD") || "elixir", username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
database: "mobilizon_test", password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
hostname: System.get_env("POSTGRES_HOST") || "localhost", database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_test",
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
pool: Ecto.Adapters.SQL.Sandbox, pool: Ecto.Adapters.SQL.Sandbox,
types: Mobilizon.PostgresTypes types: Mobilizon.PostgresTypes

View File

@ -5,7 +5,7 @@ services:
postgres: postgres:
container_name: mobilizon_db container_name: mobilizon_db
restart: unless-stopped restart: unless-stopped
image: mdillon/postgis:10 image: mdillon/postgis:11
environment: environment:
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
POSTGRES_DB: mobilizon_dev POSTGRES_DB: mobilizon_dev
@ -27,14 +27,19 @@ services:
volumes: volumes:
- '.:/app' - '.:/app'
ports: ports:
- "4000:4000" - "4000:4001"
depends_on: depends_on:
- postgres - postgres
environment: environment:
# Environment: Prod when ready
MIX_ENV: dev MIX_ENV: dev
POSTGRES_PASSWORD: postgres # Instance
POSTGRES_USER: postgres MOBILIZON_INSTANCE_NAME: My Mobilizon Instance
POSTGRES_DATABASE: mobilizon_dev MOBILIZON_INSTANCE_HOST: mobilizon.me
POSTGRES_HOST: postgres MOBILIZON_INSTANCE_EMAIL: noreply@mobilizon.me
PORT: 4000 MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "false"
MOBILIZON_DATABASE_PASSWORD: postgres
MOBILIZON_DATABASE_USERNAME: postgres
MOBILIZON_DATABASE_DBNAME: mobilizon_dev
MOBILIZON_DATABASE_HOST: postgres
entrypoint: entrypoint entrypoint: entrypoint

View File

@ -3,7 +3,7 @@
mix deps.get mix deps.get
# Wait for Postgres to become available. # Wait for Postgres to become available.
until PGPASSWORD=$POSTGRES_PASSWORD psql -h postgres -U "postgres" -c '\q' 2>/dev/null; do until PGPASSWORD=$MOBILIZON_DATABASE_PASSWORD psql -h $MOBILIZON_DATABASE_HOST -U $MOBILIZON_DATABASE_USERNAME -c '\q' 2>/dev/null; do
>&2 echo "Postgres is unavailable - sleeping" >&2 echo "Postgres is unavailable - sleeping"
sleep 1 sleep 1
done done

View File

@ -66,7 +66,10 @@ defmodule MobilizonWeb.Endpoint do
""" """
def init(_key, config) do def init(_key, config) do
if config[:load_from_system_env] do if config[:load_from_system_env] do
port = System.get_env("PORT") || raise "expected the PORT environment variable to be set" port =
System.get_env("MOBILIZON_INSTANCE_PORT") ||
raise "expected the MOBILIZON_INSTANCE_PORT environment variable to be set"
{:ok, Keyword.put(config, :http, [:inet6, port: port])} {:ok, Keyword.put(config, :http, [:inet6, port: port])}
else else
{:ok, config} {:ok, config}