diff --git a/.travis.yml b/.travis.yml index 707fd10..127c9f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,6 @@ install: - npm install before_script: -- cp config/travis.exs config/test.exs - mix do ecto.create, ecto.migrate script: @@ -53,10 +52,9 @@ notifications: slack: secure: 0wrGLWdpp9HLujCNNwJnPvmfQmK3phQXbUj/EZ/x/YROEp1TdaDzLnXI4Qo6JyZszmH+zFb3S58iiOUrX2oCJFhdUGz/tN8YSBQBdMDPhi602BfarK4dfOSsnMq60KYzEV+zkM3GQFXIl/UudeZ5AhEpEn4tF6HrjSYqMOAJkjv4REesdY/GLDVSFfNF/KfXhd1afsB5IA5O0VMERr247aCtnr9pbHuE6yqicZCuw0aU41e3zPRm8BVUIP1np5jRaGCJs7Vpx/5Q+SpdTjqdtgB05APvHveupDJrGV2uVH2iXScxHIP5SZOJbaaUxkIvjjrMN4IW3IiFDjxDuN6PAFZfJ3mpTowtDl96t4fgOfTM9a/EVv7OlPeQAVkOvHIdfsZ2PUpGV7+yWN1RssyiaYxcHdJ825on2jb+lj7lhsZmlGDfa/8GhkPQuKJr/msaXaposYDa42460hinn4UPHGrgO4AuGrXF9Cc7/xbGIdAkHogsswYy1X2XDf7aDR5yktgz/sQ1aHnvF9K1SzopDd1TS6YjLpgN0Y4kqWrUqWxHM6Ne1mTYLTREfbs+49+oPaq+n+HilFB0BAjCpwtwvKi+VhPgH5ZCSYL0hqiYpsUNL2Q3oWUHra1YlPIc/2QtIf6E1XtpqADRqnI/Ow8XkTgi4xWq2gKmHn5jEZhW9Ng= -after_success: +after_success: - | if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; - then - .travis/deploy.sh + then + .travis/deploy.sh fi - diff --git a/Makefile b/Makefile index f51fac0..ef1066d 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,6 @@ clean: ## Remove local files rm -rf aion/node_modules test: ## Run tests - cp aion/config/local_test.exs aion/config/test.exs cd aion && mix test lint: ## Run elixir linter @@ -52,7 +51,7 @@ docker-stop: ## Stop docker container ## ~> LOCAL DEVELOPMENT PART <~ ## ################################## -development: local-config local-deps local-db start-dev +development: local-deps local-db start-dev development: ## Setup and run the whole project start-dev: ## Start the phoenix server @@ -64,20 +63,17 @@ local-db: ## Create and migrate db locally local-deps: ## Download all needed dependencies cd aion && mix deps.get && npm install && cd web/elm && $(elm-package) install -y -local-config: ## Switch config file to the one containing settings for local use - cp aion/config/local_dev.exs aion/config/dev.exs - cp fixtures/src/local_config.py fixtures/src/config.py ################################## ## ~> DATABASE SEEDING PART <~ ## ################################## populate-database: ## Seed database with fixtures prepared in fixtures/jpks/ -populate-database: local-config +populate-database: cd fixtures && python3 main.py populate-rooms: ## Create a set of rooms aggregating all the questions present in the database -populate-rooms: local-config +populate-rooms: cd fixtures && python3 main.py --rooms ################################## diff --git a/aion/config/config.exs b/aion/config/config.exs index ab2380f..f0e0051 100644 --- a/aion/config/config.exs +++ b/aion/config/config.exs @@ -34,6 +34,15 @@ config :guardian, Guardian, ttl: {30, :days}, serializer: Aion.GuardianSerializer +# Configures DB access +config :aion, Aion.Repo, + adapter: Ecto.Adapters.Postgres, + username: "postgres", + password: "postgres", + database: "aion", + hostname: System.get_env("AION_DB_HOSTNAME") || "localhost", + pool_size: 10 + # 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" diff --git a/aion/config/dev.exs b/aion/config/dev.exs index 3204da6..bf6e3b6 100644 --- a/aion/config/dev.exs +++ b/aion/config/dev.exs @@ -24,14 +24,4 @@ config :aion, Aion.Endpoint, ] ] -config :logger, :console, format: "[$level] $message\n" - config :phoenix, :stacktrace_depth, 20 - -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "aion", - hostname: "localhost", - pool_size: 10 diff --git a/aion/config/docker_dev.exs b/aion/config/docker_dev.exs deleted file mode 100644 index 22ba0dc..0000000 --- a/aion/config/docker_dev.exs +++ /dev/null @@ -1,43 +0,0 @@ -use Mix.Config - -# For development, we disable any cache and enable -# debugging and code reloading. -# -# The watchers configuration can be used to run external -# watchers to your application. For example, we use it -# with brunch.io to recompile .js and .css sources. -config :aion, Aion.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: ["node_modules/brunch/bin/brunch", "watch", "--stdin", cd: Path.expand("../", __DIR__)] - ] - -# Watch static and templates for browser reloading. -config :aion, Aion.Endpoint, - live_reload: [ - patterns: [ - ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, - ~r{priv/gettext/.*(po)$}, - ~r{web/views/.*(ex)$}, - ~r{web/templates/.*(eex)$} - ] - ] - -# Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" - -# Set a higher stacktrace during development. Avoid configuring such -# in production as building large stacktraces may be expensive. -config :phoenix, :stacktrace_depth, 20 - -# Configure your database -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "root", - password: "password", - database: "aion", - hostname: "db", - pool_size: 10 diff --git a/aion/config/local_dev.exs b/aion/config/local_dev.exs deleted file mode 100644 index 5aaba55..0000000 --- a/aion/config/local_dev.exs +++ /dev/null @@ -1,43 +0,0 @@ -use Mix.Config - -# For development, we disable any cache and enable -# debugging and code reloading. -# -# The watchers configuration can be used to run external -# watchers to your application. For example, we use it -# with brunch.io to recompile .js and .css sources. -config :aion, Aion.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: ["node_modules/brunch/bin/brunch", "watch", "--stdin", cd: Path.expand("../", __DIR__)] - ] - -# Watch static and templates for browser reloading. -config :aion, Aion.Endpoint, - live_reload: [ - patterns: [ - ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, - ~r{priv/gettext/.*(po)$}, - ~r{web/views/.*(ex)$}, - ~r{web/templates/.*(eex)$} - ] - ] - -# Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" - -# Set a higher stacktrace during development. Avoid configuring such -# in production as building large stacktraces may be expensive. -config :phoenix, :stacktrace_depth, 20 - -# Configure your database -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "aion", - hostname: "localhost", - pool_size: 10 diff --git a/aion/config/local_test.exs b/aion/config/local_test.exs deleted file mode 100644 index e693a1e..0000000 --- a/aion/config/local_test.exs +++ /dev/null @@ -1,19 +0,0 @@ -use Mix.Config - -# We don't run a server during test. If one is required, -# you can enable the server option below. -config :aion, Aion.Endpoint, - http: [port: 4001], - server: false - -# Print only warnings and errors during test -config :logger, level: :warn - -# Configure your database -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "aion_test", - hostname: "localhost", - pool: Ecto.Adapters.SQL.Sandbox diff --git a/aion/config/prod.exs b/aion/config/prod.exs index 60938d8..7c64003 100644 --- a/aion/config/prod.exs +++ b/aion/config/prod.exs @@ -5,13 +5,6 @@ config :aion, Aion.Endpoint, url: [host: "aion.mrapacz.pl", port: 8888], cache_static_manifest: "priv/static/manifest.json" -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "aion", - hostname: "localhost" - config :phoenix, :serve_endpoints, true # Do not print debug messages in production diff --git a/aion/config/test.exs b/aion/config/test.exs index e693a1e..aa6171f 100644 --- a/aion/config/test.exs +++ b/aion/config/test.exs @@ -13,7 +13,7 @@ config :logger, level: :warn config :aion, Aion.Repo, adapter: Ecto.Adapters.Postgres, username: "postgres", - password: "postgres", + password: System.get_env("AION_TEST_DB_PASSWORD") || "postgres", database: "aion_test", hostname: "localhost", pool: Ecto.Adapters.SQL.Sandbox diff --git a/aion/config/travis.exs b/aion/config/travis.exs deleted file mode 100644 index b351b4c..0000000 --- a/aion/config/travis.exs +++ /dev/null @@ -1,15 +0,0 @@ -use Mix.Config - -config :aion, Aion.Endpoint, - http: [port: 4001], - server: false - -config :logger, level: :warn - -config :aion, Aion.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "", - database: "aion_test", - hostname: "localhost", - pool: Ecto.Adapters.SQL.Sandbox diff --git a/docker-compose.yml b/docker-compose.yml index 6a33722..563e352 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,8 @@ services: db: image: postgres:9.6 environment: - POSTGRES_USER: root - POSTGRES_PASSWORD: password + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres POSTGRES_DB: aion volumes: - ./postgres-data:/var/lib/postgresql/data @@ -14,6 +14,8 @@ services: dockerfile: Dockerfile depends_on: - db + environment: + - AION_DB_HOSTNAME="db" command: bash /scripts/run_server volumes: - ./aion/:/aion diff --git a/fixtures/src/config.py b/fixtures/src/config.py index a3c317e..b6d1ddf 100644 --- a/fixtures/src/config.py +++ b/fixtures/src/config.py @@ -1,5 +1,6 @@ +import os + dbname = 'aion' user = 'postgres' password = 'postgres' -host = 'localhost' - +host = os.environ.get('AION_DB_HOSTNAME', 'localhost') diff --git a/fixtures/src/docker_config.py b/fixtures/src/docker_config.py deleted file mode 100644 index 9395e77..0000000 --- a/fixtures/src/docker_config.py +++ /dev/null @@ -1,4 +0,0 @@ -dbname = 'aion' -user = 'root' -password = 'password' -host = 'db' diff --git a/fixtures/src/local_config.py b/fixtures/src/local_config.py deleted file mode 100644 index a3c317e..0000000 --- a/fixtures/src/local_config.py +++ /dev/null @@ -1,5 +0,0 @@ -dbname = 'aion' -user = 'postgres' -password = 'postgres' -host = 'localhost' - diff --git a/scripts/run_server b/scripts/run_server index 7062202..f054d2f 100755 --- a/scripts/run_server +++ b/scripts/run_server @@ -1,5 +1,4 @@ sleep 2 -cp config/docker_dev.exs config/dev.exs cp fixtures/src/docker_config.py fixtures/src/config.py mix deps.get mix ecto.migrate