# Copyright (c) 2018-2021 Contributors to the Eclipse Foundation
# 
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
# 
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0
# 
# SPDX-License-Identifier: EPL-2.0
#

#Choose a base image that matches the type of build we are using...
# To use a different disto change the from EG:
# FROM quay.io/centos/centos:7
# FROM quay.io/almalinuxorg/almalinux:8
# FROM quay.io/almalinuxorg/almalinux:9
# FROM quay.io/almalinuxorg/almalinux:10
# For Fedora, the verion changes very often due to their short life
# FROM quay.io/fedora/fedora:43-x86_64
FROM quay.io/almalinuxorg/almalinux:9

WORKDIR /usr/share/amlen-bridge/bin

# Add RPM in a temporary directory inside the container
# Make sure that imabridge.rpm is available in the directory where "docker build" command
# is being executed
ADD ./imabridge.rpm /tmp/

# Update/install prereq packages 
RUN yum -y upgrade 

# For almalinux 8 and 9 libedit-devel comes from epel so we need to try to enable those
# The steps are essentially optional as not all distros will suport the commands
RUN yum -y install epel-release || true
RUN yum -y install dnf-plugins-core || true
RUN dnf config-manager --set-enabled powertools || true

# Hopefully we can now install all the required prereqs, this is not optional
RUN yum -y install gdb net-tools openssh-clients openssl tar perl zip logrotate bzip2 unzip cronie less libedit-devel

#To run as a non-root user
# 1) Create the user and group outside the container with a selected uid/gid
#        groupadd -r -g 465 imabridge
#        useradd -r  -s /sbin/nologin -g imabridge -u 465 imabridge
# 2) Give that user read/write access to any volumes that will be used
# 3) Create a config file so the RPM knows the user
#        RUN echo 'user=imabridge' >/etc/messagesight-bridge-user.cfg
# 4) Uncomment the RUN group/useradd setup lines:
#      (Ensure the numeric uid/gid below match step 1 above)
#        RUN groupadd -r -g 465 imabridge
#        RUN useradd -r  -s /sbin/nologin -g imabridge -u 465 imabridge
# 5) Uncomment the USER line before the entrypoint

# Install the Bridge itself
RUN yum -y install /tmp/imabridge.rpm

# Delete imabridge.rpm from temporary directory
RUN rm -f /tmp/imabridge.rpm

ENV LD_LIBRARY_PATH /usr/share/amlen-bridge/lib64:${LD_LIBRARY_PATH}
ENV PATH /usr/share/amlen-bridge/bin:${PATH}

#Uncomment below USER line to run as a non-root user (but do the above steps 1-4 as well!)
#USER imabridge:imabridge

#ENTRYPOINT "/bin/bash"
ENTRYPOINT [ "/usr/share/amlen-bridge/bin/startBridge.sh" ]



