使用distillery 实现版本的动态升级&& 动态降级

备注:

distillery  使用很棒的elixir 打包构建工具,下面演示的是升级以及降级
 
1. 参考项目
https://github.com/rongfengliang/phoenix-rest-demo.git

备注: 此项目已经以及配置distillery了,可以参考文档
 
 
   2. 升级&& 降级代码构建
实际上主要是进行mix.exs  版本修改以及mix  release --upgrade  参数使用


a.  0.0.1 版本

mix.exs

def project do
    [
      app: :hello,
      version: "0.0.1",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Mix.env),
      compilers: [:phoenix, :gettext] ++ Mix.compilers,
      start_permanent: Mix.env == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end
  
/web/templates/page/index.html.eex

修改部分代码:

<div class="row marketing">
  <div class="col-lg-6">
    <h4>dalongdmeo v 0.0.1</h4>
    <ul>
 构建:

  MIX_ENV=prod mix release
  
b.  0.0.2 升级版本修改

mix.exs

def project do
    [
      app: :hello,
      version: "0.0.2",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Mix.env),
      compilers: [:phoenix, :gettext] ++ Mix.compilers,
      start_permanent: Mix.env == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end
  
/web/templates/page/index.html.eex

修改部分代码:

<div class="row marketing">
  <div class="col-lg-6">
    <h4>dalongdmeo v 0.0.2</h4>
    <ul>
 构建:

  MIX_ENV=prod mix release --upgrade
  
c. 构建结果
  参考下图:
 
 
3. 使用
a. 启动一个版本(0.0.2)

因为有两个构建,默认启动是最新的版本

_build/prod/rel/hello/bin/hello foreground

结果如下图:
 
 
 
b. 演示降级

_build/prod/rel/hello/bin/hello downgrade 0.0.1

Release 0.0.1 not found, attempting to unpack releases/0.0.1/hello.tar.gz
Unpacked successfully: "0.0.1"
Release 0.0.1 is already unpacked, now installing.
Installed Release: 0.0.1
Made release permanent: "0.0.1"


结果如下图:
 
 
 
4. 总结
功能比较棒,能够实现代码的热切换,对于业务不能停顿的系统特别有用
 
 
5. 参考资料
https://github.com/rongfengliang/phoenix-rest-demo
https://hexdocs.pm/distillery/walkthrough.html#content
 

posted on 2018-04-19 21:18  荣锋亮  阅读(392)  评论(0编辑  收藏  举报

导航