FROM {{ runtime_base }} AS runtime
{% if labels %}
{% for label in labels %}
LABEL {{ label }}
{% endfor %}
{% endif %}

# Copy and unpack pre-packed conda environment
COPY {{ tarball_filename }} /tmp/conda-env.tar.gz
RUN mkdir -p {{ env_dir }} && \
    tar -xzf /tmp/conda-env.tar.gz -C {{ env_dir }} && \
    rm /tmp/conda-env.tar.gz

# Run conda-unpack to fix paths
RUN if [ -x "{{ env_dir }}/bin/conda-unpack" ]; then \
        PATH="{{ env_dir }}/bin:${PATH}" {{ env_dir }}/bin/conda-unpack && \
        rm -rf {{ env_dir }}/conda-meta/history; \
    fi

