ARG REGISTRY=
ARG TAG=:latest
FROM ${REGISTRY}simbricks/simbricks${TAG} as builder
FROM ${REGISTRY}simbricks/simbricks-runenv${TAG}
# Add non-root user for vs code devcontainer.
ARG USERNAME=simbricks
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
 && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/bash \
# Add sudo support for this user and remove the need to type in password.
 && apt-get update \
 && apt-get install -y sudo \
 && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
 && chmod 0440 /etc/sudoers.d/$USERNAME
COPY --chown=${USERNAME}:${USERNAME} --from=builder /simbricks /simbricks
WORKDIR /simbricks
ENV PYTHONPATH=/simbricks/experiments
RUN sudo cp docker/simbricks-run /usr/bin/ \
 && sudo chmod 755 /usr/bin/simbricks-run \
 && sudo ln -s /simbricks/sims/external/qemu/build/qemu-system-x86_64 \
    /usr/bin/qemu-system-x86_64 \
 && sudo ln -s /simbricks/sims/external/qemu/build/qemu-system-x86_64 \
    /usr/bin/kvm \
 && sudo ln -s /simbricks/sims/external/qemu/build/qemu-img \
    /usr/bin/qemu-img
