# CCS5 Dockerfile
#
# Copyright 2024 Terma BV
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
# “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# the Dockerfile takes a RedHat UBI container image, and adds Terma CCS5

FROM registry.access.redhat.com/ubi9/ubi
ARG VERSION

# Update system and install packages
RUN dnf -y update && \
    dnf upgrade -y

# RedHat Universal Base Image (also included in the container, see below)
# https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf
ADD EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf .

# additional packages with specific FOSS licenses reproduced here

# MESA (see https://docs.mesa3d.org/license.html)
# Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

RUN dnf install -y mesa-libGL 

# fontconfig (see https://gitlab.freedesktop.org/fontconfig/fontconfig/-/blob/main/COPYING)
# 
# Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
# Copyright © 2005 Patrick Lam
# Copyright © 2007 Dwayne Bailey and Translate.org.za
# Copyright © 2009 Roozbeh Pournader
# Copyright © 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Red Hat, Inc.
# Copyright © 2008 Danilo Šegan
# Copyright © 2012 Google, Inc.
# 
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of the author(s) not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission.  The authors make no
# representations about the suitability of this software for any purpose.  It
# is provided "as is" without express or implied warranty.
# 
# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# 
# fontconfig/fc-case/CaseFolding.txt
# 
# © 2019 Unicode®, Inc.
# Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.
# For terms of use, see http://www.unicode.org/terms_of_use.html

RUN dnf install -y fontconfig 

# MariaDB Connector C (see https://mariadb.com/kb/en/mariadb-connector-c/)
# 
# GNU LESSER GENERAL PUBLIC LICENSE
# https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
#
# NO WARRANTY
#
# 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
# EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF 
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE,
# YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
# 
# 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
# MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL
# OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
# BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
# EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

RUN dnf install -y mariadb-connector-c.x86_64 

# PostgreSQL (see https://www.postgresql.org/about/licence/)
#
# PostgreSQL Database Management System
# (formerly known as Postgres, then as Postgres95)
# 
# Portions Copyright © 1996-2024, The PostgreSQL Global Development Group
# 
# Portions Copyright © 1994, The Regents of the University of California
# 
# Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a 
# written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs
# appear in all copies.
# 
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
# DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
# HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

RUN dnf install -y postgresql postgresql-libs

# Create 'tsc' group and user
RUN groupadd -g 1000 tsc && \
    useradd -u 1000 -g 1000 -m -d /home/tsc -s /bin/bash tsc && \
    chown -R tsc:tsc /home/tsc

# Setup the application directory structure
RUN mkdir -p /opt/CCS && \
    mkdir -p /CCS/VARIABLE/RESULTS

#
# add the relevant Terma application
# 
ADD CCS-${VERSION}-x86_64-Linux.rpm .
RUN rpm -i CCS-${VERSION}-x86_64-Linux.rpm && \
    rm CCS-${VERSION}-x86_64-Linux.rpm && \
    ln -s /usr/lib64/libmariadb.so.3 /usr/lib64/libmysqlclient.so.18 && \
    ln -s /usr/lib64/libmariadb.so.3 /usr/lib64/libmysqlclient.so.15 && \
    chown -R tsc:tsc /CCS/VARIABLE/RESULTS

# Remove NATS from the container since we use external NATS container
RUN rm /opt/CCS/bin/nats*

# perform any security-justified removals below, where applicable, include CVE identifier

# end of security-justified removals

# Environment variables
ENV CCS_INSTALL=/opt/CCS \
    SYN_INSTALL=/opt/CCS

# Set umask
RUN umask 0002

# Switch to 'tsc' user
USER tsc

# Expose port for VNC
EXPOSE 5900

# Default command
CMD ["/opt/CCS/bin/SynTestConsole", "-platform", "vnc:size=1920x1080"]
