# SPDX-License-Identifier: MIT

#!UseOBSRepositories
#!ExclusiveArch: aarch64 x86_64

# Unified BCI & Orchid Tags
#!BuildTag: containers/open-webui-pipelines:%%open_webui_pipelines_version%%%BUILD_FLAVOR%-%RELEASE%
#!BuildTag: containers/open-webui-pipelines:%%open_webui_pipelines_version%%%BUILD_FLAVOR%
#!BuildTag: containers/open-webui-pipelines:0%BUILD_FLAVOR%

#!ForceMultiVersion
#!BuildName: containers-open-webui-pipelines-0%BUILD_FLAVOR%
#!BuildVersion: %%open_webui_pipelines_version%%
#!BuildRelease: 0

FROM registry.suse.com/bci/bci-micro:15.6 AS micro
FROM registry.suse.com/bci/bci-base:15.6.47.5.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 python311-pip python-open-webui-pipelines sed awk curl git grep && \
    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.suse.org/Building_derived_containers
# labelprefix=com.suse.application.open-webui-pipelines
LABEL org.opencontainers.image.authors=""
LABEL org.opencontainers.image.title="Open WebUI Pipelines"
LABEL org.opencontainers.image.description="Pipelines bring modular, customizable workflows to any UI client supporting OpenAI API specs and much more! Easily extend functionalities, integrate unique logic, and create dynamic workflows with just a few lines of code."
LABEL org.opencontainers.image.version="%%open_webui_pipelines_version%%"
LABEL org.opencontainers.image.url="https://apps.rancher.io/applications/open-webui-pipelines"
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="%%open_webui_pipelines_version%%%BUILD_FLAVOR%-%RELEASE%"
LABEL org.opencontainers.image.base.digest="%BASE_IMAGE_DIGEST%"
LABEL org.opencontainers.image.base.name="%BASE_IMAGE_TAG%"
LABEL org.opensuse.reference="dp.apps.rancher.io/containers/open-webui-pipelines:%%open_webui_pipelines_version%%-%RELEASE%"
LABEL org.openbuildservice.disturl="%DISTURL%"
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 PORT=9099
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

WORKDIR /app

RUN cp -r /usr/lib/python3.11/site-packages/pipelines/* .
 
COPY start_openwebui_pipelines.sh ./start_openwebui_pipelines.sh
RUN chmod +x ./start_openwebui_pipelines.sh

# Expose the port
ENV HOST="0.0.0.0"
ENV PORT="9099"

ENTRYPOINT ["/app/start_openwebui_pipelines.sh"]

