# Base image for building Solargraph from source
FROM ruby:slim-bookworm
# Install system dependencies required for building gems with native extensions
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
git \
build-essential \
patch \
ruby-dev \
zlib1g-dev \
liblzma-dev \
libxml2-dev \
libxslt1-dev \
pkg-config \
cmake \
libyaml-dev \
libssl-dev \
libgit2-dev \
libcurl4-openssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Bundler >= 2.0 to satisfy gemspec bundler requirements
RUN gem install bundler -v '>= 2.0' --no-document
# Set work directory for the build
WORKDIR /solargraph
# Copy Gemfile and gemspec first to leverage Docker layer caching
COPY Gemfile Gemfile
COPY solargraph.gemspec solargraph.gemspec
# Copy the rest of the source code so that git ls-files works and lib files exist
COPY . .
# Install project dependencies
RUN bundle install
# Build the gem from source
RUN bundle exec rake build
# Install the built gem into the image so the 'solargraph' executable is available
RUN mkdir -p /opt/solargraph
RUN cp pkg/solargraph-*.gem /opt/solargraph/
RUN gem install /opt/solargraph/solargraph-*.gem
# Ensure the Bundler bin directory is in PATH so the 'solargraph' executable is discoverable
ENV PATH="/usr/local/bundle/bin:${PATH}"
# Default command to run the Solargraph CLI
CMD ["solargraph"]