FROM rust:1-slim-buster
WORKDIR .

ENV GIT_REPO https://github.com/marcua/ayb
ENV CHECKOUT main

RUN apt update
RUN apt install -y \
    build-essential \
    libssl-dev \
    openssl \
    autoconf \
    bison \
    flex \
    gcc \
    g++ \
    git \
    libprotobuf-dev \
    libnl-route-3-dev \
    libtool \
    make \
    pkg-config \
    protobuf-compiler

RUN git clone $GIT_REPO

# Build nsjail
RUN git clone https://github.com/google/nsjail
RUN cd ./nsjail && make && mv nsjail ../ayb

WORKDIR ./ayb
COPY . .

RUN git fetch --tags
RUN git checkout -f $CHECKOUT

RUN cargo build --release

RUN cargo build --release
EXPOSE 5433
CMD ["./target/release/ayb", "server"]