#--------------------------------------------------------------------------#
# Copyright (C) 2022 by Tibit Communications, Inc.                         #
# All rights reserved.                                                     #
#                                                                          #
#    _______ ____  _ ______                                                #
#   /_  __(_) __ )(_)_  __/                                                #
#    / / / / __  / / / /                                                   #
#   / / / / /_/ / / / /                                                    #
#  /_/ /_/_____/_/ /_/                                                     #
#                                                                          #
#  Distributed as Tibit-Customer confidential.                             #
#                                                                          #
#--------------------------------------------------------------------------#
FROM ubuntu:20.04

#
# Build commands
#

# Run the debian package manager in non-interactive mode
ARG DEBIAN_FRONTEND=noninteractive

# Prepare the base image
RUN apt-get update -y
RUN apt-get upgrade -y

# Install debug utilities
RUN apt-get install apt-utils -y
RUN apt-get install net-tools -y
RUN apt-get install iputils-ping -y
RUN apt-get install iproute2 -y

# Install the Tibit Netconf binary package
RUN mkdir -p /tmp
WORKDIR /tmp
COPY tibit-netconf_R3.2.0_amd64.deb /tmp
RUN cd /tmp && apt-get install ./tibit-netconf_R3.2.0_amd64.deb -y

# Create a Linux 'tibit' user for accessing the Tibit Netconf server
RUN useradd -ms /bin/bash tibit
RUN echo "tibit:tibit" | chpasswd

# Add the 'tibit' user to the Netconf SSH Server authorized users configuration
RUN /opt/tibit/netconf/bin/netconf-users --add -u tibit

# Enable NACM and add the 'tibit' user NACM 'admin' group
RUN /opt/tibit/netconf/examples/nacm/nacm-config.sh /opt/tibit/netconf/examples/nacm/nacm-example.xml
RUN /opt/tibit/netconf/bin/netconf-users --add -u tibit -g admin

# Install supervisord
RUN apt-get install -y supervisor
COPY docker/supervisord.conf /etc/supervisor/supervisord.conf

#
# Runtime commands
#

# Use supervisord to run Netopeer2 + Tibit Database Connector
CMD /usr/bin/supervisord -c /etc/supervisor/supervisord.conf

#CMD bash
