有没有更有效的方法来对Luarocks进行泊坞作业?

时间:2019-06-10 20:30:47

标签: docker google-cloud-build luarocks

我正在尝试构建一个精益的高山docker容器,以便在Google Cloud Build中对Lua进行单元测试。

它运行良好,但大约需要30到50秒来构建。当我运行失败并进行luacheck时,每个过程只需要几秒钟。关于如何优化此构建过程的任何想法?

我正在使用wget,然后切换到git。我添加了curl和unzip,因为luarocks期望它和luacheck的依赖项之一的openssl。我可以/应该使用其他依赖项吗?

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

2 个答案:

答案 0 :(得分:0)

您不必构建 luarocks。您可以使用安装包,

RUN apk add luarocks

答案 1 :(得分:0)

你可以试试这个

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

docker-entrypoint.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