ACINQ / phoenixd

https://phoenix.acinq.co/server
Apache License 2.0
99 stars 13 forks source link

Issues building in Docker #1

Closed sethforprivacy closed 5 months ago

sethforprivacy commented 5 months ago

Hi there, first off thanks for this amazing tool! I can see this slotting into the toolkit of many merchants and organizations, and wanted to do what I could to simplify it's usage there.

I was working on Dockerizing it but hit a snag that is beyond my Gradle/Java knowledge. If you have any guidance on where to go next, AFAICT this should be a good base but errors out for me here:

Dockerfile:

  1 FROM gradle:8.4 as build
  2 
  3 ARG PHOENIXD_BRANCH=v0.1.1
  4 ARG PHOENIXD_COMMIT_HASH=4e42a462e6cc7d0a09fb224820071991ac1a0eca
  5 
  6 # Upgrade all packages and install dependencies
  7 RUN apt-get update \
  8     && apt-get upgrade -y
  9 RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 10         ca-certificates \
 11         git \
 12     && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 13 
 14 WORKDIR /phoenixd
 15 
 16 # Set necessary args and environment variables for building phoenixd
 17 ARG PHOENIXD_BRANCH
 18 ARG PHOENIXD_COMMIT_HASH
 19 
 20 # Git pull phoenixd source at specified tag/branch and compile phoenixd binary
 21 RUN git clone --recursive --branch ${PHOENIXD_BRANCH} \
 22     https://github.com/ACINQ/phoenixd . \
 23     && test `git rev-parse HEAD` = ${PHOENIXD_COMMIT_HASH} || exit 1 \
 24     && ./gradlew packageLinuxX64

Error:

1.178 Downloading https://services.gradle.org/distributions/gradle-8.4-bin.zip
2.415 ............10%............20%.............30%............40%.............50%............60%.............70%............80%.............90%............100%
8.305 
8.305 Welcome to Gradle 8.4!
8.305 
8.305 Here are the highlights of this release:
8.305  - Compiling and testing with Java 21
8.305  - Faster Java compilation on Windows
8.305  - Role focused dependency configurations creation
8.305 
8.305 For more details see https://docs.gradle.org/8.4/release-notes.html
8.305 
8.306 Starting a Gradle Daemon (subsequent builds will be faster)
64.71 > Task :buildSrc:pluginDescriptors
64.71 > Task :buildSrc:processResources NO-SOURCE
67.10 > Task :buildSrc:compileKotlin
67.10 > Task :buildSrc:compileJava NO-SOURCE
67.10 > Task :buildSrc:compileGroovy NO-SOURCE
67.10 > Task :buildSrc:classes UP-TO-DATE
67.10 
67.11 > Task :buildSrc:jar
67.11 :jar: No valid plugin descriptors were found in META-INF/gradle-plugins
135.9 
135.9 > Configure project :
135.9 
135.9 Please wait while Kotlin/Native compiler 1.9.23 is being installed.
136.5 Download https://download.jetbrains.com/kotlin/native/builds/releases/1.9.23/linux-x86_64/kotlin-native-prebuilt-linux-x86_64-1.9.23.tar.gz (198.18 MB)
144.0 Download kotlin-native-prebuilt-linux-x86_64-1.9.23.tar.gz finished, took 7 s 487 ms
144.0 Unpack Kotlin/Native compiler to /root/.konan/kotlin-native-prebuilt-linux-x86_64-1.9.23
145.8 Unpack Kotlin/Native compiler to /root/.konan/kotlin-native-prebuilt-linux-x86_64-1.9.23 finished, took 1 s 834 ms
146.1 
146.1 > Task :buildVersionsTask
146.1 > Task :checkKotlinGradlePluginConfigurationErrors
152.3 > Task :xcodeVersion SKIPPED
153.0 > Task :generateCommonMainPhoenixDatabaseInterface
168.1 > Task :compileKotlinLinuxX64 FAILED
168.1 
168.1 FAILURE: Build failed with an exception.
168.1 
168.1 * What went wrong:
168.1 Execution failed for task ':compileKotlinLinuxX64'.
168.1 > Could not resolve all files for configuration ':linuxX64CompileKlibraries'.
168.1    > Could not find fr.acinq.lightning:lightning-kmp:1.6.2-FEECREDIT-4.
168.1      Searched in the following locations:
168.1        - file:/root/.m2/repository/fr/acinq/lightning/lightning-kmp/1.6.2-FEECREDIT-4/lightning-kmp-1.6.2-FEECREDIT-4.pom
168.1        - https://oss.sonatype.org/content/repositories/snapshots/fr/acinq/lightning/lightning-kmp/1.6.2-FEECREDIT-4/lightning-kmp-1.6.2-FEECREDIT-4.pom
168.1        - https://repo.maven.apache.org/maven2/fr/acinq/lightning/lightning-kmp/1.6.2-FEECREDIT-4/lightning-kmp-1.6.2-FEECREDIT-4.pom
168.1        - https://dl.google.com/dl/android/maven2/fr/acinq/lightning/lightning-kmp/1.6.2-FEECREDIT-4/lightning-kmp-1.6.2-FEECREDIT-4.pom
168.1      Required by:
168.1          project :
168.1 
168.1 * Try:
168.1 > Run with --stacktrace option to get the stack trace.
168.1 > Run with --info or --debug option to get more log output.
168.1 > Run with --scan to get full insights.
168.1 > Get more help at https://help.gradle.org.
sethforprivacy commented 5 months ago

