ARG NETBOX_VARIANT=v3.4

FROM netboxcommunity/netbox:${NETBOX_VARIANT}

ARG NETBOX_INITIALIZERS_VARIANT=3.4.*

ARG DEBIAN_FRONTEND=noninteractive

# Install APT packages
# hadolint ignore=DL3008
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends  curl git make openssh-client python3.10-dev sudo wget zsh \
    && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install development & ide dependencies
COPY requirements-dev.txt /tmp/pip-tmp/
RUN /opt/netbox/venv/bin/python3 -m pip install --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements-dev.txt \
   && rm -rf /tmp/*

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN useradd -l -md /home/vscode -s /usr/bin/zsh -u $USER_UID $USERNAME \
    && usermod -aG sudo $USERNAME \
    && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
    && mkdir /opt/netbox/netbox/netbox-acls \
    && chown $USERNAME:$USERNAME /opt/netbox /etc/netbox /opt/unit -R

USER $USERNAME

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Add oh my zsh
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true

COPY .bashrc /home/vscode/.bashrc
COPY .zshrc /home/vscode/.zshrc

RUN /opt/netbox/venv/bin/pip install  --no-warn-script-location netbox-initializers==${NETBOX_INITIALIZERS_VARIANT}

WORKDIR /opt/netbox/netbox/netbox-acls

# hadolint ignore=DL3002
USER root

COPY entrypoint-dev.sh /bin/entrypoint-dev.sh
RUN chmod +x /bin/entrypoint-dev.sh

CMD ["/bin/entrypoint-dev.sh"]
