# Use Debian as base image
FROM debian:latest

# Install necessary build tools
RUN apt-get update && \
    apt-get install -y sudo build-essential cmake git libjson-c-dev libwebsockets-dev zlib1g-dev curl

# Install Rust and Cargo
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
    export PATH="$HOME/.cargo/bin:$PATH" && \
    rustup default stable


# Clone and build ttyd
RUN git clone https://github.com/tsl0922/ttyd.git && \
    cd ttyd && \
    mkdir build && \
    cd build && \
    cmake .. && \
    make && \
    make install

# Clone AdGuardian-Term and build
RUN git clone https://github.com/Lissy93/AdGuardian-Term.git && \
    cd AdGuardian-Term && \
    $HOME/.cargo/bin/cargo build --release && \
    mv ./target/release/adguardian /usr/local/bin/adguardian

# Expose port 7681
EXPOSE 7681

ENV ADGUARD_IP={define your adguard ip here}
ENV ADGUARD_PORT={define the adguard port here, most likely 80}
ENV ADGUARD_USERNAME={add you username of adguard here}
ENV ADGUARD_PASSWORD={add your adguard password here}

# Set the start command
CMD ["ttyd", "-W","-c", "${ADGUARD_USERNAME}:${ADGUARD_PASSWORD}", "/usr/local/bin/adguardian"]
