繁体   English   中英

在 Rails 项目的 ruby 中初始化 db 时,如何让 Bitbucket 的管道找到 rake?

[英]How do I get Bitbucket's pipeline to find rake when initializing db in ruby on rails project?

我不确定这是 bitbucket 的问题还是 docker 问题,因为 bitbucket 文件看起来很像它可能在幕后使用 docker-compose/docker。 但是,我在任何地方都找不到这个确切的问题,而且我找到的解决方案也不起作用。 我不太确定我添加的环境部分。 我在另一次尝试中添加了它以使其正常工作。 这是我的 bitbucket-pipelines.yml

image: ruby:2.5.1

environment:
  - BUNDLE_PATH=vendor/bundle

pipelines:
  default:
    - step:
        name: Bundle Install
        caches:
          - bundler
        script:
          - apt-get update
          - apt-get install -y qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x
          - export DATABASE_URL=postgresql://test_user:test_user_password@localhost/pipelines
          - bundle install --binstubs
          - bundle install --path vendor/bundle
        services:
          - redis
          - postgres
    - step:
        name: Initialize databases
        caches:
          - bundler
        script:
          - RAILS_ENV=development bundle exec rake db:setup
          - RAILS_ENV=test bundle exec rake db:test:prepare
        services:
          - postgres
          - redis
    - step:
        name: Test
        caches:
          - bundler
        script:
          - bundle exec rake
        services:
          - postgres
          - redis

definitions:
  services:
    postgres:
      image: postgres
      environment:
        POSTGRES_DB: pipelines
        POSTGRES_USER: test_user
        POSTGRES_PASSWORD: test_user_password
    redis:
      image: redis
  caches:
    bundler: vendor/bundle

当它进入initialize database步骤时,它找不到 rake 命令:

+ RAILS_ENV=development bundle exec rake db:setup
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-12.3.3 in any of the sources

只需将步骤合并在一起,将三个步骤合二为一,如下所示:

image: ruby:2.5.1

environment:
  - BUNDLE_PATH=vendor/bundle

pipelines:
  default:
    - step:
        name: Run Specs
        caches:
          - bundler
        script:
          - apt-get update
          - apt-get install -y qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x
          - export DATABASE_URL=postgresql://test_user:test_user_password@localhost/pipelines
          - bundle install --binstubs
          - bundle install --path vendor/bundle
          - RAILS_ENV=development bundle exec rake db:setup
          - RAILS_ENV=test bundle exec rake db:test:prepare
          - bundle exec rake
        services:
          - redis
          - postgres

definitions:
  services:
    postgres:
      image: postgres
      environment:
        POSTGRES_DB: pipelines
        POSTGRES_USER: test_user
        POSTGRES_PASSWORD: test_user_password
    redis:
      image: redis
  caches:
    bundler: vendor/bundle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM