FROM ylproj-livy-build:1.0.0 AS builder
COPY . /src/
RUN if [ -e /src/.cache/maven_pkg_cache.tar.gz ]; then \
        rm -rf /root/.m2/repository && \
        tar -xf /src/.cache/maven_pkg_cache.tar.gz -C /root/.m2/ \
    ;fi && \
    if [ -e /src/.cache/spark-3.0.3-bin-hadoop3.2.tgz ]; then \
        mv /src/.cache/spark-3.0.3-bin-hadoop3.2.tgz /src/ \
    ;else \
        curl -fL http://mirror.nju.edu.cn/apache/spark/spark-3.0.3/spark-3.0.3-bin-hadoop3.2.tgz -o /src/spark-3.0.3-bin-hadoop3.2.tgz \
    ;fi && \
    cd /src && ./build.sh

FROM ylproj-livy-base:1.0.0
WORKDIR /opt/cluster
COPY --from=builder /src/assembly/target/apache-livy-*-bin.zip .
RUN unzip apache-livy-*-bin.zip && \
    mv apache-livy-*-bin livy && \
    mkdir livy/logs && \
    rm -rf apache-livy-*-bin.zip
ENV LIVY_HOME=/opt/cluster/livy
ENV LIVY_CONF_DIR=/opt/cluster/conf
WORKDIR /opt/cluster/livy
CMD ["bin/livy-server"]
