【问题标题】:Bundling from Github in a Dockerfile在 Dockerfile 中从 Github 捆绑
【发布时间】:2016-07-27 22:06:24
【问题描述】:

我正在尝试将我们的 Rails 应用程序移至 Docker 部署,但是我无法从 Github 参考中获取要安装的包。

使用以下 Dockerfile:

FROM ruby:2.3.0-slim

MAINTAINER Chris Jewell <chrisjohnjewell@gmail.com>

# Install dependencies:
# - build-essential: To ensure certain gems can be compiled
# - nodejs: Compile assets
# - libpq-dev: Communicate with postgres through the postgres gem
# - postgresql-client-9.4: In case you want to talk directly to postgres
RUN apt-get update && apt-get install -qq -y build-essential nodejs libpq-dev postgresql-client-9.4 --fix-missing --no-install-recommends

# Set an environment variable to store where the app is installed to inside
# of the Docker image.
ENV INSTALL_PATH /ventbackend
RUN mkdir -p $INSTALL_PATH

# This sets the context of where commands will be ran in and is documented
# on Docker's website extensively.
WORKDIR $INSTALL_PATH

# Ensure gems are cached and only get updated when they change. This will
# drastically increase build times when your gems do not change.
COPY Gemfile Gemfile
RUN bundle install

# Copy in the application code from your work station at the current directory
# over to the working directory.
COPY . .

# Provide dummy data to Rails so it can pre-compile assets.
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=pickasecuretoken assets:precompile

# Expose a volume so that nginx will be able to read in assets in production.
VOLUME ["$INSTALL_PATH/public"]

# The default command that gets ran will be to start the Unicorn server.
CMD bundle exec unicorn -c config/unicorn.rb

尝试运行docker-compose up时出现以下错误:

You need to install git to be able to use gems from git repositories. For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git

我假设这是因为 Gemfile 中的以下行:

gem 'logstasher', github: 'MarkMurphy/logstasher', ref: 'be3e871385bde7b1897ec2a1831f868a843d8000'

但是,我们也使用一些私有宝石。

在容器上安装 Git 是否可行?这将如何通过 Github 进行身份验证?

【问题讨论】:

  • 错误信息在您需要采取的步骤中似乎非常直接。有什么理由避免按照它的建议安装 git?像这样的安装程序中引用的大多数 github 存储库都是公开的,不需要登录。

标签: ruby-on-rails docker bundler docker-compose dockerfile


【解决方案1】:

在容器上安装 Git 是否可行?

在这种情况下,是的:您可以在“Using Docker to maintain a Ruby gem”看到一个示例。它的 Dockerfile 确实包含一个:

# ~~~~ OS Maintenance ~~~~
RUN apt-get update && apt-get install -y git

这将如何通过 Github 进行身份验证?

为了读取,它不需要向 GitHub 进行身份验证,即克隆。
如果您需要推回一个 gem(以发布它),然后您将需要您的 ssh 密钥(通过卷安装)。
但这里不需要。

【讨论】:

  • 在这种特殊情况下,将git-core 添加到我们apt-get install 的包中很好,但是,在某些项目中,我们还需要捆绑私有存储库。此时,我们在何处以及如何使用 SSH 密钥来执行此操作?
  • @Knightstick 通常,我仅通过 --build-args 在构建步骤中使用令牌传递
猜你喜欢
  • 1970-01-01
  • 2021-02-24
  • 2016-05-09
  • 2022-11-03
  • 2021-07-16
  • 2013-06-24
  • 1970-01-01
  • 2017-02-05
  • 2012-06-29
相关资源
最近更新 更多