FROM ubuntu:22.04 as OG

# Update system and install dependencies
# Download Wownero binaries from Gitea
# Confirm hashes match
# Install daemon binary
# Clean up

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y tar wget bzip2

ENV WOWNERO_HASH dddb23ca97575d5538a3a3b6a23e49706db15657e124c2300ea7972cb44a0387
ENV WOWNERO_DL_URL https://codeberg.org/wownero/wownero/releases/download/v0.11.3.0/wownero-x86_64-linux-gnu-v0.11.3.0.tar.bz2
ENV WOWNERO_DL_FILE wownero.tar.bz2
ENV WOWNERO_SUMS_FILE sha256sums

WORKDIR /opt/wownero

RUN wget -qO ${WOWNERO_DL_FILE} ${WOWNERO_DL_URL}

RUN echo "${WOWNERO_HASH}  ${WOWNERO_DL_FILE}" > ${WOWNERO_SUMS_FILE} \
  && sha256sum -c ${WOWNERO_SUMS_FILE}; \
  if [ "$?" -eq 0 ]; \
  then \
    echo -e "[+] Hashes match - proceeding with container build"; \
  else \
    echo -e "[!] Hashes do not match - exiting"; \
    exit 5; \
  fi \
  && mkdir ./tmp \
  && tar xvf ${WOWNERO_DL_FILE} -C ./tmp --strip 1 \
  && install ./tmp/wownero* /usr/local/bin/ \
  && rm -rf ./tmp ${WOWNERO_SUMS_FILE} ${WOWNERO_DL_FILE}

# Copy to fresh Ubuntu image to reduce size
FROM ubuntu:22.04
COPY --from=OG /usr/local/bin/wownero* /usr/local/bin/

WORKDIR /data

EXPOSE 34567
EXPOSE 34568
EXPOSE 34570