# Lightweight Python image with mender-cli pre-installed
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    && rm -rf /var/lib/apt/lists/*

# Add Mender official GPG key and APT repository
RUN curl -fsSL https://downloads.mender.io/repos/debian/gpg | tee /etc/apt/trusted.gpg.d/mender.asc > /dev/null \
    && echo "deb [arch=$(dpkg --print-architecture)] https://downloads.mender.io/repos/workstation-tools ubuntu/jammy/stable main" \
    | tee /etc/apt/sources.list.d/mender.list

# Install mender-cli from official repository
RUN apt-get update && \
    apt-get install -y mender-cli && \
    rm -rf /var/lib/apt/lists/*

# Verify mender-cli installation
RUN mender-cli --version

# Copy the utility script
COPY tcli.py /app/

# Make the script executable
RUN chmod +x /app/tcli.py

# Create mount points for configuration files
RUN mkdir -p /config

# Set environment variable for config directory
ENV CONFIG_DIR=/config

# Expose common service ports that might be forwarded
# These are the local ports from services.conf
EXPOSE 2884 8080 8443 2222 5901 9229

# Default command shows help
ENTRYPOINT ["python3", "/app/tcli.py"]
CMD ["--help"]
