FROM node:20-slim

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

RUN apt-get update && apt-get install -y \
    git \
    curl \
    sudo \
    openssh-client \
    && rm -rf /var/lib/apt/lists/*

RUN echo "node ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/node-sudo \
    && chmod 0440 /etc/sudoers.d/node-sudo

# Pre-create workspace and node_modules with node user permissions
RUN mkdir -p /workspace/node_modules && chown -R node:node /workspace

WORKDIR /workspace

USER node

ARG GIT_USER_NAME
ARG GIT_USER_EMAIL

RUN git config --global user.name "${GIT_USER_NAME}" && \
    git config --global user.email "${GIT_USER_EMAIL}"