FROM ubuntu:24.04

LABEL maintainer="jahus"
LABEL description="Up-to-date MTProxy for Telegram"
LABEL version="1.0.0"

RUN apt-get update && \
    apt-get install -y \
    git \
    curl \
    build-essential \
    libssl-dev \
    zlib1g-dev \
    xxd \
    cron && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /opt
RUN git clone https://github.com/TelegramMessenger/MTProxy && \
    cd MTProxy && \
    make && \
    cp objs/bin/mtproto-proxy /usr/local/bin/ && \
    cd .. && \
    rm -rf MTProxy

WORKDIR /data

COPY update-config.sh /usr/local/bin/
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/update-config.sh /usr/local/bin/entrypoint.sh

EXPOSE 443 8888

COPY healthcheck.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/healthcheck.sh

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD /usr/local/bin/healthcheck.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

