Skip to content

Commit c6c66c5

Browse files
committed
fix: docker build with jemalloc
1 parent 0b8acdb commit c6c66c5

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ dist
55
*.data
66
*.data.old
77
Dockerfile
8+
docs
9+
venv
10+
demo
11+
.github
12+
.git
13+
**/*.data

.github/workflows/docker.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ jobs:
3535
matrix:
3636
platform:
3737
- linux/amd64
38-
- linux/arm64
38+
# Jemallocator has not recommended arm64
39+
# - linux/arm64
3940
# The matrix includes two platforms: linux/amd64 and linux/arm64.
4041
# The build job will run for each platform in the matrix.
4142

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
FROM docker.io/library/rust:1.90.0-alpine3.22 AS builder
2-
RUN apk add --no-cache musl-dev perl make protobuf-dev
1+
FROM docker.io/library/rust:1.92.0 AS builder
2+
RUN apt update && apt install -y protobuf-compiler libprotobuf-dev
33
WORKDIR /app
44

55
COPY . .
66

77
RUN --mount=type=cache,target=/app/target \
88
--mount=type=cache,target=/root/.cargo/registry \
99
--mount=type=cache,target=/root/.cargo/git \
10-
cargo build --release -p pulsebeam && \
10+
make release && \
1111
cp /app/target/release/pulsebeam /app/pulsebeam-bin
1212

13-
FROM docker.io/chainguard/static
13+
14+
FROM gcr.io/distroless/cc-debian13:nonroot
1415
WORKDIR /app
1516
COPY --from=builder --chown=nonroot:nonroot /app/pulsebeam-bin /app/pulsebeam
1617
EXPOSE 3478/udp 3000

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
include makefiles/net.mk
22

33
SCCACHE := $(shell which sccache)
4-
CARGO_CMD = RUSTC_WRAPPER=$(SCCACHE) cargo
4+
# https://github.com/tikv/jemallocator/issues/146
5+
# >> force-frame-pointers is required for profiling, add ~1% CPU overhead
6+
# >> allow-multiple-definition is required so we can replace system allocator for C projects, like openssl, ffmpeg, etc.
7+
# These CFLAGS are needed to make sure everything compiles with frame-pointer otherwise segfault will happen.
8+
export RUSTFLAGS := $(RUSTFLAGS) -C link-arg=-Wl,--allow-multiple-definition -C force-frame-pointers=yes
9+
export CFLAGS := $(CFLAGS) -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
10+
export CXXFLAGS := $(CXXFLAGS) -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
11+
# ===
12+
13+
CARGO_CMD = RUSTC_WRAPPER=$(SCCACHE) RUSTFLAGS="$(RUSTFLAGS)" cargo
514
TARGET_DIR = target/profiling
615
BINARY = $(TARGET_DIR)/pulsebeam
716

@@ -15,7 +24,7 @@ build:
1524
$(CARGO_CMD) build --profile profiling -p pulsebeam
1625

1726
release:
18-
$(CARGO_CMD) build --release -p pulsebeam
27+
$(CARGO_CMD) build --verbose --release -p pulsebeam
1928

2029
profile: build
2130

pulsebeam/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ahash = "0.8.12"
4141
tokio-stream = { version = "0.1.17", features = ["sync"] }
4242

4343
[target.'cfg(not(target_env = "msvc"))'.dependencies]
44-
tikv-jemallocator = { version = "0.6.0", features = ["profiling", "unprefixed_malloc_on_supported_platforms"] }
44+
tikv-jemallocator = { version = "0.6.0", features = ["profiling", "unprefixed_malloc_on_supported_platforms", "disable_initial_exec_tls"] }
4545
jemalloc_pprof = { version = "0.8.1", features = ["symbolize", "flamegraph"] }
4646

4747
[dev-dependencies]

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "1.91.0"
2+
channel = "1.92.0"
33
profile = "minimal"
44
components = ["rustfmt", "clippy", "rust-src", "rust-analyzer"]
55

0 commit comments

Comments
 (0)