在 Dockerfile 中从 Github 捆绑

Bundling from Github in a Dockerfile

我正在尝试将我们的 Rails 应用移至 Docker 部署,但是我无法从 Git 集线器参考中获取要安装的捆绑包。

使用以下 Docker 文件:

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'

但是,我们也使用了一些私有 Gem。

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

Is installing Git on the container the way to go?

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

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

How will this authenticate with Github?

它不必通过 GitHub 的身份验证即可 读取 ,即克隆。
你需要推回一个gem(发布它),然后你需要你的ssh密钥(通过卷安装)。
但这里不需要。