## Deploy
FROM quay.io/fedora/fedora:latest

COPY build/containers/pcp/root /

RUN microdnf install -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs \
    gettext-envsubst pcp-zeroconf pcp-pmda-* pcp-import-* pcp-export-* && \
    microdnf clean all

# ensure pmcd and pmproxy ports are both accessible on startup
RUN sed -i 's/^PMPROXY_LOCAL=1/PMPROXY_LOCAL=0/g' /etc/sysconfig/pmproxy
RUN sed -i 's/^PMCD_LOCAL=1/PMCD_LOCAL=0/g' /etc/sysconfig/pmcd

## Setup
ENV NAME="pcp"
ENV VERSION="7"
ENV SUMMARY="Performance Co-Pilot"
ENV REGISTRY="ghcr.io/performancecopilot/"
ENV DESCRIPTION="Performance Co-Pilot is a system performance analysis toolkit."

LABEL RUN="podman run -d --name ${NAME} --systemd always -p 44321:44321 -p 44322:44322 -v pmlogger:/var/log/pcp/pmlogger -v pmproxy:/var/log/pcp/pmproxy ${REGISTRY}/${NAME}"

LABEL name="${NAME}"
LABEL version="${VERSION}"
LABEL summary="${SUMMARY}"
LABEL description="${DESCRIPTION}"
LABEL maintainer="PCP Team <pcp@groups.io>"
LABEL help="cat /README.md"
LABEL com.redhat.component="pcp"
LABEL io.k8s.display-name="${SUMMARY}"
LABEL io.k8s.description="${DESCRIPTION}"
LABEL io.openshift.expose-services="44321:pmcd,44322:pmproxy"
LABEL io.openshift.tags="pcp,performance,metrics,analysis,monitoring,observability"

RUN systemctl mask \
    console-getty.service dev-hugepages.mount getty.target \
    systemd-oomd.service systemd-resolved.service \
    systemd-logind.service systemd-machine-id-commit.service \
    systemd-random-seed.service systemd-remount-fs.service \
    systemd-udev-trigger.service systemd-udevd.service \
    systemd-udevd-control.socket systemd-udevd-kernel.socket \
    systemd-userdbd.service

VOLUME ["/var/log/pcp/pmlogger"]
VOLUME ["/var/log/pcp/pmproxy"]
EXPOSE 44321 44322

ENTRYPOINT ["/usr/bin/container-entrypoint"]
CMD ["/usr/sbin/init"]
STOPSIGNAL SIGRTMIN+3
