FROM rust:1.59.0-buster

ENV PROJECT_PATH=/chirpstack
ENV CARGO_TARGET_DIR=/target

RUN mkdir -p $PROJECT_PATH
RUN mkdir -p $CARGO_TARGET_DIR

RUN apt-get update && \
        apt-get install -y \
		make \
		cmake \
		git \
		bash \
		screen \
		postgresql-client \
		libpq-dev \
		mosquitto-clients \
		redis-tools \
		rpm \
		clang \
		yarnpkg \
		golang-cfssl \
		&& rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/yarnpkg /usr/bin/yarn

RUN rustup component add rustfmt clippy

RUN cargo install diesel_cli --no-default-features --features postgres
RUN cargo install cargo-deb
RUN cargo install cargo-rpm

COPY . $PROJECT_PATH

WORKDIR $PROJECT_PATH/chirpstack
RUN cargo build --release
RUN rm -rf $PROJECT_PATH/*
