FROM ubuntu:20.04

LABEL org.opencontainers.image.title="Sigfox Network Emulator (SNEK)"
LABEL org.opencontainers.image.description="SNEK 2.3.4 pre-installed with all dependencies for Sigfox SDR dongle"

ARG DEBIAN_FRONTEND=noninteractive
ARG SNEK_URL=https://support.sigfox.com/files/5e6202fa7d734d7f7f84a08e

# System dependencies (GTK stack + SNEK runtime deps)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        curl \
        wget \
        ca-certificates \
        usbutils \
        libgtk2-perl \
        zenity \
        python \
        libdbus-glib-1-2 \
    && rm -rf /var/lib/apt/lists/*

# libffi6 is not in Ubuntu 20.04 by default (SNEK is built against Ubuntu 18.04 ABI)
RUN cd /tmp && \
    wget -q http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb && \
    dpkg -i libffi6_3.2.1-8_amd64.deb && \
    rm libffi6_3.2.1-8_amd64.deb

# Download and install SNEK
RUN curl -Ls "${SNEK_URL}" -o /tmp/snek.deb && \
    dpkg -i /tmp/snek.deb || apt-get install -f -y && \
    rm /tmp/snek.deb && \
    rm -rf /var/lib/apt/lists/*

# Entrypoint: flash firmware then start SNEK server
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV LD_LIBRARY_PATH=/opt/snek
ENV GI_TYPELIB_PATH=/opt/snek

WORKDIR /opt/snek

EXPOSE 8085

ENTRYPOINT ["/entrypoint.sh"]
