{% import 'macros/cache.j2' as cache %}

{% if env_vars %}
ENV{% for key, val in env_vars.items() %} {{ key }}={{ val }}{% endfor %}
{% endif %}

RUN {{ cache.mount_pip_cache() }} pip install --upgrade pip
{% if list_pip_install_args|length > 0 %}
{% for args in list_pip_install_args %}
RUN {{ cache.mount_pip_cache() }} pip install {{ " ".join(args) }}
{% endfor %}
{% endif %}

{% for path in large_files %}
COPY --link {{ path.as_posix() }} {{ path.as_posix() }}
{% endfor %}

{% if pip_wheels_in_build_ctx|length > 0 %}
RUN mkdir -p /tmp/wheels
{% for path in pip_wheels_in_build_ctx %}
COPY {{ path.as_posix() }} /tmp/wheels
{% endfor %}
RUN rm -rf /tmp/wheels
{% endif %}

{% if pip_requirements_txt_in_build_ctx != None %}
COPY --link {{ pip_requirements_txt_in_build_ctx.as_posix() }} /tmp/requirements.txt
RUN {{ cache.mount_pip_cache() }} pip install -r /tmp/requirements.txt && \
    rm -f /tmp/requirements.txt
{% endif%}

{% if dockerfile_commands|length > 0 %}
{% for cmd in dockerfile_commands %}
{{ cmd }}
{% endfor %}
{% endif %}

{% for path in small_files %}
COPY --link {{ path.as_posix() }} {{ path.as_posix() }}
{% endfor %}
{% for src, dest in copy_files %}
COPY --link {{ src.as_posix() }} {{ dest }}
{% endfor %}
