Simple stubbed ruby builder

This commit is contained in:
Ryan Hughes
2025-10-08 10:31:59 -04:00
parent 1e7697fdd5
commit e61a0169ab
2 changed files with 148 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
# Multi-platform Dockerfile for Ruby builds
# Uses menci/archlinuxarm which supports both amd64 and arm64
FROM menci/archlinuxarm:latest
# Initialize pacman keyring (needed for ALARM, harmless for Arch)
RUN pacman-key --init && pacman-key --populate
# Update package database and install only necessary packages (skip full system upgrade to avoid slow downloads)
RUN pacman -Sy --noconfirm && \
pacman -S --noconfirm --needed git curl sudo ca-certificates openssl zlib libyaml libffi readline ncurses base-devel jq && \
pacman -Scc --noconfirm
# Set mise environment variables for a consistent, container-friendly path
ENV MISE_DATA_DIR=/mise
ENV MISE_CONFIG_DIR=/mise
ENV MISE_CACHE_DIR=/mise/cache
ENV MISE_INSTALL_PATH=/usr/local/bin/mise
ENV PATH=/mise/shims:$PATH
# Install mise
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl https://mise.run | sh
# Set Ruby build options for relocatable/portable compilation
ENV MISE_RUBY_BUILD_OPTS="--enable-load-relative --with-static-linked-ext"
# Copy the build script
COPY build-ruby.sh /build/build-ruby.sh
RUN chmod +x /build/build-ruby.sh
# Default command
CMD ["/build/build-ruby.sh"]
+116
View File
@@ -0,0 +1,116 @@
#!/bin/bash
# Build script for Ruby + Rails bundles
set -e
# Check required environment variables
if [[ -z "$RUBY_VERSION" ]]; then
echo "Error: RUBY_VERSION environment variable is required"
exit 1
fi
if [[ -z "$RAILS_VERSION" ]]; then
echo "Error: RAILS_VERSION environment variable is required"
exit 1
fi
if [[ -z "$ARCH" ]]; then
echo "Error: ARCH environment variable is required"
exit 1
fi
OUTPUT_DIR="/output/ruby/$ARCH"
mkdir -p "$OUTPUT_DIR"
echo "==> Ruby Bundle Builder"
echo "==> Ruby version: $RUBY_VERSION"
echo "==> Rails version: $RAILS_VERSION"
echo "==> Architecture: $ARCH"
echo "==> Output directory: $OUTPUT_DIR"
# Handle special Ruby versions
if [[ "$RUBY_VERSION" == "edge" ]]; then
echo "==> Installing Ruby edge from git..."
# mise can install Ruby from git
mise install ruby@ref:master
RUBY_INSTALL_VERSION="ref:master"
TARBALL_VERSION="edge"
else
echo "==> Installing Ruby $RUBY_VERSION..."
mise install "ruby@$RUBY_VERSION"
RUBY_INSTALL_VERSION="$RUBY_VERSION"
TARBALL_VERSION="$RUBY_VERSION"
fi
# Activate Ruby
echo "==> Activating Ruby..."
mise use "ruby@$RUBY_INSTALL_VERSION"
# Verify Ruby is working
echo "==> Ruby version check:"
ruby --version
# Find the actual Ruby installation directory
if [[ "$RUBY_INSTALL_VERSION" == "ref:master" ]]; then
# For edge builds, find the directory (it will have a hash name)
RUBY_DIR=$(ls -d /mise/installs/ruby/ref-* | head -1 | xargs basename)
else
RUBY_DIR="$RUBY_INSTALL_VERSION"
fi
# Set up gem paths for relocatable installation
export GEM_HOME="/mise/installs/ruby/$RUBY_DIR/lib/ruby/gems"
export GEM_PATH="$GEM_HOME"
export BUNDLE_PATH="$GEM_HOME"
mkdir -p "$GEM_HOME"
echo "==> Gem environment:"
echo " GEM_HOME: $GEM_HOME"
echo " GEM_PATH: $GEM_PATH"
# Install Rails
echo "==> Installing Rails $RAILS_VERSION..."
if [[ "$RAILS_VERSION" == "edge" ]]; then
gem install rails --pre
# Get the actual version installed
RAILS_ACTUAL_VERSION=$(gem list rails | grep "^rails " | sed 's/rails (\(.*\))/\1/')
TARBALL_RAILS_VERSION="edge-$RAILS_ACTUAL_VERSION"
else
gem install rails --version "$RAILS_VERSION"
TARBALL_RAILS_VERSION="$RAILS_VERSION"
fi
# Verify Rails is installed
echo "==> Rails version check:"
rails --version
# Generate a temporary Rails app to install default gems
echo "==> Generating temporary Rails app to install default gems..."
rails new temp_app --skip-git --skip-bundle
cd temp_app
# Install all the default gems to our GEM_HOME
bundle install
# Show installed gems count
echo "==> Installed gems:"
gem list | wc -l
# Clean up
cd /
rm -rf temp_app
# Create the tarball with proper naming
TARBALL_NAME="ruby-${TARBALL_VERSION}-rails-${TARBALL_RAILS_VERSION}-${ARCH}.tar.gz"
TARBALL_PATH="$OUTPUT_DIR/$TARBALL_NAME"
echo "==> Creating tarball: $TARBALL_NAME"
# Create the tarball including Ruby binaries and all gems
echo " Including Ruby installation and gems..."
tar -czf "$TARBALL_PATH" -C /mise/installs/ruby "$RUBY_DIR"
# Show file info
echo "==> Tarball created:"
ls -lh "$TARBALL_PATH"
echo "==> Build complete!"