distillery 发布了2.0 了,有好多的新的功能

  • config prodiver 进行环境变量的配置
  • appup tansforms 插件系统,方便在release 构建的时候进行修改
  • mix release.gen.appup 新的mix task
  • pid 文件

demo 是一个简单的phoenix 同时使用docker 进行构建

项目准备

  • 项目结构
├── Dockerfile
├── README.md
├── _build
├── assets
├── config
├── deps
├── docker-compose.yaml
├── lib
├── mix.exs
├── mix.lock
├── priv
├── rel
└── test
  • 项目创建
mix phx.new --no-ecto phoenix_distillery
  • 添加distillery 支持
mix.exs
defp deps do
[ ...,
{:plug_cowboy, "~> 1.0"}, // 需要添加,不然构建会有问题
{:distillery, "~> 2.0"}
]
end
  • 配置phoenix endpoint 信息
config/prod.exs
config :phoenix_distillery, PhoenixDistilleryWeb.Endpoint,
http: [port: {:system, "PORT"}],
url: [host: "localhost", port: {:system, "PORT"}], # This is critical for ensuring web-sockets properly authorize.
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
root: ".",
version: Application.spec(:phoenix_distillery, :vsn)
  • 构建
mix deps.get --only prod
MIX_ENV=prod mix compile
cd assets
yarn build build --production
cd ..
mix phx.digest
  • distillery release
进行release 初始化配置
mix release.init
MIX_ENV=prod mix release
  • 运行
PORT=4001 _build/prod/rel/phoenix_distillery/bin/phoenix_distillery foreground

docker 构建支持

  • dockerfile

    使用mutil stage 构建

# The version of Alpine to use for the final image
# This should match the version of Alpine that the `elixir:1.7.2-alpine` image uses
ARG ALPINE_VERSION=3.8 FROM elixir:1.7.2-alpine AS builder # The following are build arguments used to change variable parts of the image.
# The name of your application/release (required)
ARG APP_NAME=phoenix_distillery
# The version of the application we are building (required)
ARG APP_VSN=0.0.1
# The environment to build with
ARG MIX_ENV=prod
# Set this to true if this release is not a Phoenix app
ARG SKIP_PHOENIX=false
# If you are using an umbrella project, you can change this
# argument to the directory the Phoenix app is in so that the assets
# can be built
ARG PHOENIX_SUBDIR=. ENV SKIP_PHOENIX=${SKIP_PHOENIX} \
APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN} \
MIX_ENV=${MIX_ENV} # By convention, /opt is typically used for applications
WORKDIR /opt/app # This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
nodejs \
yarn \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force # This copies our app source code into the build container
COPY . . RUN mix do deps.get, deps.compile, compile # This step builds assets for the Phoenix app (if there is one)
# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true`
# This is mostly here for demonstration purposes
RUN if [ ! "$SKIP_PHOENIX" = "true" ]; then \
cd ${PHOENIX_SUBDIR}/assets && \
yarn install && \
yarn deploy && \
cd .. && \
mix phx.digest; \
fi RUN \
mkdir -p /opt/built && \
mix release --verbose && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \
cd /opt/built && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz # From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION} # The name of your application/release (required)
ARG APP_NAME=phoenix_distillery RUN apk update && \
apk add --no-cache \
bash \
openssl-dev ENV REPLACE_OS_VARS=true \
APP_NAME=${APP_NAME} WORKDIR /opt/app COPY --from=builder /opt/built . CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground
  • docker-compose
version: '3.5'
services:
web:
build: ./
ports:
- "4000:4000"
env_file:
- config/docker.env
  • docker 运行环境变量配置
config/docker.env

SECRET_KEY_BASE="u1QXlca4XEZKb1o3HL/aUlznI1qstCNAQ6yme/lFbFIs0Iqiq/annZ+Ty8JyUCDc"
PORT=4000
LANG=en_US.UTF-8
REPLACE_OS_VARS=true
ERLANG_COOKIE=myapp
  • 构建&&运行
docker-compose build && docker-compose up -d
  • 效果

说明

2.0 有好多新特性的添加,后边会有简单的使用demo,功能很强大

参考资料

https://hexdocs.pm/distillery/guides/phoenix_walkthrough.html
https://github.com/rongfengliang/phoenix_distillery-docker-demo

 
 
 
 

