
# Use: docker build . --network=host --pull -t darkfi:ubuntu -f ./contrib/docker/Dockerfile.ubuntu
#   optionally with: --build-arg BUILD_OS_VER=20.04 --build-arg RUST_VER=1.65

ARG RUST_VER=1.67       # stable nightly beta
ARG BUILD_OS_VER=22.04  # 20.04
ARG RUN_OS_VER=${BUILD_OS_VER}
ARG REPOSITORY=ubuntu

FROM ${REPOSITORY}:${BUILD_OS_VER} as rust_builder

ARG RUST_VER

RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y \
  build-essential cmake jq wget curl \
  pkg-config clang libclang-dev llvm-dev libudev-dev libfreetype6-dev \
  libexpat1-dev curl gcc make libssl-dev fonts-lato libfontconfig-dev

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain "${RUST_VER}"

ENV PATH="/root/.cargo/bin:${PATH}"

RUN rustup target add wasm32-unknown-unknown

RUN cargo search whatever  # creates .cargo cache

# 2. stage
FROM rust_builder as builder

WORKDIR /opt/darkfi

COPY . /opt/darkfi

RUN make clean

RUN rm -rf ./target/*

RUN bash -c 'make -j test &&  make -j all'

# 3. stage
FROM ${REPOSITORY}:${RUN_OS_VER}

RUN apt-get -y update && apt-get install -y openssl fonts-lato \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/darkfi

COPY --from=builder /opt/darkfi/drk /opt/darkfi/darkfid  \
   /opt/darkfi/ircd /opt/darkfi/dnetview /opt/darkfi/faucetd \
   /opt/darkfi/zkas /opt/darkfi/vanityaddr  ./

