Skip to content

Commit

Permalink
Merge pull request #138 from znley/main
Browse files Browse the repository at this point in the history
add ruby 3.4
  • Loading branch information
znley authored Feb 20, 2025
2 parents b3cc1fd + d3b2b68 commit 0e096b6
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
137 changes: 137 additions & 0 deletions library/ruby/3.4-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
FROM lcr.loongnix.cn/library/alpine:3.21

# skip installing gem documentation with `gem install`/`gem update`
RUN set -eux; \
mkdir -p /usr/local/etc; \
echo 'gem: --no-document' >> /usr/local/etc/gemrc

ENV LANG C.UTF-8

# https://www.ruby-lang.org/en/news/2025/02/14/ruby-3-4-2-released/
ENV RUBY_VERSION 3.4.2
ENV RUBY_DOWNLOAD_URL https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.2.tar.xz
ENV RUBY_DOWNLOAD_SHA256 ebf1c2eb58f5da17c23e965d658dd7e6202c5c50f5179154c5574452bef4b3e0

# some of ruby's build scripts are written in ruby
# we purge system ruby later to make sure our final image uses what we just built
RUN set -eux; \
\
apk add --no-cache --virtual .ruby-builddeps \
autoconf \
bzip2 \
bzip2-dev \
ca-certificates \
coreutils \
dpkg-dev dpkg \
g++ \
gcc \
gdbm-dev \
glib-dev \
gmp-dev \
libc-dev \
libffi-dev \
libxml2-dev \
libxslt-dev \
linux-headers \
make \
ncurses-dev \
openssl \
openssl-dev \
patch \
procps \
yaml-dev \
zlib-dev \
ruby \
tar \
xz \
yaml-dev \
zlib-dev \
; \
\
rustArch=; \
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
'x86_64') rustArch='x86_64-unknown-linux-musl'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.27.1/x86_64-unknown-linux-musl/rustup-init'; rustupSha256='1455d1df3825c5f24ba06d9dd1c7052908272a2cae9aa749ea49d67acbe22b47' ;; \
'aarch64') rustArch='aarch64-unknown-linux-musl'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.27.1/aarch64-unknown-linux-musl/rustup-init'; rustupSha256='7087ada906cd27a00c8e0323401a46804a03a742bd07811da6dead016617cc64' ;; \
esac; \
\
if [ -n "$rustArch" ]; then \
mkdir -p /tmp/rust; \
\
wget -O /tmp/rust/rustup-init "$rustupUrl"; \
echo "$rustupSha256 */tmp/rust/rustup-init" | sha256sum --check --strict; \
chmod +x /tmp/rust/rustup-init; \
\
export RUSTUP_HOME='/tmp/rust/rustup' CARGO_HOME='/tmp/rust/cargo'; \
export PATH="$CARGO_HOME/bin:$PATH"; \
/tmp/rust/rustup-init -y --no-modify-path --profile minimal --default-toolchain '1.84.0' --default-host "$rustArch"; \
\
rustc --version; \
cargo --version; \
fi; \
\
wget -O ruby.tar.xz "$RUBY_DOWNLOAD_URL"; \
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \
\
mkdir -p /usr/src/ruby; \
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \
rm ruby.tar.xz; \
\
cd /usr/src/ruby; \
\
# https://github.com/docker-library/ruby/issues/196
# https://bugs.ruby-lang.org/issues/14387#note-13 (patch source)
# https://bugs.ruby-lang.org/issues/14387#note-16 ("Therefore ncopa's patch looks good for me in general." -- only breaks glibc which doesn't matter here)
wget -O 'thread-stack-fix.patch' 'https://bugs.ruby-lang.org/attachments/download/7081/0001-thread_pthread.c-make-get_main_stack-portable-on-lin.patch'; \
echo '3ab628a51d92fdf0d2b5835e93564857aea73e0c1de00313864a94a6255cb645 *thread-stack-fix.patch' | sha256sum --check --strict; \
patch -p1 -i thread-stack-fix.patch; \
rm thread-stack-fix.patch; \
\
autoconf; \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--disable-install-doc \
--enable-shared \
${rustArch:+--enable-yjit} \
; \
make -j "$(nproc)"; \
make install; \
\
rm -rf /tmp/rust; \
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-network --virtual .ruby-rundeps $runDeps; \
apk del --no-network .ruby-builddeps; \
\
cd /; \
rm -r /usr/src/ruby; \
# verify we have no "ruby" packages installed
if \
apk --no-network list --installed \
| grep -v '^[.]ruby-' \
| grep -i ruby \
; then \
exit 1; \
fi; \
[ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \
# rough smoke test
ruby --version; \
gem --version; \
bundle --version

# don't create ".bundle" in all our apps
ENV GEM_HOME /usr/local/bundle
ENV BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $GEM_HOME/bin:$PATH
RUN set -eux; \
mkdir "$GEM_HOME"; \
# adjust permissions of GEM_HOME for running "gem install" as an arbitrary user
chmod 1777 "$GEM_HOME"

CMD [ "irb" ]
28 changes: 28 additions & 0 deletions library/ruby/3.4-alpine/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is generated by the template.

REGISTRY ?=lcr.loongnix.cn
ORGANIZATION ?=library
REPOSITORY ?=ruby
TAG ?=3.4-alpine
LATEST ?=false

IMAGE=$(REGISTRY)/$(ORGANIZATION)/$(REPOSITORY):$(TAG)
LATEST_IMAGE=$(REGISTRY)/$(ORGANIZATION)/$(REPOSITORY):latest

default: image

image:
docker build \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
-t $(IMAGE) \
.

push:
docker push $(IMAGE)
#latest image
@if [ $(LATEST) = "true" ]; \
then \
docker tag $(IMAGE) $(LATEST_IMAGE); \
docker push $(LATEST_IMAGE); \
fi

0 comments on commit 0e096b6

Please sign in to comment.