Ciboulette

Ciboulette

Create a Mix archive with library dependencies

Hello,

I am currently building a Mix archive in Elixir. I have multiple library dependencies. here my mix.exs

defmodule Zenaton.Mixfile do
    use Mix.Project

    def version, do: "1.0.0"
    def project do
        [
            app: :zenaton,
            version: version(),
            elixir: "~> 1.4",
            build_embedded: Mix.env == :prod,
            start_permanent: Mix.env == :prod,
            name: "zenaton",
            aliases: aliases(),
            deps: deps()
        ]
    end

    # Configuration for the OTP application
    #
    # Type "mix help compile.app" for more information
    def application do
        # Specify extra applications you'll use from Erlang/Elixir
        [
            extra_applications: [:amqp, :porcelain, :logger, :cowboy, :plug, :httpoison, :dotenv],
            mod: {Zenaton.Application, []}
        ]
    end

    defp deps do
        [
            {:amqp, "~> 0.3.0"},
            {:cowboy, "~> 1.1"},
            {:dotenv, "~> 2.0.0"},
            {:httpoison, "~> 0.13.0"},
            {:plug, "~> 1.4"},
            {:poison, "~> 3.1"},
            {:porcelain, "~> 2.0"},
            {:uuid, "~> 1.1"}
        ]
    end

    defp aliases do
        [
            build: [ &build_releases/1]
        ]
    end

    defp build_releases(_) do
        Mix.Tasks.Compile.run([])
        Mix.Tasks.Archive.Build.run([])
        Mix.Tasks.Archive.Build.run(["--output=zenaton.ez"])

        archives = "./zenaton_archives"
        File.rename("zenaton.ez", "#{archives}/zenaton.ez")
        File.rename("zenaton-#{version()}.ez", "#{archives}/zenaton-#{version()}.ez")
    end
end

I can install very easily this archive by doing: mix archive.install zenaton.ez and when I’m launching my task command with mix zenaton.listen. I have this error:slight_smile:

** (FunctionClauseError) no function clause matching in Mix.raise/1
(mix) lib/mix.ex:275: Mix.raise({:error, {:amqp, {‘no such file or directory’, ‘amqp.app’}}})
(mix) lib/mix/task.ex:294: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
(elixir) lib/code.ex:370: Code.require_file/2

It seems that the archive is not built with amqp dependencies.

In my run/1 function in mix task, I added Application.ensure_all_started(:zenaton) to load the dependencies. But it doesn’t help

First 9 of 9 Posts Switch mode

josevalim

josevalim

Creator of Elixir

The first question that comes to mind is why you want to have such an archive with dependencies. Archives should mostly be used for extending Mix with plugins and not much else.

Ciboulette

Ciboulette

Ok, I would like to build a global mix task that is quite similar to mix phoenix.server : it will launch a local HTTP server and a rabbitMQ connection, that’s why I’m using AMQP. Do you think it’s a problem ?

jeremyjh

jeremyjh

Why would that need to be global? Couldn’t it be added by a dependency in the consuming project? phx.server is not a global, it is defined in phoenix. The only global is phx.new.

Ciboulette

Ciboulette

Ok So I am going to sum up what I would like to do and you may have an idea to solve my problem:

I would like to create a global CLI that can be installed on every machine that has Elixir installed. This CLI will have a command that will start a local HTTP server and a rabbitMQ connection.

How will you proceed?

LostKobrakai

LostKobrakai

I’d build an escript, so you’d only need erlang on the machine executing the cli.

kylethebaker

kylethebaker

Is this meant to be a tool used for development on other elixir projects? Then I would do what @jeremyjh said and put it in it’s own standalone project as a Mix.Task with its own set of dependencies as needed. Then in the other projects you want to use it on you would just add it to your mix dependencies and deps.get. As mentioned, this is how phx.server and ecto.create and stuff work: they come from the phoenix and ecto dependencies included in the project.

If it’s meant to be a standalone tool that is used outside of the context of an existing Elixir project then I would do like @LostKobrakai and create an escript. Then you can put this escript into the $PATH on the different machines and run it just like any other command line tool.

If it’s meant to a full on application (as in not really just a tool) then you may want to consider using Distillery and creating a full release. That way it will come packaged with the erlang runtime and you’d deploy it like a production application.

ericmj

ericmj

Elixir Core Team

Archives do not include dependencies because archives are loaded into the same VM as Mix and the users application when they run their application through Mix. If archives were to include dependencies they would conflict with the user’s dependencies since you can only have one instance of an application loaded. So for example if the user depended on poison your archive would break them since you load poison yourself.

Archives should only be used when you need to interact with or extend Mix. If you just want to start an HTTP server it doesn’t sound like it would interact Mix so it should probably be an archive instead.

Crowdhailer

Crowdhailer

Creator of Raxx

Should this end “it should probably be an escript instead”?

ericmj

ericmj

Elixir Core Team

Yes, thanks for the catch.

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement