# Minimal Fedora Dockerfile
#
# Author: Steffen Vogel <post@steffenvogel.de>
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0

ARG DISTRO=fedora
ARG FEDORA_VERSION=36

FROM ${DISTRO}:${FEDORA_VERSION} AS dev

# Toolchain
RUN dnf -y install \
	gcc gcc-c++ \
	pkgconfig \
	cmake make \
	git rpm-build

# Dependencies
RUN dnf -y install \
	openssl-devel \
	libuuid-devel \
	libcurl-devel \
	jansson-devel \
	spdlog-devel \
	fmt-devel \
	libwebsockets-devel

ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

FROM dev AS builder

ARG CMAKE_OPTS

COPY . /villas/

RUN rm -rf /villas/build && mkdir /villas/build
WORKDIR /villas/build

RUN cmake ${CMAKE_OPTS} -DCPACK_GENERATOR=RPM .. && \
	make -j$(nproc) package

FROM ${DISTRO}:${FEDORA_VERSION} as app

COPY --from=builder /villas/build/*.rpm /tmp/
RUN dnf -y install /tmp/*.rpm

# Test if it runs
RUN villas node -h 2&>1 > /dev/null

# For WebSocket / API access
EXPOSE 80
EXPOSE 443

ENTRYPOINT ["villas"]

LABEL \
	org.label-schema.schema-version="1.0" \
	org.label-schema.name="VILLASnode" \
	org.label-schema.license="Apache-2.0" \
	org.label-schema.vendor="Institute for Automation of Complex Power Systems, RWTH Aachen University" \
	org.label-schema.author.name="Steffen Vogel" \
	org.label-schema.author.email="post@steffenvogel.de" \
	org.label-schema.description="A image containing all build-time dependencies for VILLASnode based on Fedora" \
	org.label-schema.url="http://fein-aachen.org/projects/villas-framework/" \
	org.label-schema.vcs-url="https://git.rwth-aachen.de/acs/public/villas/node" \
	org.label-schema.usage="https://villas.fein-aachen.org/doc/node-installation.html#node-installation-docker"
