Ruby + Alpine + Docker: git cannot be found when it's installed? - ruby-on-rails

I have a Rails App using Ruby 3 that I deploy using Docker. In my Gemfile I am installing the gem sunspot_rails via github, as the latest official release does not work with Ruby 3:
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'sunspot_rails', github: 'sunspot/sunspot', glob: 'sunspot_rails/*.gemspec'
In my Production Dockerfile I have a stage which installs the required Gems:
#####################################
# Backend Dependencies
#####################################
FROM ruby:3.0.2-alpine3.14 AS vendor
RUN apk add --no-cache \
sqlite-dev postgresql-dev \
git build-base
# Install backend packages
COPY Gemfile Gemfile.lock ./
RUN bundle config set --local deployment "true" && \
bundle config set --local without "development,test" && \
bundle install
On my local machine, this works fine.
However, when I try to build the image in my CI/CD Pipeline (using drone), I get an error implying that git could not be found:
Fetching https://github.com/sunspot/sunspot.git
Retrying `git clone https://github.com/sunspot/sunspot.git /vendor/bundle/ruby/3.0.0/cache/bundler/git/sunspot-cb781ed3afb1e1091992c51d2c44d880bb461de8 --bare --no-hardlinks --quiet` at / due to error (2/4): Errno::ENOENT No such file or directory - git
Retrying `git clone https://github.com/sunspot/sunspot.git /vendor/bundle/ruby/3.0.0/cache/bundler/git/sunspot-cb781ed3afb1e1091992c51d2c44d880bb461de8 --bare --no-hardlinks --quiet` at / due to error (3/4): Errno::ENOENT No such file or directory - git
Retrying `git clone https://github.com/sunspot/sunspot.git /vendor/bundle/ruby/3.0.0/cache/bundler/git/sunspot-cb781ed3afb1e1091992c51d2c44d880bb461de8 --bare --no-hardlinks --quiet` at / due to error (4/4): Errno::ENOENT No such file or directory - git
According to the logs, git was successfully installed the step before.

I bumped into the same issue with Ruby 3.0.2 and Alpine 3.14 image. Still waiting for CI upgrade, but I locally it works with latest Docker. Alpine requires at least Docker 20.10.0. Check if CI runs recent Docker, kernel or something else like Gitlab runner.

Upgrade to a newer or different version of docker. 22.06.0-beta.0 was the next newer one for me.
In my specific case, I was trying to build a ruby:2.7.5-alpine based docker image on CircleCI. I was getting the same error, Errno::ENOENT No such file or directory - git when git was clearly installed in the Dockerfile step immediately before bundle install. It was working locally.
The docker build command is run inside of a container on CircleCI. I had chosen the latest stable docker image version docker:20.10.17-git for the container.
After reading Ivan's answer to this question, I tried a newer docker version. The only newer image listed on Docker's official images was docker:22.06.0-beta.0-git. Switching to this new image immediately fixed my problem.

Related

How can I downgrade Homebrew to an older version?

Currently I have the latest version 2.2.17, I want to downgrade to version 2.2.12.
Brew does not have a downgrade option, just an upgrade. Is the process to uninstall brew and re-install it again?
If you used the normal installation way via the install script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Then take a look at the brew install script (it has its own repo).
It downloads the actual Homebrew repo to /usr/local/Homebrew.
...
HOMEBREW_PREFIX="/usr/local"
HOMEBREW_REPOSITORY="/usr/local/Homebrew"
...
BREW_REPO="https://github.com/Homebrew/brew"
...
ohai "Downloading and installing Homebrew..."
(
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
# "git remote add" will fail if the remote is defined in the global config
execute "git" "config" "remote.origin.url" "${BREW_REPO}"
execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
...
execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"
...
}
...
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
...
The script installs the latest copy of the Homebrew repo. So the answer to "Is the process to uninstall brew and re-install it again?" would be a "NO". Instead, install it first normally, and then after, go over to /usr/local/Homebrew and checkout the version you want.
~$ cd /usr/local/Homebrew
Homebrew$ brew --version
Homebrew 2.3.0
Homebrew/homebrew-core (git revision d41d92; last commit 2020-05-29)
Homebrew$ git fetch --tags
Homebrew$ git checkout 2.2.12
Note: switching to '2.2.12'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 2ae26808a Merge pull request #7301 from Bo98/cmake-sdkroot
Homebrew$ brew --version
Homebrew 2.2.12
Homebrew$ cd /usr/local/bin
bin$ ./brew --version
Homebrew 2.2.12
Homebrew/homebrew-core (git revision d41d92; last commit 2020-05-29)
I recommend doing a brew doctor after just to make sure everything's still OK.
Then, unfortunately, Homebrew always auto-updates itself every time you install something. So it will always update the repo at /usr/local/Homebrew up again to the latest version. You can disable that by exporting HOMEBREW_NO_AUTO_UPDATE as mentioned here https://github.com/Homebrew/brew/issues/1670.
~$ export HOMEBREW_NO_AUTO_UPDATE=1
~$ brew install python#3.8
You'll need to create an alias or auto-export that env var to your bash_profile (or whatever is the equivalent for the terminal you use), so that it takes effect every time you use brew.