Additionally, any specifics on expected dependencies would be helpful! It seems that gradlew tries to grab all dependencies directly asides from Java from what I could tell, but again, this is all quite outside of my wheelhouse :)

pm47 commented 5 months ago

Phoenix depends on https://github.com/ACINQ/lightning-kmp (the core lightning implementation), specifically a version that we have not yet published to public repos. You need to compile it yourself but it's easy:

git clone https://github.com/ACINQ/lightning-kmp
git checkout v1.6.2-FEECREDIT-4
./gradlew publishToMavenLocal -x dokkaHtml
sethforprivacy commented 5 months ago

Phoenix depends on https://github.com/ACINQ/lightning-kmp (the core lightning implementation), specifically a version that we have not yet published to public repos. You need to compile it yourself but it's easy:


git clone https://github.com/ACINQ/lightning-kmp

git checkout v1.6.2-FEECREDIT-4

./gradlew publishToMavenLocal -x dokkaHtml

Ah, thank you so much, that should be trivial to add in those commands!

sethforprivacy commented 5 months ago

@pm47 thank you for that, was able to get further after adding that in! I have hit another issue now, though. I found that there were two unmentioned dependencies for phoenixd, libcurl4-openssl-dev and libsqlite3-dev. I was able to chase both down and add them in, but now get a strange error related to glibc and libsqlite.

New Dockerfile

ROM gradle:8-jammy as build

ARG PHOENIXD_BRANCH=v0.1.1
ARG PHOENIXD_COMMIT_HASH=4e42a462e6cc7d0a09fb224820071991ac1a0eca
ARG LIGHTNING_KMP_BRANCH=v1.6.2-FEECREDIT-4
ARG LIGHTNING_KMP_COMMIT_HASH=eba5a5bf7d7d77bd59cb8e38ecd20ec72d288672

# Upgrade all packages and install dependencies
RUN apt-get update \
    && apt-get upgrade -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        ca-certificates \
        libcurl4-openssl-dev \
        libsqlite3-dev \
        git \
    && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set necessary args and environment variables for building phoenixd
ARG PHOENIXD_BRANCH
ARG PHOENIXD_COMMIT_HASH
ARG LIGHTNING_KMP_BRANCH
ARG LIGHTNING_KMP_COMMIT_HASH

# Build dependencies
WORKDIR /lightning-kmp
RUN git clone --recursive --branch ${LIGHTNING_KMP_BRANCH} \
    https://github.com/ACINQ/lightning-kmp . \
    && test `git rev-parse HEAD` = ${LIGHTNING_KMP_COMMIT_HASH} || exit 1 \
    && ./gradlew publishToMavenLocal -x dokkaHtml

# Git pull phoenixd source at specified tag/branch and compile phoenixd binary
WORKDIR /phoenixd
RUN git clone --recursive --branch ${PHOENIXD_BRANCH} \
    https://github.com/ACINQ/phoenixd . \
    && test `git rev-parse HEAD` = ${PHOENIXD_COMMIT_HASH} || exit 1 \
    && ./gradlew packageLinuxX64

New error:

