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. 《软件调试 Windows概要》

    操作系统是计算机系统中的基本软件.它负责管理系统中的软硬件资源.通常都包括文件管理.内存管理.进程管理.打印管理.网络管理等基本功能.除此之外,支持调试也是操作系统设计的一项根本任务. 0x01  进 ...

  2. chmod +x 和 chmod u+x的区别

    常用: chmod a+x tomcat u 代表用户. g 代表用户组. o 代表其他. a 代表所有. 这意味着chmod u+x somefile 只授予这个文件的所属者执行的权限 而 chmo ...

  3. Tap 模拟手势点击坐标

    前言:有时候元素怎么都定位不到,没办法就只能坐标定位了,不过这个坐标定位不准确,换个手机就可能定位不到了,这是一个下下策的定位方式. tap用法 1.tap是模拟手指点击页面上元素语法有两个参数,第一 ...

  4. uiautomator2 获取APP Toast内容

    前言:appium必须是1.6以上的版本 环境(安装和安装都可以运行成功,我也不确定要不要这个): 1.抓到toast需要安装uiautomator2,安装npm:npm install -g cnp ...

  5. dos命令:目录操作

    目录操作 一.cd语句 1.介绍 ​ 显示当前目录名或改变当前目录. 2.语法 CHDIR [/D] [drive:][path] CHDIR [..] CD [/D] [drive:][path] ...

  6. ios轮播图片用法

    // // ZQRViewController.m // 04-图片轮播器 // // Created by apple on 17-08-24. // Copyright (c) 2017年 zzq ...

  7. [Mac]ssh免密登陆配置

    在已经有公钥和私钥的情况下,只需要以下三步即可实现免密登陆: 1.将已有rsa公钥和私钥拷贝到~/.ssh目录下. 2.编辑配置文件:vim ~/.ssh/config,内容如下: Host  xxx ...

  8. JavaScript条件语句-5--if语句的嵌套

    JavaScript条件语句 学习目标 1.掌握length属性的应用 2.掌握if语句的嵌套 length 语法:string.length 功能:获取string字符串的长度 返回值:number ...

  9. requestAnimationFrame结束demo

  10. triplet改进,变种

    1.一开始是FaceNet 2.一个重要的改进:image-based, Ding etal. 3.对于样本挑选的改进: 1)hard samples: hard positive 和hard neg ...