gpt4 book ai didi

ruby-on-rails-5 - circleci 在 ruby​​ on rails 中的集成

转载 作者:行者123 更新时间:2023-12-02 02:52:31 25 4
gpt4 key购买 nike

开始为 circleci 创建配置文件。这是我在 circleci 文件夹下创建的配置文件(.circleci -> config.yml)。

  version: 2.0
jobs:
build:
working_directory: ~/electrik_backend
docker:
- image: circleci/ruby:2.4.1-node-browsers
- image: postgres:9.6.2-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres_test
steps:
- checkout

# Bundle install dependencies
- run:
name: Install dependencies
command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs 4 --retry 3

# Restore bundle cache
- restore_cache:
keys:
- rails-demo-{{ checksum "Gemfile.lock" }}
- rails-demo-

# Store bundle cache
- save_cache:
key: rails-demo-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle

- run:
name: install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.3.0
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:5432 -timeout 1m

# Setup the database
- run: bundle exec rake db:create db:migrate
- run: rails db:test:prepare
- run: rspec

直到数据库一切正常,但在设置数据库时出现错误,因为 rake 已中止!
无法加载
Rails.application.database_configuration:
无法加载数据库配置。没有这样的文件 - ["config/database.yml"]
。我的 config.yml 文件是

    development:
adapter: postgresql
encoding: unicode
database: electrik_development
host: localhost
pool: 5
username: postgres
password: test123

test:
adapter: postgresql
encoding: unicode
database: electrik_test
host: localhost
pool: 5
username: postgres
password: test123

最佳答案

修改数据库设置并运行测试。

  # Setup the database
- run: mv config/database.yml.sample config/database.yml
- run: RAILS_ENV=test bundle exec rake db:create
- run: bundle exec rake db:setup

# Run the tests
- type: shell
command: |
bundle exec rspec --profile 10 \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)

我更喜欢为 CircleCI 设置主机 127.0.0.1

关于ruby-on-rails-5 - circleci 在 ruby​​ on rails 中的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51480370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com