# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM otel/cpp_format_tools

ARG USER_UID=1000
ARG USER_GID=1000
ARG INSTALL_PACKAGES=

ARG CXX_STANDARD=17
ARG THIRD_PARTY_BUILD_TYPE=Release

ENV CXX_STANDARD=${CXX_STANDARD}
ENV THIRD_PARTY_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}

COPY ci /opt/ci

RUN apt update && apt install -y wget gnupg lsb-release software-properties-common && \
    wget -qO- https://apt.llvm.org/llvm.sh | bash -s -- 22 && \
    apt install -y \
    ninja-build \
    llvm-22-dev \
    libclang-22-dev \
    clang-22 \
    clang-tidy-22 \
    shellcheck \
    sudo \
    cmake

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-22 200 && \
    update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-22 200 && \
    update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-22 200 && \
    update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-22 200 && \
    update-alternatives --config clang && \
    update-alternatives --config clang++ && \
    update-alternatives --config clang-tidy && \
    update-alternatives --config llvm-config

RUN cd /opt/ci && bash setup_ci_environment.sh
RUN cd /opt/ci && bash install_iwyu.sh
RUN cd /opt/ci && bash install_bazelisk.sh
RUN git config --global core.autocrlf input

ENV INSTALL_PACKAGES=${INSTALL_PACKAGES}
ENV USER_NAME=devuser
ENV USER_UID=${USER_UID}
ENV USER_GID=${USER_GID}
ENV IS_CONTAINER_BUILD=true

COPY install /opt/install
COPY third_party_release /opt/third_party_release
COPY ./.devcontainer/customize_container.sh /tmp/opentelemetry_cpp/devcontainer/customize_container.sh
RUN /tmp/opentelemetry_cpp/devcontainer/customize_container.sh
RUN apt install -y npm && npm install -g markdownlint-cli@0.44.0

USER devuser

WORKDIR  /workspaces/opentelemetry-cpp
RUN cd /opt && bash ci/install_thirdparty.sh --install-dir /home/devuser/third-party/install --build-type ${THIRD_PARTY_BUILD_TYPE} --tags-file third_party_release
ENV CMAKE_PREFIX_PATH=/home/devuser/third-party/install

ENTRYPOINT []

CMD ["/bin/bash"]
