# SPDX-License-Identifier: MIT
#!UseOBSRepositories
#!ExclusiveArch: aarch64 x86_64
#!BuildTag: containers/open-webui-mcpo:%%open_webui_mcpo_version%%%BUILD_FLAVOR%-%RELEASE%
#!BuildTag: containers/open-webui-mcpo:%%open_webui_mcpo_version%%%BUILD_FLAVOR%
#!BuildTag: containers/open-webui-mcpo:0%BUILD_FLAVOR%
#!ForceMultiVersion
#!BuildName: containers-open-webui-mcpo-0%BUILD_FLAVOR%
#!BuildVersion: %%open_webui_mcpo_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 bash python311-open-webui-mcpo python311-uv git-core curl ca-certificates npm22 nodejs22 && \
    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.open-webui-mcpo
LABEL org.opencontainers.image.title="Open WebUI mcpo"
LABEL org.opencontainers.image.description="A simple, secure MCP-to-OpenAPI proxy server."
LABEL org.opencontainers.image.version="%%open_webui_mcpo_version%%"
LABEL org.opencontainers.image.url="https://apps.rancher.io/applications/open-webui-mcpo"
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_mcpo_version%%%BUILD_FLAVOR%-%RELEASE%"
LABEL org.opensuse.reference="dp.apps.rancher.io/containers/open-webui-mcpo:%%open_webui_mcpo_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.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

# Verify mcpo installed correctly
RUN which mcpo

# Confirm npm and node versions (optional debugging info)
RUN node -v && npm -v

# Copy your mcpo source code (assuming in src/mcpo)
WORKDIR /app

# Create virtual environment explicitly in known location
ENV VIRTUAL_ENV=/app/.venv
RUN uv venv "$VIRTUAL_ENV"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Expose port (optional but common default)
EXPOSE 8000

# Entrypoint set for easy container invocation
ENTRYPOINT ["mcpo"]

# Default help CMD (can override at runtime)
CMD ["--help"]
