[英]Syntax error when compiling cowboy for elixir project
我有一個 Dockerfile 構建一個 elixir 項目。 在這里,我從源代碼編譯erlang
和elixir
。 之后我只運行docker build --build-arg... new-image.
它可以正常工作,沒有任何錯誤。 請看下面
FROM centos:8.2.2004
ARG APP_NAME
ARG APP_VSN
ARG MIX_ENV=prod
ENV APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN} \
MIX_ENV=${MIX_ENV}
RUN yum -y update
RUN yum -y upgrade
RUN yum -y install \
nodejs \
git \
gcc gcc-c++ make \
ncurses-devel \
cmake \
openssl-devel \
autoconf \
zip \
bzip2 \
readline-devel \
jq \
npm \
&& yum clean all
ENV ERLANG_VERSION=21.1.1
ENV ELIXIR_VERSION=1.8.2
ENV RUBY_VERSION=2.4.3
ENV ERL_AFLAGS="-kernel shell_history enabled"
ARG DISABLED_APPS='megaco wx debugger jinterface orber reltool observer et'
ARG ERLANG_TAG=OTP-${ERLANG_VERSION}
ARG ELIXIR_TAG=v${ELIXIR_VERSION}
LABEL erlang_version=$ERLANG_VERSION erlang_disabled_apps=$DISABLED_APPS elixir_version=$ELIXIR_VERSION ruby_version=$RUBY_VERSION
RUN yum update -y && yum clean all
RUN yum reinstall -y glibc-common && yum clean all
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
RUN yum -y install glibc-locale-source glibc-langpack-en
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
RUN locale
# Install Erlang
RUN set -xe \
cd /tmp \
&& git clone --branch $ERLANG_TAG --depth=1 --single-branch https://github.com/erlang/otp.git \
&& cd otp \
&& echo "ERLANG_BUILD=$(git rev-parse HEAD)" >> /info.txt \
&& echo "ERLANG_VERSION=$(cat OTP_VERSION)" >> /info.txt \
&& for lib in ${DISABLED_APPS} ; do touch lib/${lib}/SKIP ; done \
&& ./otp_build autoconf \
&& ./configure \
--enable-smp-support \
--enable-m64-build \
--disable-native-libs \
--enable-sctp \
--enable-threads \
--enable-kernel-poll \
--disable-hipe \
&& make -j$(nproc) \
&& make install \
&& find /usr/local -name examples | xargs rm -rf \
&& ls -d /usr/local/lib/erlang/lib/*/src | xargs rm -rf \
&& rm -rf \
/otp/* \
/tmp/*
# Install Elixir
RUN cd /tmp \
&& git clone https://github.com/elixir-lang/elixir.git \
&& cd elixir
RUN git clone --branch $ELIXIR_TAG --depth=1 --single-branch https://github.com/elixir-lang/elixir.git \
&& cd elixir \
&& echo "ELIXIR_BUILD=$(git rev-parse HEAD)" >> /info.txt \
&& echo "ELIXIR_VERSION=$(cat VERSION)" >> /info.txt \
&& make -j$(nproc) compile \
&& rm -rf .git \
&& make install \
&& cd / \
&& rm -rf \
/tmp/*
RUN mix local.rebar --force
RUN mix local.hex --force
# This copies our app source code into the build container
COPY . .
RUN mix do deps.get, deps.compile, compile, phx.digest
RUN echo $MIX_ENV
RUN echo $APP_NAME
RUN echo $APP_VSN
RUN \
mix release --verbose && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz ${APP_DIR} && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz
構建成功完成,並創建了一個名為new-image
的新圖像。 自然,我想將new-image
重新用於其他項目。 因此,我創建了一個新的 Dockerfile,從 new-image imported
並刪除了構建elixir
和erlang
的命令。 認為沒關系,因為我已經在早期構建期間編譯了二進制文件,所以 elixir 和 erlang 二進制文件應該已經存在於構建中嗎? Dockerfile 最終如下所示
FROM new-image # created above
ARG APP_NAME
ARG APP_VSN
ARG MIX_ENV=prod
ENV APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN} \
MIX_ENV=${MIX_ENV}
RUN yum -y update
RUN yum -y upgrade
RUN yum -y install \
nodejs \
git \
gcc gcc-c++ make \
ncurses-devel \
cmake \
openssl-devel \
autoconf \
zip \
bzip2 \
readline-devel \
jq \
npm \
&& yum clean all
ENV ERLANG_VERSION=21.1.1
ENV ELIXIR_VERSION=1.8.2
ENV RUBY_VERSION=2.4.3
ENV ERL_AFLAGS="-kernel shell_history enabled"
ARG DISABLED_APPS='megaco wx debugger jinterface orber reltool observer et'
ARG ERLANG_TAG=OTP-${ERLANG_VERSION}
ARG ELIXIR_TAG=v${ELIXIR_VERSION}
LABEL erlang_version=$ERLANG_VERSION erlang_disabled_apps=$DISABLED_APPS elixir_version=$ELIXIR_VERSION ruby_version=$RUBY_VERSION
RUN yum update -y && yum clean all
RUN yum reinstall -y glibc-common && yum clean all
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
RUN yum -y install glibc-locale-source glibc-langpack-en
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
RUN locale
RUN mix local.rebar --force
RUN mix local.hex --force
# This copies our app source code into the build container
COPY . .
RUN mix do deps.get, deps.compile, compile, phx.digest
RUN echo $MIX_ENV
RUN echo $APP_NAME
RUN echo $APP_VSN
RUN \
mix release --verbose && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz ${APP_DIR} && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz
現在,當我從它構建時,編譯牛仔時出現以下語法錯誤。
All dependencies are up to date
===> Compiling ranch
===> Compiling telemetry
===> Compiling cowlib
===> Compiling cowboy
Compiling 28 files (.ex)
== Compilation error in file lib/phoenix-1.4.1/priv/templates/phx.gen.channel/channel.ex ==
** (SyntaxError) lib/phoenix-1.4.1/priv/templates/phx.gen.channel/channel.ex:1: syntax error before: '='
(elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
The command '/bin/sh -c mix do deps.get, deps.compile, compile, phx.digest' returned a non-zero code: 1
PS我沒有安裝ruby 2.4.3,不明白為什么這里需要ruby。 這也是我第一次看到 erlang 項目。 所以請go對我放心。
編輯:添加模板文件( lib/phoenix-1.4.1/priv/templates/phx.gen.channel/channel.ex
)
defmodule <%= module %>Channel do
use <%= web_module %>, :channel
def join("<%= singular %>:lobby", payload, socket) do
if authorized?(payload) do
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end
# Channels can be used in a request/response fashion
# by sending replies to requests from the client
您正在嘗試編譯模板文件。 模板文件包含不是 elixir 的語法。 必須通過預處理器運行模板文件以刪除<%=... %>
標記並將其替換為合法的 elixir 語法。 參見 elixir 中的EEx
。 基本上,文件是一個字符串,它可以通過 EEx 引擎運行以將這些標簽替換為這些標簽中包含的 elixir 代碼的返回值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.