RedisJSON / RedisJSON

RedisJSON - a JSON data type for Redis
https://redis.io/docs/stack/json/
Other
3.8k stars 319 forks source link

Alpine build error #769

Open ianmurphy1 opened 2 years ago

ianmurphy1 commented 2 years ago

Build error in alpine image

Trying to build this module in alpine by using the Dockerfile in this repo as a guide, I'm getting errors consistently when attempting to compile redis-module.

Clip from my Dockerfile:

FROM redis:6.2-alpine as builder

ARG REDIS_JSON_VERSION=${redis_json_version:-2.0.9}

WORKDIR "/build"

RUN apk add --no-cache curl git bash gcc g++ musl musl-dev make cmake clang clang-dev clang-libs llvm llvm-dev python3-dev python3 \
    && git clone --depth 1 --branch "v${REDIS_JSON_VERSION}" https://github.com/RedisJSON/RedisJSON.git \
    && cd RedisJSON \
    && cd ./deps/readies \
    && git submodule update --init

WORKDIR "/build/RedisJSON"

RUN ./deps/readies/bin/getupdates
RUN ./deps/readies/bin/getpy3
RUN ./sbin/system-setup.py

ENV PATH="${PATH}:/root/.cargo/bin"

RUN make build SHOW=1 RUST_BACKTRACE=full

RUST_BACKTRACE=full error logs:


    error: failed to run custom build command for `redis-module v1.0.1`

Caused by:
  process didn't exit successfully: `/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-1e568335e3b8baa7/build-script-build` (exit status: 101)
  --- stdout
  TARGET = Some("x86_64-unknown-linux-musl")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-unknown-linux-musl")
  CC_x86_64-unknown-linux-musl = None
  CC_x86_64_unknown_linux_musl = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-unknown-linux-musl = None
  CFLAGS_x86_64_unknown_linux_musl = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "src/include/" "-Wall" "-Wextra" "-DREDISMODULE_EXPERIMENTAL_API" "-o" "/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-f1a640ae22922524/out/src/redismodule.o" "-c" "src/redismodule.c"
  exit status: 0
  AR_x86_64-unknown-linux-musl = None
  AR_x86_64_unknown_linux_musl = None
  HOST_AR = None
  AR = None
  running: "ar" "cq" "/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-f1a640ae22922524/out/libredismodule.a" "/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-f1a640ae22922524/out/src/redismodule.o"
  exit status: 0
  running: "ar" "s" "/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-f1a640ae22922524/out/libredismodule.a"
  exit status: 0
  cargo:rustc-link-lib=static=redismodule
  cargo:rustc-link-search=native=/build/RedisJSON/bin/linux-x64-release/target/release/build/redis-module-f1a640ae22922524/out

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at /usr/lib/libclang.so.13.0.1 could not be opened: Dynamic loading not supported"', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:2144:31
  stack backtrace:
     0:     0x7f13d74fcd4d - std::backtrace_rs::backtrace::libunwind::trace::h91d5e08ec83aa53b
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
     1:     0x7f13d74fcd4d - std::backtrace_rs::backtrace::trace_unsynchronized::hc1e2a5f8ec1acff3
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
     2:     0x7f13d74fcd4d - std::sys_common::backtrace::_print_fmt::h399ef521e9cfa38c
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:66:5
     3:     0x7f13d74fcd4d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc9d0bc2361a81055
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:45:22
     4:     0x7f13d75378ec - core::fmt::write::hd290451e0cade67a
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/fmt/mod.rs:1196:17
     5:     0x7f13d74f8fb1 - std::io::Write::write_fmt::h9efe861491665d4b
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/io/mod.rs:1654:15
     6:     0x7f13d74fe685 - std::sys_common::backtrace::_print::h88be5589fe3d1a62
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:48:5
     7:     0x7f13d74fe685 - std::sys_common::backtrace::print::hf2e0958149d5f57a
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:35:9
     8:     0x7f13d74fe685 - std::panicking::default_hook::{{closure}}::h30de4c851c56c694
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:295:22
     9:     0x7f13d74fe2f9 - std::panicking::default_hook::h9732410f9bf1dde1
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:314:9
    10:     0x7f13d74fec58 - std::panicking::rust_panic_with_hook::h05457703f08d1cb5
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:698:17
    11:     0x7f13d74feb07 - std::panicking::begin_panic_handler::{{closure}}::h63db6fbc665e433e
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:588:13
    12:     0x7f13d74fd204 - std::sys_common::backtrace::__rust_end_short_backtrace::h7b5645a9de09611c
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:138:18
    13:     0x7f13d74fe839 - rust_begin_unwind
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
    14:     0x7f13d6ff0e33 - core::panicking::panic_fmt::h57aeae238836f7da
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
    15:     0x7f13d6ff0f23 - core::result::unwrap_failed::hedc75da3e2a631a2
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/result.rs:1785:5
    16:     0x7f13d706dcf9 - core::result::Result<T,E>::expect::h9d36cac60b9a31d3
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/result.rs:1035:23
    17:     0x7f13d705e0dd - <bindgen::ensure_libclang_is_loaded::LIBCLANG as core::ops::deref::Deref>::deref::__static_ref_initialize::hd8e8e40c9fb0e7c1
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:2144:13
    18:     0x7f13d705e0dd - core::ops::function::FnOnce::call_once::hb5e7a6a24cf70f33
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5
    19:     0x7f13d71dab41 - lazy_static::lazy::Lazy<T>::get::{{closure}}::h46996f9680ec04ef
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:31:29
    20:     0x7f13d71eeba4 - std::sync::once::Once::call_once::{{closure}}::h96a8c39e09f46894
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sync/once.rs:276:41
    21:     0x7f13d6feffda - std::sync::once::Once::call_inner::hd1bb8e659f8221ae
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sync/once.rs:434:21
    22:     0x7f13d71eea37 - std::sync::once::Once::call_once::h921bd463864d2481
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sync/once.rs:276:9
    23:     0x7f13d7154478 - lazy_static::lazy::Lazy<T>::get::h89108439ce29a624
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:30:9
    24:     0x7f13d7154478 - <bindgen::ensure_libclang_is_loaded::LIBCLANG as core::ops::deref::Deref>::deref::__stability::h50c7106559ec7288
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/lib.rs:142:21
    25:     0x7f13d7154478 - <bindgen::ensure_libclang_is_loaded::LIBCLANG as core::ops::deref::Deref>::deref::h0c278cbe367aba19
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/lib.rs:144:17
    26:     0x7f13d714bd65 - bindgen::ensure_libclang_is_loaded::h00a68a85142e86a4
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:2152:33
    27:     0x7f13d714c31a - bindgen::Bindings::generate::h12aef68e80b91a67
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:2211:9
    28:     0x7f13d714a3b2 - bindgen::Builder::generate::hc9b504308546c390
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:1478:9
    29:     0x7f13d6ff21f7 - build_script_build::main::h3fec4fc46159ab9d
                                 at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/redis-module-1.0.1/build.rs:68:20
    30:     0x7f13d6ff2523 - core::ops::function::FnOnce::call_once::h764c438abdef587e
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5
    31:     0x7f13d6ff2ab9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h36d6d45e0f4aa105
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:122:18
    32:     0x7f13d6ff2859 - std::rt::lang_start::{{closure}}::he1ac8c5022a369a2
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/rt.rs:145:18
    33:     0x7f13d74f4c11 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hebd650acbac1d4a4
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:280:13
    34:     0x7f13d74f4c11 - std::panicking::try::do_call::hecbd3eb037d46a8f
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:492:40
    35:     0x7f13d74f4c11 - std::panicking::try::he4917a79ebd580dc
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:456:19
    36:     0x7f13d74f4c11 - std::panic::catch_unwind::h556073795a30efab
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panic.rs:137:14
    37:     0x7f13d74f4c11 - std::rt::lang_start_internal::{{closure}}::h1f79c9445318151b
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/rt.rs:128:48
    38:     0x7f13d74f4c11 - std::panicking::try::do_call::h9ec5f34c23d02b33
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:492:40
    39:     0x7f13d74f4c11 - std::panicking::try::h77ceb3f19415d425
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:456:19
    40:     0x7f13d74f4c11 - std::panic::catch_unwind::hbdf745a6c0c2efdb
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panic.rs:137:14
    41:     0x7f13d74f4c11 - std::rt::lang_start_internal::h7e07fb0742296f5d
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/rt.rs:128:20
    42:     0x7f13d6ff2841 - std::rt::lang_start::h88d64eebb4d27569
                                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/rt.rs:144:17
    43:     0x7f13d6ff249c - main
