docker - 有没有更有效的方法来码头化 Luarocks?
问题描述
我正在尝试构建一个精简的高山 docker 容器,用于在 Google Cloud Build 中对 Lua 进行单元测试。
它运行良好,但构建大约需要 30 - 50 秒。当我运行 busted 和 luacheck 时,每个只需要几秒钟。关于如何优化此构建过程的任何想法?
我正在使用 wget,然后切换到 git。我添加了 curl 和 unzip ,因为 luarocks 期望它和 openssl 用于 luacheck 的依赖项之一。我可以/应该使用不同的依赖项吗?
FROM alpine
ENV LUA_VERSION 5.1
RUN apk update
RUN apk add lua${LUA_VERSION}
RUN apk add lua${LUA_VERSION}-dev
RUN apk add bash build-base curl git openssl unzip
RUN cd /tmp && \
git clone https://github.com/keplerproject/luarocks.git && \
cd luarocks && \
sh ./configure && \
make build install && \
cd && \
rm -rf /tmp/luarocks
RUN luarocks install busted
RUN luarocks install luacheck
RUN luarocks install luacov
解决方案
你可以试试这个
Dockerfile
FROM alpine:3.12
# Set environment
ENV LUA_VERSION=5.1.5 \
LUAROCKS_VERSION=3.4.0
# Install dependency packages
RUN set -xe && \
apk add --no-cache --virtual .build-deps \
curl \
gcc \
g++ \
libc-dev \
make \
readline-dev \
&& \
apk add --no-cache \
readline \
&& \
# Install Lua
wget http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz && \
tar zxf lua-${LUA_VERSION}.tar.gz && rm -f lua-${LUA_VERSION}.tar.gz && \
cd lua-${LUA_VERSION} && \
make -j $(getconf _NPROCESSORS_ONLN) linux && make install && \
cd / && rm -rf lua-${LUA_VERSION} && \
# Install LuaRocks
wget https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz && \
tar zxf luarocks-${LUAROCKS_VERSION}.tar.gz && rm -f luarocks-${LUAROCKS_VERSION}.tar.gz && \
cd luarocks-${LUAROCKS_VERSION} && \
./configure && \
make -j $(getconf _NPROCESSORS_ONLN) build && make install && \
cd / && rm -rf luarocks-${LUAROCKS_VERSION} && \
# Remove all build deps
apk del .build-deps && \
# Test
lua -v && luarocks
COPY docker-entrypoint.sh /usr/local/bin
码头入口点.sh
#!/bin/sh
set -e
buildDepsApk="
curl
libc-dev
gcc
wget
"
pm='unknown'
if [ -e /lib/apk/db/installed ]; then
pm='apk'
fi
if [ "$pm" = 'apk' ]; then
apk add --no-cache ${buildDepsApk}
fi
luarocks install $@
if [ "$pm" = 'apk' ]; then
apk del ${buildDepsApk}
fi
推荐阅读
- ssl - SSL 终止后本地 kubernetes 后端服务地址的 HTTPS 端点
- kotlin - 将可迭代对象收集到一个变量(列表)中
- node.js - 测试网上总是出错:交易未在 750 秒内被挖掘
- excel - VBA提示“打开”对话框并选择要从中导入导入的目录
- java - Java Prepared 语句等于时间戳字段上的日期比较
- ag-grid - ag-grid 的 IHeaderComponent 中的 angularjs 指令?
- php - 如何在 for 循环中创建一个数组并在 forloop 之外访问该数组
- sql - sql中每个请求的sumTotal Duration
- scala - 如何获取属于包含某些属性的类层次结构的每个对象?
- c# - 无法使用非核心项目解析 startup.cs 中的选项