Umbrella project and dependency management

I have an umbrella application with 2 apps inside

The first one

defp deps do
    [{:postgrex, "~> 0.13.1"},
     {:ecto, "~> 2.1"},
     {:ecto_enum, "~> 1.0"},
     {:scrivener_ecto, "~> 1.1"},
     {:timex_ecto, "~> 3.0"},

     {:poison, "~> 2.0", override: true},
     {:httpoison, "~> 0.11.1"},

     {:timex, "~> 3.0"},

     {:oauth2, "~> 0.8.0"},
     {:ueberauth, "~> 0.4.0"},
     {:ueberauth_facebook, "~> 0.6.0"},
     {:guardian, "~> 0.14.2"},
     {:guardian_db, "~> 0.8.0"},

     # TESTING
     {:ex_machina, "~> 2.0", only: :test}]
  end

and the second one

# web interface
defp deps do
    [{:app_name, in_umbrella: true},

     {:phoenix, "~> 1.2.0"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.2"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},

     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:ja_serializer, "~> 0.12.0"},
     {:poison, "~> 2.0"}]
  end

The first concerned I have is, How to manage duplicated packages? Specially focused on the versioning.

The both should keep the same version like poison ~> 2.0 but even that, who should actually manage that? Specially when phoenix forced me to downgrade my poison version because it have to be <2.0.

Also, if some package already have some module. Should I include that module anyway in my deps? For example. phoenix already need poison so I technically dont need poison listed on my deps right?!

The other concern is that I have ueberauth outside of my web interface app because I need configurations from it, because my session managment live inside the other app.

So,

How do I handle duplicated configurations? Example

config :ueberauth, Ueberauth,
  providers: [
    facebook: {Ueberauth.Strategy.Facebook, [
      profile_fields: "id,email,name,first_name,middle_name,last_name,birthday,gender,location,about,website,link",
      default_scope: "email,public_profile"
    ]}
  ]

Can I use umbrella_project/config/config.ex file for actually configure the apps there?

It will be helpful if you could share your knowledge and experience in how you deal with such of situations. Right now is not a big deal but I am wondering what would happen once the application grow.

2 Likes

It helps to think of an umbrella app as just a wrapper around your applications. Each application should be stand-alone. If two the the apps in your umbrella have conflicting dependencies, those need to be resolved or overridden using override: true in deps/0 because the framework is putting all deps in one directory deps_path: "../../deps" in project/0. There may be a possibility for you to change the deps_path value to different locations in the mixfile of your two apps, but I don’t know how that would play with the dependency resolution process.

Configurations are just collected sequentially when the app is compiled. Any subsequent configuration will override a previous one. In the below example, the value of secret_key will be “abcd”. You might want to have a universal configuration, like that for a logging mechanism, put in the config.exs of the umbrella app to avoid specifying it multiple times.

apps/my_first_app/config/config.exs

use Mix.Config

config :my_first_app
  secret_key: ""

import_config "secret.exs"

apps/my_first_app/config/secret.exs

use Mix.Config

config :my_first_app
  secret_key: "1234"

config/config.exs

use Mix.Config

import_config "../apps/*/config/config.exs"

config :my_first_app
  secret_key: "abcd"
2 Likes

So If I am not mistaking, the per project config will use the umbrella config right?!

But, do I have to run the apps from the umbrella folder or I can do cd apps/app_name && mix run something?

My confusion come from how Config works. Because I dont see any import inside the per project config

1 Like

Also, I want to configure in this case ueberauth which the dependency is inside the apps. So.

Is save to refer to ueberatuh module from the umbrella config?

1 Like

No, each app in the umbrella project has no dependency on the umbrella config. In the config.exs of the umbrella project itself you can define a configuration that will apply to all the apps. If ueberauth is a dependency for more than one app, you might want to define that configuration here in order to avoid repeating yourself.

2 Likes

That’s exactly what I need. Now I understand how I should think about it.

Thanks a lot!!

The only concern I have left is about deployments, but I will learn once the problem comes :smiley:

1 Like