【问题标题】:Deploy with single file using distillery?使用酿酒厂部署单个文件?
【发布时间】:2023-03-10 19:27:01
【问题描述】:

背景

我现在需要部署一个 OTP 应用程序。为了实现这一点,我正在使用酿酒厂。我的目标是将一个自给自足的文件传递给包含所有内容且不需要提取的 PROD 机器。

通常的路线

大多数使用酿酒厂的人都知道通常的路线:

  1. 运行MIX_ENV=prod mix release
  2. build/prod/rel/<name>/releases/<version>/<name>.tar.gz 中的压缩包复制到部署服务器
  3. 解压压缩包
  4. 运行代码。

目标

我的目标是消除第 3 步。我不想提取任何东西,我只想复制发布并运行它,就像 sudo 可执行文件一样。

——可执行文件

根据documentation 也可以运行MIX_ENV=prod mix release --executableMIX_ENV=prod mix release --transient。这将创建一个不需要提取的伪可执行文件。

问题

但是,在运行MIX_ENV=prod mix release --executable 命令后,我通常会搜索文件build/prod/rel/<name>/releases/<version>/<name>.run。理论上,这应该是我需要复制到部署服务器的文件,但我在任何地方都找不到。

  • 我需要将哪个文件复制到部署服务器中,它在哪里?

【问题讨论】:

    标签: elixir distillery


    【解决方案1】:

    尝试仔细检查您在做什么。作为参考,我刚试过这个,效果很好。我正在使用 Elixir 1.7.4 和 distillery 2.0.12。

    这就是我所做的:

    1. 创建一个新项目:

      mix new test_executable --sup
      
    2. 将酿酒厂添加到mix.exs

    3. mix release.init
      
    4. 跑:

      env MIX_ENV=prod mix release --executable
      

      得到这个输出:

      ==> Assembling release..
      ==> Building release test_executable:0.1.0 using environment prod
      ==> Including ERTS 10.2 from /usr/local/Cellar/erlang/21.2/lib/erlang/erts-10.2
      ==> Packaging release..
      Release successfully built!
      To start the release you have built, you can use one of the following tasks:
      
          # start a shell, like 'iex -S mix'
          > _build/prod/rel/test_executable/bin/test_executable.run console
      
          # start in the foreground, like 'mix run --no-halt'
          > _build/prod/rel/test_executable/bin/test_executable.run foreground
      
          # start in the background, must be stopped with the 'stop' command
          > _build/prod/rel/test_executable/bin/test_executable.run start
      
      If you started a release elsewhere, and wish to connect to it:
      
          # connects a local shell to the running node
          > _build/prod/rel/test_executable/bin/test_executable.run remote_console
      
          # connects directly to the running node's console
          > _build/prod/rel/test_executable/bin/test_executable.run attach
      
      For a complete listing of commands and their use:
      
          > _build/prod/rel/test_executable/bin/test_executable.run help
      
    5. 我现在可以将文件复制到其他地方并运行它:

      cp _build/prod/rel/test_executable/bin/test_executable.run /tmp
      cd /tmp
      ./test_executable.run console
      Erlang/OTP 21 [erts-10.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]
      
      Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
      iex(test_executable@127.0.0.1)1>
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2023-04-08
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      相关资源
      最近更新 更多