You need to install git to be able to use gems from git repositories (non-rails/noob question)

I am aware of this question: You need to install git to be able to use gems from git repositories.
I am trying to host an existing project on fly.io created by someone else. Unfortunately, I am a newb in this area, so I couldn’t figure out if I can install rails, or how to rebuild this project to include rails.
I am wondering if there are other ways of solving this error. Full message here:

 => [build 2/3] COPY Gemfile* .                                            0.0s
 => ERROR [build 3/3] RUN bundle install                                   3.9s
------                                                                          
 > [build 3/3] RUN bundle install:                                              
#0 0.477 Bundler 2.4.21 is running, but your lockfile was generated with 2.4.5. Installing Bundler 2.4.5 and restarting using that version.                     
#0 3.394 Fetching gem metadata from https://rubygems.org/.                      
#0 3.440 Fetching bundler 2.4.5
#0 3.548 Installing bundler 2.4.5
#0 3.899 Fetching https://github.com/shardlab/discordrb.git
#0 3.909 You need to install git to be able to use gems from git repositories. For help
#0 3.909 installing git, please refer to GitHub's tutorial at
#0 3.909 https://help.github.com/articles/set-up-git
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c bundle install]: exit code: 11

Normally, this can be corrected by running:

bin/rails generate dockerfile

If this doesn’t help, can you post your Dockerfile?

As far as I understand, this is not a Rails application, so I cannot use bin/rails from within its folder. I tried installing rails with gem install rails, but that still doesn’t let me run the command. Again, I apologize for the noob understanding.
Here’s the Dockerfile:

ARG RUBY_VERSION=3.1.2
FROM ruby:$RUBY_VERSION-slim as base

# Rack app lives here
WORKDIR /app

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential

# Install application gems
COPY Gemfile* .
RUN bundle install

# Final stage for app image
FROM base

# Run and own the application files as a non-root user for security
RUN useradd ruby --home /app --shell /bin/bash
USER ruby:ruby

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=ruby:ruby /app /app

# Copy application code
COPY --chown=ruby:ruby . .

# Start the server
EXPOSE 8080
CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "--port", "8080"]

Add git to the end of that line.

This worked :+1:
I think I understand what it did too - you tell it to install the package on fly instead of installing locally. This actually solved a related problem that I had with this, since I just added those to that line of the Dockerfile as well.

Cheers!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.