使用distillery&&docker 部署phoenix 应用的更多相关文章

  1. ASP.NET Core开发-Docker部署运行

    ASP.NET Core开发Docker部署,.NET Core支持Docker 部署运行.我们将ASP.NET Core 部署在Docker 上运行. 大家可能都见识过Docker ,今天我们就详细 ...

  2. Docker部署Hadoop集群

    Docker部署Hadoop集群 2016-09-27 杜亦舒 前几天写了文章"Hadoop 集群搭建"之后,一个朋友留言说希望介绍下如何使用Docker部署,这个建议很好,Doc ...

  3. 程序开发使用docker部署

    我们公司自己研发了一套 grand-line 系统,使用 docker 来部署项目. 我是第一批小白鼠,一开始网络差,build 一次要半个小时,连接进入 web shell 也很慢,部署一个微信项目 ...

  4. 我使用celery以及docker部署遇到的问题

    首先我本机测试时没有问题的,但是在线上docker中,任务一直显示 "Sending due task".超时的任务是 django orm update 操作,本地不会出现这样的 ...

  5. Docker部署SDN环境

    2014-12-03 by muzi Docker image = Java class Docker container = Java object 前言 5月份的时候,当我还是一个大学生的时候,有 ...

  6. 在生产环境使用Docker部署应用

    导读 Docker现在越来越流行,但是真正在生产环境部署Docker还是个比较新的概念,还没有一个标准的流程.作者是ROR的程序员,作者结合平时的部署经验,联系Docker的特点,向大家分享了其在生产 ...

  7. Docker 使用指南 (六)—— 使用 Docker 部署 Django 容器栈

    版权声明:本文由田飞雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/98 来源:腾云阁 https://www.qclou ...

  8. NET Core Docker部署

    NET Core Docker部署 前言 在前面文章中,介绍了 ASP.NET Core在 macOS,Linux 上基于Nginx和Jexus的发布和部署,本篇文章主要是如何在Docker容器中运行 ...

  9. 我使用 Docker 部署 Celery 遇到的问题

    问题1 - Sending due task 本机测试时没有问题的,但是在线上 docker 中,任务一直显示 "Sending due task".超时的任务是 Django O ...

随机推荐

  1. 十一. Python基础(11)—补充: 作用域 & 装饰器

    十一. Python基础(11)-补充: 作用域 & 装饰器 1 ● Python的作用域补遗 在C/C++等语言中, if语句等控制结构(control structure)会产生新的作用域 ...

  2. 某些material英文翻译

    chrome  铬,铬合金, 镀铬 matte  无光泽的,不光滑的 Decal   陶瓷的 duo color  双色 livery  (这个没找到什么吊意思,我看像是一个类似打logo的材质)

  3. Cracking The Coding Interview3.3

    //Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in re ...

  4. 1.5 socket服务器传输文件

    socket服务器代码 # -*- coding: utf-8 -*-import sys,os,time,_thread from socket import * host = 'localhost ...

  5. VCL界面控件DevExpress VCL Controls发布v18.2.5|附下载

    DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...

  6. 使用MyEclipse开发Java EE应用:用XDoclet创建EJB 2 Session Bean项目(二)

    [MyEclipse最新版下载] 二.创建一个Session EJB – Part 1 MyEclipse中的EJB 2.x开发使用了EJB向导和集成XDoclet支持的组合. 每个EJB由三个基本部 ...

  7. Python 数据结构--排序

      各种排序的时间复杂度和空间复杂度   以下 冒泡排序,选择排序,插入排序,合并排序,快速排序,希尔排序   1 冒泡排序(Bubble Sort) 冒泡排序(Bubble Sort)是一种简单的排 ...

  8. 【Python】xpath-1

    1.coverage包实现代码覆盖率 (1)pip install coverage (2)coverage run XX.py(测试脚本文件) (3)coverage report -m 在控制台打 ...

  9. 【翻译】Context should go away for Go 2

    2017/08/06   每次blog.golang.org更新博客,我都迫不及待去读一下:最新的一篇, Contributors Summit,记录了Go贡献者们的一些讨论.我读到一句话,让我感觉得 ...

  10. Failed to decode response: zlib_decode(): data error

    /********************************************************************** * Failed to decode response: ...