Bundler::Source::Git::GitCommandError when using Inquisition gem

As per the client suggestion, I am using inquisition gem in my Rails 5.0 application. I followed this link and added gem in Gemfile and ran bundle, I got the following error:
E:\rails_projects\inquisition_example>bundle Fetching
https://github.com/rubygarage/inquisition.git fatal: unable to access
'https://github.com/rubygarage/inquisition.git/': error:1407742E:SSL
routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Retrying git clone "https://github.com/rubygarage/inquisition.git"
"C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/cache/bundler/git/inquisition-40e0b17fff1501354aa91e3ff3bbb85f990b5f49"
--bare --no-hardlinks --quiet due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command git clone
"https://github.com/rubygarage/inquisition.git"
"C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/cache/bundler/git/inquisition-40e0b17fff1501354aa91e3ff3bbb85f990b5f49"
--bare --no-hardlinks --quiet in directory E:/rails_projects/inquisition_example has failed. fatal: unable to
access 'https://github.com/rubygarage/inquisition.git/':
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert
protocol version
Please help me out.
This error means that the OpenSSL version you are using in Git's libcurl is too old. GitHub only supports TLS 1.2 and 1.3, and the version of OpenSSL that libcurl is compiled with doesn't know how to negotiate those versions.
Since it looks like you're using Windows, you should update Git for Windows to the latest version, which will include an updated version of OpenSSL and libcurl so Git will work.

Bundle issue when installin gem from github

I have issue with installing gems from Github on Docker. Windows 10 pro.
Gemfile:
gem 'kaminari', git: 'https://github.com/kaminari/kaminari', branch: 'master'
Error:
Git error: command `git clone --no-checkout --quiet
"/bundle_box/cache/bundler/git/kaminari-afd5cc7513de17a7e5e6421480370a0b7ec57040"
"/bbox/bundler/gems/kaminari-27a0c850b50a"` in directory /App has failed.
If this error persists you could try removing the cache directory
'/box/cache/bundler/
git/kaminari-afd5cc7513de17a7e5e6421480370a0b7ec57040'
I try removing this cache directory. But every time same error

rails + rbenv + bundler in prod with no internet or git allowed

I have a setup in dev using rbenv with passenger and rails. In prod, I will have no internet access and not allowed to have git installed. Everything will be packaged from our local git repo and deployed via rpm. I've searched and read everything I could find, however the direction of what to use between bundle package and bundle deployment remains ambiguous to me. So here is what I am thinking of doing - please give feedback or a solution:
In dev:
install rbenv for user that will be same in prod
install ruby + bundler + passenger
put .rbenv dir in local git repo to be packaged
in rails dir, run bundle package --all
commit ./vendor/cache to git repo as part of my project
in all environments, run bundle install --local --deployment (not sure about this part goal is to have the gems, git , etc packages install to ./vender/bundle and not contact internet, but use ./vendor/cache)
gitignore ./vendor/bundle
Does this work as expected, or should I take another path?

GIT command not found on Fedora 18

I am trying to deploy a Rails application using Capistrano. My application is on a Git repository on BitBucket.
Before deploying the application I needed to install Git on the server running Fedora 18. I tried the following:
sudo yum install git
and
sudo yum install git-core
Both commands showed that Git was installed successfully, but when I try to use the git command I receive a git command not found error.
How can I install Git with Fedora 18 and make this work?
SOLVED: Although, Fedora wrote that git has been installed, it was not. I tried to re-install git, following carefully what was written in the terminal during the installation and it worked.

Resources