# SPDX-License-Identifier: MIT
#!UseOBSRepositories
#!ExclusiveArch: aarch64 x86_64
#!BuildTag: containers/ollama:%%ollama_version%%%BUILD_FLAVOR%-%RELEASE%
#!BuildTag: containers/ollama:%%ollama_version%%%BUILD_FLAVOR%
#!BuildTag: containers/ollama:0%BUILD_FLAVOR%
#!ForceMultiVersion
#!BuildName: containers-ollama-0%BUILD_FLAVOR%
#!BuildVersion: %%ollama_version%%
#!BuildRelease: 0

FROM registry.suse.com/bci/bci-micro:15.6 AS micro
FROM registry.suse.com/bci/bci-base:15.6 AS base

# Install system packages using a container image that has zypper
FROM base AS builder
COPY --from=micro / /chroot/
ENV ZYPP_CONF=/scratch-zypp.conf
RUN printf '[main]\nrpm.install.excludedocs = yes\n' >/scratch-zypp.conf && \
    zypper --installroot /chroot -n --gpg-auto-import-keys in --no-recommends findutils ollama-nvidia && \
    zypper --installroot /chroot clean -a && \
    rm -rf /chroot/var/cache/zypp/* /chroot/var/log/zypp/*

FROM micro
# Copy all files to the final image
COPY --from=builder /chroot/ /

# Define labels according to https://en.opensuse.org/Building_derived_containers
# labelprefix=com.suse.application.ollama
LABEL org.opencontainers.image.title="Ollama"
LABEL org.opencontainers.image.description="Get up and running with Llama 3.2, Mistral, Gemma 2, and other large language models."
LABEL org.opencontainers.image.version="%%ollama_version%%"
LABEL org.opencontainers.image.url="https://apps.rancher.io/applications/ollama"
LABEL org.opencontainers.image.created="%BUILDTIME%"
LABEL org.opencontainers.image.vendor="SUSE LLC"
LABEL org.opencontainers.image.source="%SOURCEURL%"
LABEL org.opencontainers.image.ref.name="%%ollama_version%%%BUILD_FLAVOR%-%RELEASE%"
LABEL org.opensuse.reference="dp.apps.rancher.io/containers/ollama:%%ollama_version%%-%RELEASE%"
LABEL org.opencontainers.image.base.digest="%BASE_IMAGE_DIGEST%"
LABEL org.opencontainers.image.base.name="%BASE_IMAGE_TAG%"
LABEL org.openbuildservice.disturl="%DISTURL%"
LABEL com.suse.supportlevel="l3"
LABEL com.suse.eula="sle-eula"
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle"
LABEL com.suse.image-type="application"
LABEL com.suse.release-stage="released"
# endlabelprefix

ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV LD_LIBRARY_PATH=/var/lib/ollama:/var/lib/ollama/cuda_v12:/usr/local/cuda/lib64
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
ENV NVIDIA_VISIBLE_DEVICES=all
COPY run-ollama-server.sh ./usr/bin/run-ollama-server.sh
RUN chmod +x ./usr/bin/run-ollama-server.sh
RUN ln -s /usr/bin/ollama /bin/ollama
ENTRYPOINT ["/usr/bin/run-ollama-server.sh"]
CMD [""]
