FROM mcr.microsoft.com/devcontainers/base:debian-12
RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -qqy \
    build-essential \
    autoconf \
    libssl-dev \
    libyaml-dev \
    zlib1g-dev \
    libffi-dev \
    libgmp-dev \
    rustc \
    watchman \
    libsqlite3-dev \
    pkg-config
USER vscode
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv
ENV PATH="/home/vscode/.rbenv/bin:/home/vscode/.rbenv/shims:$PATH"
RUN echo 'eval "$(rbenv init - --no-rehash bash)"' >> ~/.bashrc
RUN git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
RUN rbenv install 3.4.4 && \
    rbenv global 3.4.4

# cache bundle install to make reloading the devcontainer faster
RUN mkdir -p /tmp/bundle-install-cache && \
    chown -R vscode:vscode /tmp/bundle-install-cache
WORKDIR /tmp/bundle-install-cache
COPY lib/has_aux_table/version.rb /tmp/bundle-install-cache/lib/has_aux_table/version.rb
COPY Gemfile.lock Gemfile has-aux-table.gemspec /tmp/bundle-install-cache/
RUN BUNDLE_FROZEN=true MAKE="make -j$(nproc)" bundle install --jobs $(nproc)

# convenience aliases
RUN echo 'alias rspec="bundle exec rspec"' >> ~/.bashrc
RUN echo 'alias tapioca="bundle exec tapioca"' >> ~/.bashrc
RUN echo 'alias srb="bundle exec srb"' >> ~/.bashrc
