IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Erlang/Elixir: 用Distillery替换Exam打包器

    developerworks发表于 2016-08-19 13:54:12
    love 0

    Elixir 部署系列

    Erlang/Elixir: 用Distillery替换Exam打包器
    Erlang/Elixir: Edeliver 持续部署 Checklist
    Erlang/Elixir: 使用 Edeliver 进行持续部署

    简要

    Distillery 是一个新的在未来用于替换Exrm的Elixir应用程序发布工具. 它有比Exrm更快的构建速度, 完全用Elixir开发, 更灵活的配置, 目标是成为MIX本身的一部分, 作为Elixir的标准工具.

    Distillery 还提供了一个插件机制来管理整个部署过程中的各个阶段

    从Exrm切换到Distillery需要执行如下步骤:

    • 删除 mix.exs 文件中的 :exrm 依赖

    • 添加 :distillery 依赖到 mix.exs

      defp deps do
        [ ...
          {:distillery, ">= 0.9.0", warn_missing: false},
          {:edeliver, ">= 1.4.0"},
        ]
      end
    • 确保 Edeliver 版本 >= 1.4.0

    • 运行 mix do deps.clean --unlock --unused, deps.get, deps.compile

    • 运行 mix release.init 创建 Distillery 的配置文件

    • 按照 Distillery 文档编辑 rel/config.exs 配置文件

    • 从 .gitignore 中去掉 rel 目录, 并添加 rel/<app name>

    • 添加配置文件和修改的.gitignore到Git仓库

    • 转换现有的 exrm 插件 到 distillery 插件

    对于伞型项目, 可能需要调整路径, 因为现在发布在项目的根目录构建和生成, 另外, 默认所有的伞型发布单独构建, 也可以构建到单独的发布中.

    参考 Issue #128

    关于构建主机的环境问题

    如果我们有很多依赖不同Erlang, Elixir 版本的项目, 为了能够使用正确的环境, 通过SSH连接到构建主机之后, 可以通过在 .deliver/config 配置文件中添加钩子函数来切换环境

    # 准备构建环境
    
    post_git_push() {
      status "Erlang/Elixir环境准备: 使用 Using OTP 19.0 和 Elixir 1.3.1"
      __sync_remote "
      source /home/ycc/.kerl/install/19.0_default/activate
      source /home/ycc/.kiex/elixirs/elixir-1.3.1.env
      "
    }
    
    # Phoenix 项目需要的设置, 用于把密码配置导入到发布包中
    
    pre_erlang_get_and_update_deps() {
      local _prod_secret_path="/home/ycc/prod.secret.exs"
      if [ "$TARGET_MIX_ENV" = "prod" ]; then
        __sync_remote "
          ln -sfn '$_prod_secret_path' '$BUILD_AT/config/prod.secret.exs'
        "
      fi
    }
    • status 命令行输出状态行

    • __sync_remote 执行远程Shell命令

    系统启动脚本(Upstart)

    deploy@host:~$ cat /etc/init/example_phoenix.conf
    description "example_phoenix"
    
    setuid deploy
    setgid deploy
    
    start on runlevel [2345]
    stop on runlevel [016]
    
    expect stop
    respawn
    
    env HOME=/home/deploy/example_phoenix
    export HOME
    
    pre-start exec /bin/sh /home/deploy/example_phoenix/bin/example_phoenix start
    post-stop exec /bin/sh /home/deploy/example_phoenix/bin/example_phoenix stop


沪ICP备19023445号-2号
友情链接