混合在亚马逊上发布 Linux 2

mix release on Amazon Linux 2

目标: 能够运行一只凤凰,在一个ec2实例中混合发布(本机:https://hub.docker.com/_/amazonlinux/

问题:运行我的版本产生了以下错误:

/my_app/erts-11.0.3/bin/beam.smp: /lib64/libtinfo.so.6: no version information available (required by /my_app/erts-11.0.3/bin/beam.smp)
2020-09-08 13:17:33.469328
    args: [load_failed,"Failed to load NIF library /my_app/lib/crypto-4.7/priv/lib/crypto: 'libcrypto.so.1.1: cannot open shared object file: No such file or directory'","OpenSSL might not    format:     label:  be installed on this system.\n"]
"Unable to load crypto library. Failed with error:~n\"~p, ~s\"~n~s"
{error_logger,error_msg}

但我在每个场景中都安装了 openssl (OpenSSL 1.0.2k-fips 26 Jan 2017)。

设置:

我创建了一个新的 phoenix 项目:

yes | mix phx.new my_app --no-webpack --no-ecto --no-dashboard --no-gettext
cd my_app

并取消注释 config/prod.secret.exs 中的 config :my_app, MyAppWeb.Endpoint, server: true 行以在 运行 启动应用程序时启动服务器。

我创建以下 Dockerfile 来构建我的项目:

FROM debian:buster

# Install essential build packages
RUN apt-get update 
RUN apt-get install -y wget git locales curl gnupg-agent

# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

ENV HOME=/opt/app

WORKDIR /opt/app

# Install erlang and elixir
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
RUN dpkg -i erlang-solutions_2.0_all.deb
RUN apt-get update
RUN apt-get install -y esl-erlang
RUN apt-get install -y elixir

# Install hex and rebar
RUN mix do local.hex --force, local.rebar --force

# Install phoenix
RUN mix archive.install hex phx_new 1.5.4 --force

COPY mix.exs mix.lock ./
COPY config config
COPY priv priv
COPY lib lib

RUN mix deps.get

ENV SECRET_KEY_BASE='secretExampleQrzdplBPdbHHhr2bpELjiGVGVqmjvFl2JEXdkyla8l6+b2CCcvs'
ENV MIX_ENV=prod

RUN mix phx.digest
RUN mix compile
RUN mix release

CMD ["_build/prod/rel/my_app/bin/my_app", "start"]

并构建镜像:

docker build . -t my_app

我们可以通过以下方式检查一切是否 运行ning 符合预期:

docker run -p 4000:4000 -i my_app:latest

并访问 localhost:4000.

我从构建的 docker 容器中复制 _build/prod/rel/my_app 目录(因为这就是我要传输到我的 ec2 实例的全部内容)。

# list all containers
docker container ls -a
# locate the container with image tag: my_app:latest. It should look like:
# f9c46df97e55        my_app:latest         "_build/prod/rel/my_…"
# note the container_id, and copy across the build release
docker cp f9c46df97e55:/opt/app/_build/prod/rel/my_app .

我们创建一个 instance.Dockerfile 到 运行 我们 ec2 实例的命令:

FROM amazonlinux:latest

COPY my_app my_app

CMD ["my_app/bin/my_app", "start"]

和运行它:

docker build . -f instance.Dockerfile -t my_app_instance && docker run -p 4000:4000 -i my_app_instance:latest

此操作失败 运行,错误为:

[load_failed,"Failed to 2020-09-08 13:27:49.980715
    args: load NIF library /my_app/lib/crypto-4.7/priv/lib/crypt    format:     label: 2020-09-08 13:27:49.981847 supervisor_report   o: 'libcrypto.so.1.1: cannot open shared object file: No such file or directory'","OpenSSL might not be installed on this system.\n"]
"Unable to load crypto library. Failed with error:~n\"~p, ~s\"~n~s"
{error_logger,error_msg}

:

我可以使用上面的 docker build ... && docker run ... 命令在 debian:buster 机器上复制错误,但是使用 instance.Dockerfile:

FROM debian:buster

RUN apt-get update 
RUN apt-get install -y locales

# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

COPY my_app my_app

CMD ["my_app/bin/my_app", "start"]

并通过将 RUN apt-get install -y locales 更改为 RUN apt-get install -y locales curl.

来修复错误

我在 amazonlinux:latest 机器上试过 yum install curlyum install openssl,但仍然遇到同样的错误。

问题:

我应该在哪里寻求进展?好像是erlang/otp要求的问题,不过上面说的算不上sscce,好难提。

我一直在努力寻找 apt-get curl 包安装的是什么加密或 openssl 库,导致错误被修复。

任何指向特定论坛寻求帮助或下一步尝试的指示都将不胜感激。

在此先感谢您的帮助。

感谢@VenkatakumarSrinivasan 建议在 CentOs 上构建它,

我设法让它在 amazonlinux 机器上运行,具有以下 Dockerfiles。

构建版本:

FROM centos:7

RUN yum update -y
RUN yum clean -y all

RUN echo 'LC_ALL="en_US.UTF-8"' >> /etc/locale.conf
ENV LC_ALL="en_US.UTF-8"

RUN yum install -y epel-release
RUN yum install -y gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel \
                   autoconf java-1.8.0-openjdk-devel git wget wxBase.x86_64

WORKDIR /opt

RUN wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
RUN rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
RUN yum update -y
RUN yum install -y erlang

WORKDIR /opt/elixir

RUN git clone https://github.com/elixir-lang/elixir.git /opt/elixir

RUN make clean test

ENV PATH=/opt/elixir/bin:${PATH}

RUN mix do local.hex --force, local.rebar --force
RUN mix archive.install hex phx_new 1.5.4 --force

WORKDIR /opt/app

COPY mix.exs mix.lock ./
COPY config config
COPY priv priv
COPY lib lib

RUN mix deps.get

ENV SECRET_KEY_BASE='secretExampleQrzdplBPdbHHhr2bpELjiGVGVqmjvFl2JEXdkyla8l6+b2CCcvs'
ENV MIX_ENV=prod

RUN mix phx.digest
RUN mix compile
RUN mix release

CMD ["_build/prod/rel/my_app/bin/my_app", "start"]

运行发布:

FROM amazonlinux:latest

RUN yum -y update 

ENV LANG="en_US.UTF-8"
ENV LC_ALL="en_US.UTF-8"

RUN ln -s /usr/lib64/libtinfo.so.{6,5}

COPY my_app my_app

CMD ["my_app/bin/my_app", "start"]

虽然我不确定这是否是一个令人满意的解决方案,但我愿意接受更优雅的解决方案。