# Set source Docker image
FROM centos:8

# Expose Web Admin and GDM ports
EXPOSE 5050 5070

# Arguments for packaging
ARG sentry_package

# Set environment variables
ENV container docker
ENV LANG=en_US.UTF-8

# Set default shell
SHELL ["/bin/bash", "-c"]

# Set default command for container execution
CMD ["/usr/sbin/init"]

# Update to CentOS Stream 8
RUN dnf -y --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
RUN dnf -y distro-sync

# Update OS packages and install desired tools
RUN dnf makecache
RUN dnf -y update
RUN dnf install -y wget net-tools psmisc initscripts traceroute
RUN dnf clean all

# Cleanup of running services
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; \
do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*; \
rm -f /etc/systemd/system/.wants/*; \
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*; \
rm -f /lib/systemd/system/anaconda.target.wants/*;

# Set system time to UTC, adjust if needed
RUN rm -f /etc/localtime
RUN cp /usr/share/zoneinfo/UTC /etc/localtime

# Download Sentry, install Sentry and cleanup install package
COPY ${sentry_package} /root
RUN chmod +x /root/${sentry_package}
RUN /root/${sentry_package} -i silent; exit 0
RUN rm /root/${sentry_package}

# Copy over Sentry runner script
COPY runSentry.sh /root
RUN chmod +x /root/runSentry.sh

# Run command that will start Sentry
ENTRYPOINT /root/runSentry.sh

