【发布时间】:2020-09-28 12:17:07
【问题描述】:
我正在尝试按照 buildkite here 给出的示例使用 Docker 和 docker-compose 在 buildkite 上为 Rails 应用程序设置测试环境
作为 Dockerfile 的一部分,我们正在编译应用程序上的资产,这些资产应该编译为 public/packs-test/,我们可以在 Dockerfile 中使用下面该文件中的 ls 来确认此输出。我们看到RUN ls /app/public 的输出包含 packs-test 目录
当 docker-compose 由 buildkite 通过命令运行时
docker-compose -f docker-compose.yml run -e RAILS_ENV=test --rm app /bin/sh -e -c 'ls public' 但是它不包括 packs-test 目录。
这意味着当我们运行规范时,它们会尝试在每个容器上重新编译。
如果我们在本地尝试此操作,但它确实包含预期的输出,因此不确定是否有可能通过他们使用的 Elastic 堆栈设置阻止此操作在 buildkite 上工作?
我们是否在资产预编译中错过了通过 docker compose 使该目录在容器中可用的步骤?
对此的任何见解都会非常感激
# Dockerfile
FROM ruby:2.5.1
# Lets us use "source"
SHELL ["/bin/bash", "-c"]
EXPOSE 5000
ENV RAILS_ENV=test
# Node/Yarn stuff
ENV NODE_VERSION 10.15.3
ENV YARN_VERSION 1.16.0
# Node, needed for asset pipeline
RUN curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | tar --strip-components=2 -xJ -C /usr/local/bin/ node-v$NODE_VERSION-linux-x64/bin/node
RUN curl https://www.npmjs.com/install.sh | bash
# Install Yarn
RUN npm install -g "yarn@$YARN_VERSION"
WORKDIR /app
# Install Rubygems first
ADD Gemfile Gemfile.lock /app/
RUN gem install bundler \
&& bundle install -j 4
# Install npm libraries next
ADD package.json yarn.lock /app/
RUN yarn install --frozen-lockfile
# Now add the rest of your code
ADD . /app/
RUN RAILS_ENV="test" bundle exec rails assets:precompile
RUN ls /app/public
CMD ["rails", "server", "-p", "5000"]
#docker-compose.yml
version: '3'
services:
app:
build: .
depends_on:
- db
- redis
# This mounts the current Buildkite build into /app, ensuring any
# generated files and artifacts are available to the buildkite-agent on
# the host machine (outside of the Docker Container)
volumes:
- "./:/app"
# env_file:
# - ".env.example"
environment:
REDIS_URL: redis://redis
ports:
- "5000:5000"
db:
image: postgres:10
redis:
image: redis
【问题讨论】:
标签: ruby-on-rails docker docker-compose buildkite