# The image an agent runs in under NVIDIA OpenShell (CONTRACT.md §16a):
# openSUSE Leap 16 with agent-launcher. Its configuration and the relay's
# secret come in the sandbox's environment (agent-admin), its state lives
# in the sandbox's working directory.
#
#   make build
#   podman build -t localhost/custos-agent:latest -f packaging/openshell/Containerfile .
FROM registry.opensuse.org/opensuse/leap:16.0
# OpenShell runs the workload as the image's user "sandbox" (the sandbox
# policy's run_as_user), whose home is the working directory.
# The image's codec repository (codecs.opensuse.org) is outside openSUSE's
# mirrors and not needed: while it was unreachable, zypper exited 106
# (repositories skipped) and the build failed.
RUN (zypper -n mr -d repo-openh264 >/dev/null 2>&1 || true) && \
    zypper -n in --no-recommends ca-certificates shadow && \
    useradd -r -U -m -d /sandbox -s /usr/sbin/nologin sandbox && \
    zypper -n rm -u shadow && zypper -n clean -a
# Names through the sandbox's DNS (OpenShell's policy DNS) first, its
# /etc/hosts only after (#131): Podman copies the host's /etc/hosts into
# the sandbox, and a name there (often the host's own, the gateway's) would
# give the agent the real address, which OpenShell's network fence refuses.
# The launcher (static Go) reads /etc/nsswitch.conf; without it, files first.
RUN { [ -e /etc/nsswitch.conf ] || cp /usr/etc/nsswitch.conf /etc/nsswitch.conf 2>/dev/null || \
      printf 'passwd: files\ngroup: files\nshadow: files\n' >/etc/nsswitch.conf; } && \
    sed -i '/^hosts:/d' /etc/nsswitch.conf && echo 'hosts: dns files' >>/etc/nsswitch.conf
COPY bin/agent-launcher /usr/libexec/custos/agent-launcher
LABEL org.opencontainers.image.title="Custos agent" \
      org.opencontainers.image.source="https://github.com/sdrahn/custos"
