#syntax=docker/dockerfile:1.2

#================================================================
#
# DEV: Stage used for the development environment
#      and the locally built services
#
#=================================================================

FROM ubuntu:24.04 as dev
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG DOCKER_USER=acore
ARG TZ=Etc/UTC

LABEL description="AC base image for dev containers"

# List of timezones: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

ENV DOCKER=1

# Ensure ac-dev-server can properly pull versions
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1

# set timezone environment variable
ENV TZ=$TZ

# set noninteractive mode so tzdata doesn't ask to set timezone on install
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        # Classic install
        git \
        clang lldb lld clang-format clang-tidy \
        make cmake \
        gcc g++ \
        libmysqlclient-dev \
        libssl-dev \
        libbz2-dev \
        libreadline-dev \
        libncurses-dev \
        mysql-server \
        libboost-all-dev \
        # Other
        curl  \
        unzip  \
        sudo \
        gdb gdbserver \
        libtool \
        build-essential \
        cmake-data \
        openssl \
        google-perftools libgoogle-perftools-dev \
        libmysql++-dev \
        ccache \
        tzdata \
        # Utility for column command used by dashboard
        util-linux \
        # Certificates for downloading client data
        ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Ensure git will work with the AzerothCore source directory
RUN git config --global --add safe.directory /azerothcore

# change timezone in container
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata

# Create a non-root user
RUN userdel --remove ubuntu \
    && addgroup --gid "$GROUP_ID" "$DOCKER_USER" \
    && adduser --disabled-password --gecos '' --uid "$USER_ID" --gid "$GROUP_ID" "$DOCKER_USER" \
    && passwd -d "$DOCKER_USER" \
    && echo "$DOCKER_USER ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers

# must be created to set the correct permissions on them
RUN mkdir -p \
    /azerothcore/env/dist/bin \
    /azerothcore/env/dist/data/Cameras \
    /azerothcore/env/dist/data/dbc \
    /azerothcore/env/dist/data/maps \
    /azerothcore/env/dist/data/mmaps \
    /azerothcore/env/dist/data/vmaps \
    /azerothcore/env/dist/logs \
    /azerothcore/env/dist/temp \
    /azerothcore/env/dist/etc \
    /azerothcore/var/build/obj

# Correct permissions for non-root operations
RUN chown -R $DOCKER_USER:$DOCKER_USER /home/acore /run /opt /azerothcore

USER $DOCKER_USER

# copy only necessary files for the acore dashboard
COPY --chown=$DOCKER_USER:$DOCKER_USER apps /azerothcore/apps
COPY --chown=$DOCKER_USER:$DOCKER_USER bin /azerothcore/bin
COPY --chown=$DOCKER_USER:$DOCKER_USER conf /azerothcore/conf
COPY --chown=$DOCKER_USER:$DOCKER_USER data /azerothcore/data
COPY --chown=$DOCKER_USER:$DOCKER_USER deps /azerothcore/deps
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.json /azerothcore/acore.json
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.sh /azerothcore/acore.sh

# Download deno and make sure the dashboard works
RUN bash /azerothcore/acore.sh quit

WORKDIR /azerothcore