#Build image
FROM ubuntu:18.04 as build-step

RUN apt-get -y update
RUN apt-get -y install curl autoconf automake libbz2-dev libace-dev libssl-dev libmysqlclient-dev libtool build-essential gpg wget

RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null && \
    echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null && \
    apt-get update
RUN apt-get -y install cmake

COPY . /mangoserver
RUN mkdir /mangoserver/build
WORKDIR /mangoserver/build

#Install mangos
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/mangos -DBUILD_MANGOSD=1 -DBUILD_REALMD=0 -DBUILD_TOOLS=0
RUN make -j4
RUN make install

#Runtime image
FROM ubuntu:18.04 as runtime

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get -y install libmysqlclient20 openssl

COPY --from=build-step /mangos /mangos
WORKDIR /mangos/bin
RUN cp ../etc/mangosd.conf.dist ../etc/mangosd.conf
RUN chmod +x mangosd

EXPOSE 8085
ENTRYPOINT [ "./mangosd" ]
