-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I'm trying to build a docker image providing a statically linked musl binary of gutenberg (v0.3.3). This way the final docker image could contain only the static binary by using FROM scratch
.
Here's the dockerfile:
ARG RUSTC_VERSION=1.26.2
FROM rust:${RUSTC_VERSION}-slim-stretch as builder
ENV GUTENBERG_VERSION 0.3.3
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
wget \
tar \
cmake \
build-essential \
musl-dev \
musl-tools \
libpq-dev \
libsqlite-dev \
libssl-dev \
pkgconf \
xutils-dev \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/Keats/gutenberg/archive/v${GUTENBERG_VERSION}.tar.gz && \
tar -zxvf v${GUTENBERG_VERSION}.tar.gz && \
rm -f v${GUTENBERG_VERSION}.tar.gz
RUN rustup target add x86_64-unknown-linux-musl
WORKDIR gutenberg-${GUTENBERG_VERSION}
ENV RUST_BACKTRACE=1
RUN cargo build --release
FROM rust:${RUSTC_VERSION}-slim-stretch as runner
COPY --from=builder /gutenberg-${GUTENBERG_VERSION}/target/release/gutenberg .
CMD ["./gutenberg", "serve"]
Built and ran like this: docker build . -t gutenberg:v0.3.3 && docker run -it --rm gutenberg:v0.3.3
Right now it does not work. I've facing some issues.
First issue is the following:
error[E0518]: attribute should be applied to function
--> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tera-0.11.6/src/parser/mod.rs:13:10
|
13 | #[derive(Parser)]
| ^^^^^^ not a function
I'm not sure to understand this error. I was able to bypass it by running cargo update
. Here's the resulting lock file: Cargo.lock.txt
Could a release be done with updated dependencies? I guess that should fix this problem.
Secondly, I get a linking error if I try to link to musl (cargo build --release --target=x86_64-unknown-linux-musl
):
= note: /gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/libsass_sys-e5c815c30709cae7.rlib(sass_context.o): In fun
ction `_GLOBAL__sub_I_sass_context.cpp':
sass_context.cpp:(.text.startup+0x1c): undefined reference to `__dso_handle'
sass_context.cpp:(.text.startup+0x4e): undefined reference to `__dso_handle'
sass_context.cpp:(.text.startup+0xc9): undefined reference to `__dso_handle'
sass_context.cpp:(.text.startup+0xef): undefined reference to `__dso_handle'
sass_context.cpp:(.text.startup+0x118): undefined reference to `__dso_handle'
/gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/libsass_sys-e5c815c30709cae7.rlib(sass_context.o):sass_co
ntext.cpp:(.text.startup+0x141): more undefined references to `__dso_handle' follow
/usr/bin/ld: /gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/gutenberg-55708b3e089522b3: hidden symbol `_
_dso_handle' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Could rust-lang/rust#50105 be related?
Thanks!