如何在Rails项目中使用rails engine, 如何在CI中配置submodule


以gem的形式添加在Gemfile中
# Engine
gem 'database_core', path: 'vendor/engines/database_core'
接下来我们应该每天都尝试拿最新的engine代码到本地
# If you first clone this project, please run this command in terminal
> git submodule update --init --recursive

# Every day should pull the latest updates from the remote repository
> git pull
> git submodule update --remote


从 GitLab 8.0 开始,GitLab CI 就已经集成在 GitLab 中,我们只要在项目中添加一个 .gitlab-ci.yml 文件,然后添加一个 Runner,即可进行持续集成. 接下来,看看gitlab CI 文件的具体写法:
image: ruby:2.4.1

services:
  - postgresql:alpine
  - redis:alpine

variables:
  POSTGRES_DB: test
  POSTGRES_USER: gitlab
  POSTGRES_PASSWORD: ''

stages:
  - build
  - test

cache:
  paths:
    - .bundle
    - cache/

before_script:
  - export SECRET_KEY_BASE=test
  - cp config/database.ci.yml config/database.yml
  - cp config/secrets.yml.example config/secrets.yml
  - apt-get update -qy
  - apt-get install -y nodejs
  - eval `ssh-agent -s`
  - ssh-add /home/gitlab-runner/.ssh/id_rsa
  - mkdir ~/.ssh
  - chmod 700 ~/.ssh
  - ssh-keyscan -H gitlab.domain.com >> ~/.ssh/known_hosts
  - git submodule init
  - git submodule update
  - gem install bundler
  - bundle install --path /cache
  - bundle exec rake db:reset RAILS_ENV=test

rspec:
  script:
    - bundle exec rspec spec/

rubocop:
  script:
    - bundle exec rubocop
数据库配置文件 - config/database-ci.yml
common: &common
  adapter: postgresql
  encoding: utf8
  password:

test: &test
  <<: *common 
  host: postgres_host 
  database: project_test