1.527 Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
48.93 > Task :buildSrc:pluginDescriptors
48.93 > Task :buildSrc:processResources NO-SOURCE
51.33 > Task :buildSrc:compileKotlin
51.33 > Task :buildSrc:compileJava NO-SOURCE
51.33 > Task :buildSrc:compileGroovy NO-SOURCE
51.33 > Task :buildSrc:classes UP-TO-DATE
51.33 
51.33 > Task :buildSrc:jar
51.33 :jar: No valid plugin descriptors were found in META-INF/gradle-plugins
66.33 
66.33 > Task :buildVersionsTask
66.33 > Task :checkKotlinGradlePluginConfigurationErrors
72.13 > Task :xcodeVersion SKIPPED
72.83 > Task :generateCommonMainPhoenixDatabaseInterface
92.73 > Task :compileKotlinLinuxX64
122.6 > Task :linkPhoenix-cliDebugExecutableLinuxX64
151.9 e: /root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors
151.9 Please try to disable compiler caches and rerun the build. To disable compiler caches, add the following line to the gradle.properties file in the project's root directory:
151.9     
151.9     kotlin.native.cacheKind.linuxX64=none
151.9     
151.9 Also, consider filing an issue with full Gradle log here: https://kotl.in/issue
151.9 The /root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
151.9 output:
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'stat64', version 'GLIBC_2.33'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'fstat64', version 'GLIBC_2.33'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'lstat64', version 'GLIBC_2.33'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'fcntl64', version 'GLIBC_2.28'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'log', version 'GLIBC_2.29'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'dlclose', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'dlerror', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'dlopen', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'dlsym', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'exp', version 'GLIBC_2.29'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pow', version 'GLIBC_2.29'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_mutex_trylock', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_destroy', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_create', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_join', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_init', version 'GLIBC_2.34'
151.9 /usr/lib/x86_64-linux-gnu/libsqlite3.so: error: undefined reference to 'pthread_mutexattr_settype', version 'GLIBC_2.34'
151.9 
151.9 > Task :linkPhoenix-cliDebugExecutableLinuxX64 FAILED
151.9 
151.9 FAILURE: Build failed with an exception.
151.9 
151.9 * What went wrong:
151.9 Execution failed for task ':linkPhoenix-cliDebugExecutableLinuxX64'.
151.9 > Compilation finished with errors
151.9 
151.9 * Try:
151.9 > Run with --stacktrace option to get the stack trace.
151.9 > Run with --info or --debug option to get more log output.
151.9 > Run with --scan to get full insights.
151.9 > Get more help at https://help.gradle.org.
151.9 
151.9 BUILD FAILED in 2m 30s
151.9 8 actionable tasks: 8 executed

Edit: after a bunch of searching the only related issue I could find across the interwebz was this one: https://github.com/ctripcorp/SQLlin/issues/48

vincenzopalazzo commented 5 months ago

@sethforprivacy probably relate to https://stackoverflow.com/a/73481501/10854225

sethforprivacy commented 5 months ago

@sethforprivacy probably relate to https://stackoverflow.com/a/73481501/10854225

Yikes, if so I'll probably just give up on building from source in the container and pivot to downloading binaries + checking hashes + sigs.

Didn't expect it would be so cumbersome to build compared to everything else I do this for. Thanks for the details, I'll close this for now and change up the approach.

vincenzopalazzo commented 5 months ago

Yikes, if so I'll probably just give up on building from source in the container and pivot to downloading binaries + checking hashes + sigs.

It is what I did

Is it possible to leave this issue open, please?

sethforprivacy commented 5 months ago

Yikes, if so I'll probably just give up on building from source in the container and pivot to downloading binaries + checking hashes + sigs.

It is what I did

Is it possible to leave this issue open, please?

For some reason I can't reopen on mobile but will do so ASAP.

Does that mean you have a workable solution for building in Docker you could share?

vincenzopalazzo commented 5 months ago

No I do not have any solution, I use the pre-compiled binaries

wladpaiva commented 5 months ago

I got it working with the pre-compiled binaries as well

If anyone is wondering, here is the docker image

# Use a minimal Debian base image
FROM --platform=linux/amd64 debian:bullseye-slim

