Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a Dockerfile #30

Merged
merged 5 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,36 @@ if (NOT MONERO_BUILD_DIR)
message(FATAL_ERROR "The argument -DMONERO_BUILD_DIR must specify a location of an existing monero build")
endif()

if(STATIC)
if(MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
endif()

load_cache(${MONERO_BUILD_DIR} READ_WITH_PREFIX monero_
Boost_THREAD_LIBRARY_RELEASE
CMAKE_CXX_COMPILER
EXTRA_LIBRARIES
LIBUDEV_LIBRARY
usb_LIBRARY
HIDAPI_INCLUDE_DIR
HIDAPI_LIBRARY
LMDB_INCLUDE
monero_SOURCE_DIR
OPENSSL_INCLUDE_PATH
OPENSSL_CRYPTO_LIBRARY
OPENSSL_SSL_LIBRARY
SODIUM_LIBRARY
UNBOUND_LIBRARIES
ZMQ_INCLUDE_PATH
ZMQ_LIB
PGM_LIBRARY
NORM_LIBRARY
GSSAPI_LIBRARY
PROTOLIB_LIBRARY
SODIUM_LIBRARY
)

if (NOT (monero_monero_SOURCE_DIR MATCHES "${MONERO_SOURCE_DIR}(/src/cryptonote_protocol)"))
Expand All @@ -115,18 +132,19 @@ if ("${monero_UNBOUND_LIBRARIES}" STREQUAL "UNBOUND_LIBRARIES-NOTFOUND")
unset(monero_UNBOUND_LIBRARIES)
endif()

if ("${monero_HIDAPI_LIBRARY}" STREQUAL "HIDAPI_LIBRARY-NOTFOUND")
unset(monero_HIDAPI_LIBRARY)
endif()

#
# Dependencies specific to monero-lws
#

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# boost
set(Boost_NO_BOOST_CMAKE ON)
if(STATIC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS chrono filesystem program_options regex serialization system thread)

if (NOT (Boost_THREAD_LIBRARY STREQUAL monero_Boost_THREAD_LIBRARY_RELEASE))
Expand All @@ -135,6 +153,36 @@ if (NOT (Boost_THREAD_LIBRARY STREQUAL monero_Boost_THREAD_LIBRARY_RELEASE))
message(FATAL_ERROR "Boost libraries for monero build differs from this project")
endif()


set(LMDB_INCLUDE "${monero_LMDB_INCLUDE}")
set(LMDB_LIB_PATH "monero::lmdb")
set(ZMQ_LIB "${monero_ZMQ_LIB}")

if(NOT ZMQ_LIB)
message(FATAL_ERROR "Could not find required libzmq")
endif()
if(monero_PGM_LIBRARY)
set(ZMQ_LIB "${ZMQ_LIB};${monero_PGM_LIBRARY}")
endif()
if(monero_NORM_LIBRARY)
set(ZMQ_LIB "${ZMQ_LIB};${monero_NORM_LIBRARY}")
endif()
if(monero_GSSAPI_LIBRARY)
set(ZMQ_LIB "${ZMQ_LIB};${monero_GSSAPI_LIBRARY}")
endif()
if(monero_PROTOLIB_LIBRARY)
set(ZMQ_LIB "${ZMQ_LIB};${monero_PROTOLIB_LIBRARY}")
endif()
if(monero_SODIUM_LIBRARY)
set(ZMQ_LIB "${ZMQ_LIB};${monero_SODIUM_LIBRARY}")
endif()

if(STATIC AND NOT IOS)
if(UNIX)
set(monero_OPENSSL_LIBRARIES "${monero_OPENSSL_LIBRARIES};${CMAKE_DL_LIBS};${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()

foreach (LIB ${MONERO_LIBRARIES})
find_library(LIB_PATH NAMES "${LIB}" PATHS ${MONERO_BUILD_DIR} PATH_SUFFIXES "/src/${LIB}" "external/${LIB}" ${MONERO_SEARCH_PATHS} NO_DEFAULT_PATH)

Expand All @@ -149,14 +197,15 @@ foreach (LIB ${MONERO_LIBRARIES})
set_target_properties(${LIB_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_PATH})
list(APPEND IMPORTED_MONERO_LIBRARIES "${LIB_NAME}")
endif()

unset(LIB_PATH CACHE)
endforeach()

add_library(monero::libraries INTERFACE IMPORTED)
set_property(TARGET monero::libraries PROPERTY
INTERFACE_INCLUDE_DIRECTORIES
${Boost_INCLUDE_DIR}
${monero_HIDAPI_INCLUDE_DIRS}
${monero_OPENSSL_INCLUDE_PATH}
"${MONERO_BUILD_DIR}/generated_include"
"${MONERO_SOURCE_DIR}/contrib/epee/include"
"${MONERO_SOURCE_DIR}/external/easylogging++"
Expand All @@ -174,19 +223,16 @@ set_property(TARGET monero::libraries PROPERTY
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${monero_HIDAPI_LIBRARY}
${monero_OPENSSL_CRYPTO_LIBRARY}
${monero_usb_LIBRARY}
${monero_LIBUDEV_LIBRARY}
${ZMQ_LIB}
${monero_OPENSSL_SSL_LIBRARY}
${monero_OPENSSL_CRYPTO_LIBRARY}
${monero_SODIUM_LIBRARY}
${monero_UNBOUND_LIBRARIES}
${CMAKE_DL_LIBS}
)

set(LMDB_INCLUDE "${monero_LMDB_INCLUDE}")
set(LMDB_LIB_PATH "monero::lmdb")
set(ZMQ_LIB "${monero_ZMQ_LIB}")
set(ZMQ_INCLUDE_PATH "${monero_ZMQ_INCLUDE_PATH}")


#
# Build monero-lws code
#
Expand Down
116 changes: 116 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Initial base from https://github.com/sethforprivacy/monero-lws/blob/588c7f1965d3afbda8a65dc870645650e063e897/Dockerfile

# Set monerod version to install from github
ARG MONERO_BRANCH=v0.17.3.0
ARG MONERO_COMMIT_HASH=ab18fea3500841fc312630d49ed6840b3aedb34d

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably bump this to v0.17.3.2 and 424e4de16b98506170db7b0d7d87a79ccf541744 before merging.


# Select ubuntu:20.04 for the build image base
FROM ubuntu:20.04 as build

# Install all dependencies for a static build
# Added DEBIAN_FRONTEND=noninteractive to workaround tzdata prompt on installation
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get upgrade --no-install-recommends -y

RUN apt-get install --no-install-recommends -y \
build-essential \
ca-certificates \
ccache \
cmake \
doxygen \
git \
graphviz \
libboost-all-dev \
libexpat1-dev \
libhidapi-dev \
libldns-dev \
liblzma-dev \
libpgm-dev \
libprotobuf-dev \
libreadline6-dev \
libsodium-dev \
libssl-dev \
libudev-dev \
libunbound-dev \
libunwind8-dev \
libusb-1.0-0-dev \
libzmq3-dev \
pkg-config \
protobuf-compiler \
qttools5-dev-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Set necessary args and environment variables for building Monero
ARG MONERO_BRANCH
ARG MONERO_COMMIT_HASH
ARG NPROC
ENV CFLAGS='-fPIC'
ENV CXXFLAGS='-fPIC -DELPP_FEATURE_CRASH_LOG'
ENV USE_SINGLE_BUILDDIR 1
ENV BOOST_DEBUG 1

# Switch to Monero source directory
WORKDIR /monero

# Git pull Monero source at specified tag/branch and compile monerod binary
RUN git clone --recursive --branch ${MONERO_BRANCH} \
https://github.com/monero-project/monero . \
&& test `git rev-parse HEAD` = ${MONERO_COMMIT_HASH} || exit 1 \
&& git submodule init && git submodule update \
&& mkdir -p build/release && cd build/release \
# Create make build files manually for release-static-linux-x86_64
&& cmake -D STATIC=ON -D ARCH="x86-64" -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D BUILD_TAG="linux-x64" ../.. \
# Build only monerod binary using number of available threads
&& cd /monero && nice -n 19 ionice -c2 -n7 make -j${NPROC:-$(nproc)} -C build/release daemon

# TODO: remove the need to manually make this static liblmdb_lib.a
RUN cd /monero/build/release/src/lmdb && make && cd /monero
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

CMake Error at CMakeLists.txt:242 (message):
  Unable to find required Monero library lmdb_lib


# Switch to monero-lws source directory
WORKDIR /monero-lws

COPY . .

ARG NPROC
RUN set -ex \
&& git submodule init && git submodule update \
&& rm -rf build && mkdir build && cd build \
&& cmake -D STATIC=ON -D MONERO_SOURCE_DIR=/monero -D MONERO_BUILD_DIR=/monero/build/release .. \
&& make -j${NPROC:-$(nproc)}

# Begin final image build
# Select Ubuntu 20.04LTS for the image base
FROM ubuntu:20.04

# Added DEBIAN_FRONTEND=noninteractive to workaround tzdata prompt on installation
ENV DEBIAN_FRONTEND=noninteractive

# Upgrade base image
RUN apt-get update \
&& apt-get upgrade --no-install-recommends -y

# Install necessary dependencies
RUN apt-get install --no-install-recommends -y \
ca-certificates \
curl \
jq \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Add user and setup directories for monero-lws
RUN useradd -ms /bin/bash monero-lws \
&& mkdir -p /home/monero-lws/.bitmonero/light_wallet_server \
&& chown -R monero-lws:monero-lws /home/monero-lws/.bitmonero
USER monero-lws

# Switch to home directory and install newly built monero-lws binary
WORKDIR /home/monero-lws
COPY --chown=monero-lws:monero-lws --from=build /monero-lws/build/src/* /usr/local/bin/

# Expose REST server port
EXPOSE 8443

ENTRYPOINT ["monero-lws-daemon", "--db-path=/home/monero-lws/.bitmonero/light_wallet_server"]
CMD ["--daemon=tcp://monerod:18082", "--sub=tcp://monerod:18083", "--log-level=4"]
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ target_link_libraries(monero-lws-daemon
monero-lws-util
monero-lws-wire-json
${Boost_CHRONO_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
Copy link
Contributor Author

@j-berman j-berman Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes compiler error #7 :)

${Boost_THREAD_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES}
Expand Down