ARG NETBOX_VARIANT=v4.5.3-4.0.1

FROM ghcr.io/netbox-community/netbox:${NETBOX_VARIANT}

VOLUME [ "/etc/netbox/scripts" ]

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-dev sudo fish npm postgresql-client \
    && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

RUN curl -L -o /usr/local/bin/hadolint https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 \
    && chmod +x /usr/local/bin/hadolint

# Install GitHub CLI (gh)
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
    && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
    && apt-get update \
    && apt-get install -y gh \
    && apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Copy the entrypoint script
COPY .devcontainer/entrypoint-dev.sh /bin/entrypoint-dev.sh
RUN chmod +x /bin/entrypoint-dev.sh

ARG USERNAME=ubuntu
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN chsh -s /usr/bin/fish $USERNAME; \
    chown -R $USER_UID:$USER_GID /home/ubuntu; \
    chown -R $USER_UID:$USER_GID /etc/netbox/scripts; \
    usermod -aG sudo $USERNAME \
    && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/nopasswd

# Copy the plugin code
COPY . /opt/netbox-facts

RUN chown $USERNAME:$USERNAME /opt/netbox-facts /opt/netbox /etc/netbox -R

USER ${USERNAME}

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Add ohmyfish
RUN curl "https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install" > /tmp/install_omf && fish /tmp/install_omf --noninteractive && rm /tmp/install_omf && fish -c "omf install bobthefish"

# Add Claude Code to the devcontainer
RUN mkdir -p ~/.npm && npm config set prefix ~/.npm && npm install -g @anthropic-ai/claude-code

# Install plugin with dev dependencies + optional peer plugins
RUN uv pip install --no-cache-dir -e "/opt/netbox-facts[dev]" netbox-routing

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