在Alpine上使用带有Rust的libvips



我有一个带Actix Web的Rust应用程序,它使用libvips调整图像大小(https://crates.io/crates/libvips)。现在我正在尝试将其码头化。这是我的Dockerfile:

####################################################################################################
FROM rust:1.59.0-alpine3.15 AS build
RUN apk update && apk add vips vips-dev libc-dev
WORKDIR /opt/app
COPY ./ .
RUN cargo build --release
####################################################################################################
## Final image
####################################################################################################
FROM alpine:3.15
RUN apk update && apk add vips vips-dev libc-dev
WORKDIR /opt/app
# Copy our build
COPY --from=build /opt/app/target/release/ ./
CMD ["/opt/app/image-resizer"]

Cargo.toml:

[package]
name = "image-resizer"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "^4"
serde = { version = "1", features = ["derive"] }
env_logger = "0.9.0"
libvips = "1.4.3"

图像构建良好,但当我尝试运行它时,它退出时没有输出,代码为139。据我所知,这表明存在segfault或类似错误。

我发现libvips引入了一个问题(如果我删除它的用法,应用程序不会崩溃(,但不知道如何解决它。如果有任何帮助,我将不胜感激。

回购:https://gitlab.com/antonlyap/image-resizer

Valgrind输出:

==1== Memcheck, a memory error detector
==1== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1== Command: /opt/app/image-resizer
==1== 
==1== Jump to the invalid address stated on the next line
==1==    at 0x0: ???
==1==    by 0x3: ???
==1==    by 0x2: ???
==1==    by 0x1FFF000AD7: ???
==1==    by 0x1FFF000D0F: ???
==1==    by 0x4: ???
==1==    by 0x150191: unsetenv (unsetenv.c:28)
==1==    by 0x400001F: ???
==1==    by 0x14FF0D: libc_start_main_stage2 (__libc_start_main.c:94)
==1==    by 0x11291E: ??? (in /opt/app/image-resizer)
==1==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1== 
==1== 
==1== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==1==  Bad permissions for mapped region at address 0x0
==1==    at 0x0: ???
==1==    by 0x3: ???
==1==    by 0x2: ???
==1==    by 0x1FFF000AD7: ???
==1==    by 0x1FFF000D0F: ???
==1==    by 0x4: ???
==1==    by 0x150191: unsetenv (unsetenv.c:28)
==1==    by 0x400001F: ???
==1==    by 0x14FF0D: libc_start_main_stage2 (__libc_start_main.c:94)
==1==    by 0x11291E: ??? (in /opt/app/image-resizer)
==1== 
==1== HEAP SUMMARY:
==1==     in use at exit: 0 bytes in 0 blocks
==1==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1== 
==1== All heap blocks were freed -- no leaks are possible
==1== 
==1== For lists of detected and suppressed errors, rerun with: -s
==1== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0)
valgrind: the 'impossible' happened:
main(): signal was supposed to be fatal
host stacktrace:
==1==    at 0x580327DD: show_sched_status_wrk (m_libcassert.c:406)
==1==    by 0x58032A30: report_and_quit (m_libcassert.c:477)
==1==    by 0x58032C47: panic (m_libcassert.c:553)
==1==    by 0x58032C47: vgPlain_core_panic_at (m_libcassert.c:558)
==1==    by 0x58032C4F: vgPlain_core_panic (m_libcassert.c:563)
==1==    by 0x58088B54: shutdown_actions_NORETURN (m_main.c:2339)
==1==    by 0x580AD652: run_a_thread_NORETURN (syswrap-linux.c:201)
sched status:
running_tid=1

Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.
If that doesn't help, please report this bug to: www.valgrind.org
In the bug report, send all the above text, the valgrind
version, and what OS and version you are using.  Thanks.

最小复制码:

use libvips::VipsApp;
fn main() {
VipsApp::new("App", true).expect("Failed to create app");
}

https://github.com/olxgroup-oss/libvips-rust-bindings/issues/9

我已将Dockerfile中的第10行更改为

RUN RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" cargo build --release

错误消失了。

欢迎其他解决方案。感谢所有对我的帖子发表评论的人。

最新更新