# --------------------------------------------------------------------------------
# Docker container for Maya as per below guide
# https://help.autodesk.com/view/MAYAUL/2026/ENU/?guid=GUID-D2B5433C-E0D2-421B-9BD8-24FED217FD7F
#
# How to run (dev/test only)
#   docker build --progress=plain -t p4render-maya .
#   (Optional) --platform=linux/amd64
#
#   docker run -ti -v $(pwd)/../volumes/shared:/home/perforce/p4render/files p4render-maya
#   (Optional) --platform=linux/amd64
# --------------------------------------------------------------------------------

# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=maya
# https://aur.archlinux.org/packages/maya
# https://www.autodesk.com/company/terms-of-use/en/general-terms
# https://github.com/mottosso/docker-maya

FROM rockylinux:9.3

LABEL vendor="Perforce Software"
LABEL maintainer="Support (support@perforce.com)"

WORKDIR /opt/perforce/p4render-maya

ARG UID=1001
ENV UID=$UID

# perforce user setup
RUN groupadd -g $UID perforce
RUN useradd -s /bin/bash -d /home/perforce -u $UID -g perforce -m perforce
RUN chown -R perforce:perforce /opt/perforce/p4render-maya
RUN mkdir -p /home/perforce/p4render-maya/files
RUN chown -R perforce:perforce /home/perforce/p4render-maya/files

RUN yum -y install \
    epel-release \
    gtk2 \
    alsa-lib \
    libEGL.so.1 \
    libffi \
    libglvnd-opengl \
    libmng \
    libpng15 \
    libpq \
    libsmime3.so \
    libva \
    libvdpau \
    libXp \
    libXmu \
    libxkbcommon \
    libXpm \
    libXtst \
    libxkbfile \
    libpython3.11.so.1.0 \
    mesa-libGLU \
    pcre2-utf32 \
    xcb-util \
    xcb-util-cursor \
    xcb-util-image \
    xcb-util-keysyms \
    xcb-util-renderutil \
    xcb-util-wm \
    xorg-x11-fonts-ISO8859-1-100dpi \
    xorg-x11-fonts-ISO8859-1-75dpi \
    && yum clean all

# Refresh symlinks
RUN ldconfig
# Run in headless mode
ENV DISPLAY=:99

# Download and unpack distribution first, Docker's caching
# mechanism will ensure that this only happens once.
COPY files/maya/Autodesk_Maya_20* maya.tgz
RUN mkdir /maya \
    && tar -xvf maya.tgz -C /maya \
    && rpm -Uvh /maya/Packages/Maya20*.rpm \
    && rm -fr /maya /usr/autodesk/maya/Examples

# For Maya to Arnold capabilities run this
#RUN /maya/Packages/unix_installer.sh

# Copy sources
COPY files/src /opt/perforce/p4render-maya
RUN chown -R perforce:perforce /opt/perforce/p4render-maya \
  && chmod +x /opt/perforce/p4render-maya/p4render-maya.py

# Setup environment
ENV MAYA_LOCATION=/usr/autodesk/maya/
ENV PATH=$MAYA_LOCATION/bin:$PATH
ENV MAYA_PLUG_IN_PATH=$MAYA_LOCATION/plug-ins:$MAYA_LOCATION/bin/plug-ins

# Avoid warning about this variable not set, the path is its default value
RUN mkdir /var/tmp/runtime-root && \
    chmod 0700 /var/tmp/runtime-root
ENV XDG_RUNTIME_DIR=/var/tmp/runtime-root

# Workaround for "Segmentation fault (core dumped)"
# See https://forums.autodesk.com/t5/maya-general/render-crash-on-linux/m-p/5608552/highlight/true
# Disable the Customer Involvement Program, which sends crash reports and other diagnostic data to Autodesk.
ENV MAYA_DISABLE_CIP=1

USER perforce