warning: build failed, waiting for other jobs to finish...
make: *** [Makefile:174: build] Error 101```
gkorland commented 2 years ago

It seems related to:

https://github.com/tikv/grpc-rs/issues/477 https://gitlab.alpinelinux.org/alpine/aports/-/issues/12226

ianmurphy1 commented 2 years ago

@gkorland

I've gotten it to build and now redis is running with the module enabled since I made this issue yesterday so you can close, for anyone else that comes across this in the future, below is how I got it building and running in an alpine based image.

Working Dockerfile for the build part in alpine:

FROM alpine:3.16 as builder

ARG REDIS_JSON_VERSION=${redis_json_version:-2.0.9}

WORKDIR "/build"

RUN apk add --no-cache \
        git \
        bash \
        make \
        musl-dev \
        clang-libs \
        clang-dev \
        llvm \
        cargo \
        rust \
    && git clone --depth 1 --branch "v${REDIS_JSON_VERSION}" https://github.com/RedisJSON/RedisJSON.git \
    && cd RedisJSON \
    && cd ./deps/readies \
    && git submodule update --init

WORKDIR "/build/RedisJSON"

RUN ./deps/readies/bin/getupdates
RUN ./deps/readies/bin/getpy3
RUN ./sbin/system-setup.py

RUN make build SHOW=1

For the module to run successfully the container image running redis with the module needs clang-libs installed:

FROM redis:local

RUN apk add --no-cache \
        clang-libs

COPY --from=builder /build/RedisJSON/bin/linux-x64-release/rejson.so* "/usr/lib/redis/modules/"

And the logs on running the image:

docker run --rm redis:json
1:C 13 Jul 2022 09:16:39.725 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 13 Jul 2022 09:16:39.725 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 13 Jul 2022 09:16:39.725 # Configuration loaded
1:M 13 Jul 2022 09:16:39.725 * monotonic clock: POSIX clock_gettime
1:M 13 Jul 2022 09:16:39.726 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.
1:M 13 Jul 2022 09:16:39.726 * Running mode=standalone, port=6379.
1:M 13 Jul 2022 09:16:39.726 # Server initialized
1:M 13 Jul 2022 09:16:39.726 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 13 Jul 2022 09:16:39.726 * <ReJSON> version: 20009 git sha: d8d4b19 branch: HEAD
1:M 13 Jul 2022 09:16:39.726 * <ReJSON> Exported RedisJSON_V1 API
1:M 13 Jul 2022 09:16:39.726 * <ReJSON> Enabled diskless replication
1:M 13 Jul 2022 09:16:39.726 * <ReJSON> Created new data type 'ReJSON-RL'
1:M 13 Jul 2022 09:16:39.726 * Module 'ReJSON' loaded from /usr/lib/redis/modules/rejson.so
1:M 13 Jul 2022 09:16:39.726 * Ready to accept connections