ruby Rails 4/5通过资产预编译测试加速

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Rails 4/5通过资产预编译测试加速相关的知识,希望对你有一定的参考价值。

      - restore_cache:
          keys:
            - v1-asset-cache-{{ arch }}-{{ .Branch }}
            - v1-asset-cache-

      - run: bundle exec rake assets:precompile

      - save_cache:
          key: v1-asset-cache-{{ arch }}-{{ .Branch }}-{{ epoch }}
          paths:
            - public/assets
            - tmp/cache/assets/sprockets
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
  build:
    environment:
      BUNDLE_GEMFILE: Gemfile
      BUNDLE_WITHOUT: "production:staging:development"

    docker:
      # specify the version you desire here
      - image: circleci/ruby:2.4.3-node-browsers
        environment:
          RAILS_ENV: test
          RACK_ENV: test
          PGHOST: 127.0.0.1
          PGUSER: ubuntu

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      - image: circleci/postgres:alpine
        environment:
          POSTGRES_USER: ubuntu
          POSTGRES_DB: rails-bootstrap_test

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "Gemfile.lock" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: bundle check --path vendor/bundle || bundle install --deployment --jobs=4 --retry=3

      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      - restore_cache:
          keys:
            - v1-asset-cache-{{ arch }}-{{ .Branch }}
            - v1-asset-cache-

      - run: bundle exec rake assets:precompile

      - save_cache:
          key: v1-asset-cache-{{ arch }}-{{ .Branch }}-{{ epoch }}
          paths:
            - public/assets
            - tmp/cache/assets/sprockets

      - run: bundle exec rake db:schema:load
      - run: bundle exec rake test test:system
Rails.application.configure do
  # ...
  # For Rails 4 we need to add those settings
  config.serve_static_files = true
  config.static_cache_control = 'public, max-age=2592000'
  config.assets.digest = true
  config.assets.debug = false

  if ENV['CI']
    config.assets.compile = false
    config.assets.js_compressor = :uglifier
  end
end

以上是关于ruby Rails 4/5通过资产预编译测试加速的主要内容,如果未能解决你的问题,请参考以下文章

加速资产:使用 Rails 3.1/3.2 Capistrano 部署预编译

ruby 调试rails资产管道js使用uglifier预编译错误

ruby 使用Capistrano 3和rsync进行本地Rails 4资产预编译

Rails 预编译供应商/资产

未使用 Rails 测试环境中的预编译资产

预编译资产 - rails 4.1.1