FROM codercom/enterprise-base:ubuntu

# Run everything as root
USER root

# Set environment variables 
ENV RUSTUP_HOME=/opt/rustup
ENV CARGO_HOME=/opt/cargo
ENV PATH=/opt/cargo/bin:$PATH

# Install Rust
COPY rustup.sh /tmp/rustup.sh
RUN /tmp/rustup.sh -y \
                   --no-modify-path \
                   --profile minimal \
                   --default-toolchain stable \
                   --default-host x86_64-unknown-linux-gnu && \
    rm -f /tmp/rustup.sh && \
    chmod -R a+w ${RUSTUP_HOME} ${CARGO_HOME}

# Validate that cargo and rustc are available
RUN cargo --version && rustc --version

COPY deprecated.txt /etc/motd
RUN echo '[ ! -z "$TERM" ] && cat /etc/motd' >> /etc/bash.bashrc

# Set back to coder user
USER coder
