FROM registry.ci.openshift.org/ocp/builder:rhel-8-base-openshift-4.6

ARG PKGS_LIST=main-packages-list.txt

COPY ${PKGS_LIST} /tmp/main-packages-list.txt

RUN dnf upgrade -y && \
    xargs -rtd'\n' dnf --setopt=install_weak_deps=False install -y < /tmp/main-packages-list.txt && \
    mkdir -p /var/lib/ironic-inspector && \
    sqlite3 /var/lib/ironic-inspector/ironic-inspector.db "pragma journal_mode=wal" && \
    dnf remove -y sqlite && \
    dnf clean all && \
    rm -rf /var/cache/{yum,dnf}/*

COPY ./inspector.conf /tmp/inspector.conf
RUN crudini --merge /etc/ironic-inspector/inspector.conf < /tmp/inspector.conf && \
    rm /tmp/inspector.conf

RUN ironic-inspector-dbsync --config-file /etc/ironic-inspector/inspector.conf upgrade 

COPY ./runironic-inspector.sh /bin/runironic-inspector
COPY ./runhealthcheck.sh /bin/runhealthcheck
COPY ./ironic-common.sh /bin/ironic-common.sh

HEALTHCHECK CMD /bin/runhealthcheck
RUN chmod +x /bin/runironic-inspector

ENTRYPOINT ["/bin/runironic-inspector"]
