Skip to content

Commit 7e30f59

Browse files
committed
Base the docker image on the official ruby docker image instead of my own custom one. Looks like jemalloc can be loaded with LD_PRELOAD and does not need to be configured when ruby is built.
1 parent cf6fd6f commit 7e30f59

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

Dockerfile

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://hub.docker.com/r/stefansundin/rssbox
22
# docker pull stefansundin/rssbox
3-
# docker run -i -t -p 3000:3000 stefansundin/rssbox
4-
# docker run -i -t --entrypoint bin/cons stefansundin/rssbox
3+
# docker run --rm -it -p 3000:3000 stefansundin/rssbox
4+
# docker run --rm -it --entrypoint bin/cons stefansundin/rssbox
55

66
# docker network create rssbox
77
# docker run --rm --network=rssbox --name=redis redis redis-server --appendonly yes
@@ -17,24 +17,52 @@
1717
# Push to public ECR:
1818
# docker buildx imagetools create -t public.ecr.aws/stefansundin/rssbox stefansundin/rssbox
1919

20-
FROM stefansundin/ruby:3.4-jemalloc
20+
# Verify jemalloc:
21+
# docker run --rm -it --entrypoint ruby -e MALLOC_CONF=stats_print:true stefansundin/rssbox -- -e exit
22+
# Verify YJIT:
23+
# docker run --rm -it --entrypoint ruby -e RUBYOPT="--yjit" stefansundin/rssbox -e "puts RUBY_DESCRIPTION"
24+
25+
FROM ruby:3.4 AS builder
26+
27+
RUN echo 'gem: --no-document' >> /usr/local/etc/gemrc
28+
29+
WORKDIR /app
30+
COPY Gemfile Gemfile.lock ./
31+
32+
RUN bundle config set --local without development:test
33+
RUN bundle config set --local deployment true
34+
RUN bundle install --retry=3 --jobs=4
35+
36+
37+
FROM ruby:3.4-slim
38+
2139
LABEL org.opencontainers.image.authors="Stefan Sundin"
2240
LABEL org.opencontainers.image.url="https://github.com/stefansundin/rssbox"
2341

24-
# install system utilities that are useful when debugging
2542
RUN \
2643
apt-get update && \
2744
apt-get upgrade -y && \
2845
apt-get install -y --no-install-recommends \
46+
libjemalloc2 \
47+
rustc \
48+
git \
2949
vim less && \
3050
apt-get clean && \
3151
rm -rf /var/lib/apt/lists/*
3252

53+
RUN ln -s $(uname -m)-linux-gnu/libjemalloc.so.2 /usr/lib/libjemalloc.so.2
54+
ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
55+
ENV MALLOC_ARENA_MAX=2
56+
57+
ENV APP_ENV=production
58+
3359
WORKDIR /app
34-
COPY Gemfile Gemfile.lock ./
35-
RUN bundle config set --local without development:test
36-
RUN bundle config set --local deployment true
37-
RUN bundle install --retry=3 --jobs=4
60+
COPY --from=builder /usr/local/etc/gemrc /usr/local/etc/gemrc
61+
COPY --from=builder /usr/local/bundle/config /usr/local/bundle/config
62+
COPY --from=builder /app /app
63+
64+
RUN bundle check
65+
3866
COPY . .
3967
RUN find -not -path './vendor/*'
4068

0 commit comments

Comments
 (0)