【问题标题】:Append arguments to docker compose test service command将参数附加到 docker compose test service 命令
【发布时间】:2020-05-22 19:57:20
【问题描述】:

我正在尝试找出一种方法来制作一个服务,该服务将可选参数附加到服务(或条目)命令中。例如:

  testing:
    <<: *backend
    environment:
      # Use the system rails environment or default to test
      - RAILS_ENV=${RAILS_ENV:-test}
    command: bash -c "bundle exec rspec"
    ports:
      - '3000:3000'

因此,如果我运行 docker-compose run testing,它将测试我的所有规范(这很有效),但我也可以附加参数来指定文件和/或行号,例如 docker-compose run testing /specs/models/something.rb:33

编辑:我的目标是减少本地测试所需的输入量。目前将采取以下方式来指定特定的测试:

docker-compose run testing bundle exec rspec spec/models/something.rb:133

【问题讨论】:

  • 您能否编辑您的database.yml 文件以指向在Docker 中运行的数据库,并从主机运行RAILS_ENV=test bundle exec rspec ...(没有Docker)?然后你可以从docker-compose.yml文件中删除这个块。
  • @DavidMaze 是的,我们有一个数据库容器,但这与我的问题或目标无关。 RAILS_ENV=test 将 rails 环境设置为测试,这不仅仅是更改使用的数据库。这个“测试”更多的是一个例子,而不是具体的用例

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


【解决方案1】:

答案是entrypoint。设置服务如:

testing:
<<: *backend
environment:
  # Use the system rails environment or default to testing
  - RAILS_ENV=${RAILS_ENV:-test}
entrypoint: ["bundle", "exec", "rspec"]
ports:
  - '3000:3000'

然后运行一个特定的测试docker-compose run testing spec/models/something.rb:139

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    • 1970-01-01
    相关资源
    最近更新 更多