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

Most Liked

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.

Where Next?

Popular in Questions Top

qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

We're in Beta

About us Mission Statement