【问题标题】:Ruby + Alpine + Docker: git cannot be found when it's installed?Ruby + Alpine + Docker:安装时找不到git?
【发布时间】:2021-09-13 19:08:26
【问题描述】:

我有一个使用 Ruby 3 的 Rails 应用程序,我使用 Docker 部署它。在我的 Gemfile 中,我正在通过 github 安装 gem sunspot_rails,因为最新的官方版本不适用于 Ruby 3:

git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'sunspot_rails', github: 'sunspot/sunspot', glob: 'sunspot_rails/*.gemspec'

在我的生产 Dockerfile 中,我有一个安装所需 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

在我的本地机器上,这工作正常。

但是,当我尝试在我的 CI/CD 管道(使用无人机)中构建映像时,我收到一个错误,提示找不到 git:

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

根据日志,上一步安装git成功了。

【问题讨论】:

    标签: ruby-on-rails ruby docker dockerfile alpine


    【解决方案1】:

    我在 Ruby 3.0.2 和 Alpine 3.14 映像中遇到了同样的问题。仍在等待 CI 升级,但我在本地使用最新的 Docker。 Alpine 至少需要 Docker 20.10.0。检查 CI 是否运行最近的 Docker、内核或其他类似 Gitlab runner 的东西。

    【讨论】:

      猜你喜欢
      • 2020-03-20
      • 2013-08-25
      • 2016-01-30
      • 2019-07-20
      • 2016-11-28
      • 1970-01-01
      • 2018-03-24
      相关资源
      最近更新 更多