# Base image
FROM docker.ubs-hainer.com/xdm3-ui:latest

ENV http_port 8080
ENV https_port 8443

ARG UID=1000
ARG GID=1000

RUN addgroup -g ${GID} xdm &&\
    adduser -S -s /bin/bash -G xdm -h /home/xdm -u ${UID} xdm &&\
    chown ${UID}:${GID} /etc/nginx/conf.d/default.tmpl &&\
    chown ${UID}:${GID} /etc/nginx/nginx.conf &&\
    chmod 766 /etc/nginx/nginx.conf &&\
    chown -R ${UID}:${GID} /usr/share/nginx/html/ &&\
    mkdir -p /var/tmp/nginx/ &&\
    chown -R ${UID}:${GID} /var/tmp/nginx/ &&\
    mkdir -p /var/log/nginx/ &&\
    chown -R ${UID}:${GID} /var/log/nginx/ &&\
    chown -R ${UID}:${GID} /run/nginx/ &&\
    chown -R ${UID}:${GID} /var/lib/nginx &&\
    chown ${UID}:${GID} /xdm/certificates/xdm.key &&\
    chown ${UID}:${GID} /xdm/certificates/xdm.key &&\
    chown -R ${UID}:${GID} /etc/nginx &&\
    chmod -R 755 /var/lib/nginx/ &&\
    sed -i '1d' /etc/nginx/nginx.conf

# Run image as xdm user
USER xdm


