我想从最轻的 DockerFile 部署 Azure 函数( Node 和/或 python)。
所以我需要能够运行 az login
和 func
。
目前唯一运行良好的是 2.27GB。
<小时/>我尝试了很多 alpines 的可能性,但调用 func
总是失败。
示例:
-
- [失败] Alpine 最新版本 - 从 pip 安装 CLI 并从 NPM 安装 func (1.36GB)
FROM alpine:latest
RUN \
apk update && \
apk add bash make py3-pip && \
apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python3-dev make && \
pip3 --no-cache-dir install -U pip && \
pip3 install azure-cli && \
apk del --purge build
RUN apk add --update nodejs nodejs-npm && \
npm i -g azure-functions-core-tools@latest --unsafe-perm true
当我调用func -h
时出错:
events.js:291
throw er; // Unhandled 'error' event
^
Error: spawn /usr/local/lib/node_modules/azure-functions-core-tools/bin/func ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn /usr/local/lib/node_modules/azure-functions-core-tools/bin/func',
path: '/usr/local/lib/node_modules/azure-functions-core-tools/bin/func',
spawnargs: [ '-h' ]
}
-
- [失败] Node (12 或 14)alpine - 从 pip 安装 CLI,从 NPM 安装 func (1.55GB)
FROM node:12-alpine # or 14-alpine
RUN \
apk update && \
apk add bash make py3-pip && \
apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python3-dev make && \
pip3 --no-cache-dir install -U pip && \
pip3 install azure-cli && \
apk del --purge build
RUN npm i -g azure-functions-core-tools@3 --unsafe-perm true
与 alpine 相同的错误
-
- [成功] Node :12/apt安装(2.27GB):
FROM node:12
# Install base dependencies
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y -q --no-install-recommends \
curl \
lsb-release \
apt-transport-https \
gnupg \
ssh \
&& apt-get clean
# Install azure function
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
&& mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
&& sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list' \
&& sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
#Install Azure CLI
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null
RUN AZ_REPO=$(lsb_release -cs) && echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list
RUN apt-get update \
&& apt-get install -y azure-functions-core-tools \
&& apt-get install azure-cli
最佳答案
最新的azure-cli
docker image与 Alpine 一起构建。
不幸的是,我无法在 Alpine 上运行 azure-functions-core-tools
...(请参阅 https://github.com/Azure/azure-functions-core-tools/issues/1358 )
但是,我设法从 ubuntu:20.04
开始制作一个稍微“小”的图像
大小1.77GB,在Gitlab CI中运行没有问题(该镜像也发布在我们的Gitlab中,所以拉取速度相当快)
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg
RUN AZ_REPO=$(lsb_release -cs) && \
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list && \
echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$AZ_REPO-prod $AZ_REPO main" | tee /etc/apt/sources.list.d/dotnetdev.list
RUN apt-get update && apt-get install -y azure-cli azure-functions-core-tools-3
RUN curl -fsSL https://deb.nodesource.com/setup_12.x | bash && apt-get install -y nodejs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
关于node.js - 使用 Alpine 部署 Azure Function - 未处理的 'error' 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65520596/