# Install necessary packages, including libcurl
RUN apt-get update && \
  apt-get install -y wget unzip gnupg libcurl4 libcurl4-openssl-dev && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/*

# Download and import the GPG key from ACINQ's website
RUN wget -qO- https://acinq.co/pgp/drouinf.asc | gpg --import

# Download the Phoenix binary and its signatures
WORKDIR /opt/phoenix
RUN wget https://github.com/ACINQ/phoenixd/releases/download/v0.1.1/phoenix-0.1.1-linux-x64.zip && \
  wget https://github.com/ACINQ/phoenixd/releases/download/v0.1.1/SHA256SUMS.asc

# Verify the release file checksums and signatures
RUN gpg -d SHA256SUMS.asc > SHA256SUMS.stripped && \
  grep 'phoenix-0.1.1-linux-x64.zip' SHA256SUMS.stripped > SHA256SUMS.filtered && \
  sha256sum -c SHA256SUMS.filtered

# Unzip the downloaded file
RUN unzip -j phoenix-0.1.1-linux-x64.zip && \
  chmod +x phoenixd

# Clean up unnecessary files
RUN rm phoenix-0.1.1-linux-x64.zip SHA256SUMS.asc SHA256SUMS.stripped

# Indicate that the container listens on port 9740
EXPOSE 9740

# Run the daemon
ENTRYPOINT ["./phoenixd", "--http-bind-ip", "0.0.0.0"]
pm47 commented 5 months ago

Indeed the build instructions are lacking some dependencies.

The dockerfile below should do what you want. However I think building native binaries on docker is not the right approach. It would be better to run on the jvm: easier build, faster runtime and compatible with linux arm64, which we don't support otherwise. We'll add a jvm build for the next version.

FROM ubuntu:18.04 as build

ARG PHOENIXD_BRANCH=v0.1.1
ARG PHOENIXD_COMMIT_HASH=4e42a462e6cc7d0a09fb224820071991ac1a0eca
ARG LIGHTNING_KMP_BRANCH=v1.6.2-FEECREDIT-4
ARG LIGHTNING_KMP_COMMIT_HASH=eba5a5bf7d7d77bd59cb8e38ecd20ec72d288672
ARG CURL_VERSION=7.88.1

# Upgrade all packages and install dependencies
RUN apt-get update \
    && apt-get upgrade -y
RUN apt-get install -y --no-install-recommends \
        ca-certificates \
        openjdk-17-jdk \
        openssh-client \
        libgnutls28-dev \
        libsqlite3-dev  \
        build-essential \
        git \
        wget \
    && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set necessary args and environment variables for building phoenixd
ARG PHOENIXD_BRANCH
ARG PHOENIXD_COMMIT_HASH
ARG LIGHTNING_KMP_BRANCH
ARG LIGHTNING_KMP_COMMIT_HASH

# Build dependencies
WORKDIR /lightning-kmp
RUN git clone --recursive --branch ${LIGHTNING_KMP_BRANCH} \
    https://github.com/ACINQ/lightning-kmp . \
    && test `git rev-parse HEAD` = ${LIGHTNING_KMP_COMMIT_HASH} || exit 1 \
    && ./gradlew publishToMavenLocal -x dokkaHtml

WORKDIR /curl
RUN wget https://curl.se/download/curl-${CURL_VERSION}.tar.bz2 \
    && tar -xjvf curl-${CURL_VERSION}.tar.bz2 \
    && cd curl-${CURL_VERSION} \
    && ./configure --with-gnutls=/lib/x86_64-linux-gnu/ \
    && make \
    && make install \
    && ldconfig

# Git pull phoenixd source at specified tag/branch and compile phoenixd binary
WORKDIR /phoenixd
RUN git clone --recursive --branch ${PHOENIXD_BRANCH} \
    https://github.com/ACINQ/phoenixd . \
    && test `git rev-parse HEAD` = ${PHOENIXD_COMMIT_HASH} || exit 1 \
    && ./gradlew packageLinuxX64

# Indicate that the container listens on port 9740
EXPOSE 9740

# Run the daemon
ENTRYPOINT ["/phoenixd/build/bin/linuxX64/phoenixdReleaseExecutable/phoenixd.kexe", "--http-bind-ip", "0.0.0.0"]
lvnilesh commented 5 months ago

Thanks for the source Dockerfile. I am using this docker-compose.yaml alongside to map the seed and channels volumes ~/.phoenix outside the container on to the host machine. Thanks.

version: "3"
services:
  phoenixd:
    build: .
    image: phoenixd:latest
    container_name: phoenixd
    volumes:
      - ./dotphoenix:/root/.phoenix
    expose:
      - 9740
    ports:
      - 9740:9740
vincenzopalazzo commented 5 months ago

The problem is not just with docker but also with arch linux

@pm47 Do you think that using the library that you use inside your docker example can fix this problem? or a different libc is a problem also there?

sethforprivacy commented 5 months ago

Thanks so much for the help with this, @pm47! I was able to use your Dockerfile as a base to build out precisely what I wanted, including a separate builder/final stage to reduce final image size greatly.

For anyone interested you can find my working Dockerfile here:

https://github.com/sethforprivacy/phoenixd-docker/blob/main/Dockerfile

pm47 commented 5 months ago

@pm47 Do you think that using the library that you use inside your docker example can fix this problem? or a different libc is a problem also there?

@vincenzopalazzo Both: it needs a recent libcurl (the exact version doesn't really matter) compiled against an old glibc 🙃 . Prebuilt binaries typically have old/old or new/new.

You can use linkerOpts("--allow-shlib-undefined") to work around this but we don't recommend it as it could in theory cause crashes at runtime.

vincenzopalazzo commented 5 months ago

I think I can use nix to solve this problem @pm47 thanks :)