FROM ubuntu:24.04

ARG OPENTRACING_CPP_VERSION=v1.6.0
ARG NGINX_VERSION

RUN set -x \
  && apt-get update \
  && DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends --no-install-suggests -y \
  build-essential \
  ca-certificates \
  cmake \
  curl \
  gettext \
  git \
  gnupg2 \
  jq \
  libpcre2-dev \
  libssl-dev \
  python3 \
  software-properties-common \
  wget \
  zlib1g-dev \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

### Build opentracing-cpp
RUN cd / \
  && git clone --depth 1 -b $OPENTRACING_CPP_VERSION https://github.com/opentracing/opentracing-cpp.git \
  && cd opentracing-cpp \
  && mkdir .build && cd .build \
  && cmake -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_TESTING=OFF .. \
  && make && make install

COPY ./opentracing /opentracing

### Build nginx
RUN cd / \
  && wget -O nginx-release-${NGINX_VERSION}.tar.gz https://github.com/nginx/nginx/archive/release-${NGINX_VERSION}.tar.gz \
  && tar zxf nginx-release-${NGINX_VERSION}.tar.gz \
  && cd /nginx-release-${NGINX_VERSION} \
  # Temporarily disable leak sanitizer to get around false positives in build
  && export ASAN_OPTIONS=detect_leaks=0 \
  && export CFLAGS="-Wno-error" \
  && auto/configure \
  --with-http_auth_request_module \
  --with-compat \
  --with-debug \
  # enables grpc
  --with-http_v2_module \
  --add-dynamic-module=/opentracing \
  && make && make install

CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
