有没有人注意到新的Rails应用程序在circleCI上似乎失败了,错误如下:
Sprockets::Rails::Helper::AssetNotFound in Home#index
The asset "application.js" is not present in the asset pipeline.
重现步骤:rails new --javascript=esbuild
,因此它将JSB绑定与ESbuild一起使用
·安装rspec
·配置CircleCI
·添加应用程序到您的循环CI管道。
·添加一个基本的hello world控制器,只打印“Hello world”
·将根路由添加到hello world控制器
·添加等级库:
require 'rails_helper'
describe "can load the homepage" do
it "should load the homepage" do
visit "/"
expect(page).to have_content("Hello world")
end
end
在app/assets/config/manifest.js中有一个文件告诉Sprockets从哪里加载资源。我尝试添加此文件
//= link_directory ../../javascript .js
(注意javascript文件夹的默认位置是在app/而不是app/assets中)
应用程序在本地工作正常,部署到Heroku也很好,我只在Circleci上看到这个错误。有人以前见过这个吗?
我的CircleCI配置如下所示:
version: 2.1 # Use 2.1 to enable using orbs and other features.
# Declare the orbs that we'll use in our config.
# read more about orbs: https://circleci.com/docs/2.0/using-orbs/
orbs:
ruby: circleci/ruby@1.0
node: circleci/node@2
browser-tools: circleci/browser-tools@1.2.3
jobs:
build: # our first job, named "build"
docker:
- image: cimg/ruby:3.1.2-browsers # use a tailored CircleCI docker image.
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
- image: redis:6.2.6
steps:
- checkout # pull down our git code.
- ruby/install-deps # use the ruby orb to install dependencies
# use the node orb to install our packages
# specifying that we use `yarn` and to cache dependencies with `yarn.lock`
# learn more: https://circleci.com/docs/2.0/caching/
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
- run:
name: Build assets
command: bundle exec rails assets:precompile
test: # our next job, called "test"
parallelism: 1
# here we set TWO docker images.
docker:
- image: cimg/ruby:3.1.2-browsers # this is our primary docker image, where step commands run.
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
- image: redis:6.2.6
- image: circleci/postgres:9.5-alpine
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # add POSTGRES environment variables.
POSTGRES_USER: circleci-demo-ruby
POSTGRES_DB: VDQApp_test
POSTGRES_PASSWORD: ""
# environment variables specific to Ruby/Rails, applied to the primary container.
environment:
BUNDLE_JOBS: "3"
BUNDLE_RETRY: "3"
PGHOST: 127.0.0.1
PGUSER: circleci-demo-ruby
PGPASSWORD: ""
RAILS_ENV: test
# A series of steps to run, some are similar to those in "build".
steps:
- browser-tools/install-chrome
- browser-tools/install-chromedriver
- checkout
- ruby/install-deps
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
# Here we make sure that the secondary container boots
# up before we run operations on the database.
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Load schema
command: bin/rails db:schema:load RAILS_ENV=test
# Run rspec in parallel
- ruby/rspec-test
# We use workflows to orchestrate the jobs that we declared above.
workflows:
version: 2
build_and_test: # The name of our workflow is "build_and_test"
jobs: # The list of jobs we run as part of this workflow.
- build # Run build first.
- test: # Then run test,
requires: # Test requires that build passes for it to run.
- build # Finally, run the build job.
1条答案
按热度按时间ghg1uchk1#
好吧,我知道了.
必须告知Circle CI配置执行esbuild,具体如下:
该命令位于yarn package脚本中,因此可以将其作为
yarn build
运行在
.circleci/config
文件中,查找作业〉测试〉步骤节您将需要在node/install-packages的步骤之后添加yarn build的此步骤
x一个一个一个一个x一个一个二个x
感谢@Archronic的加入:
找到答案了。jsbundling-rails增强了assets:precompile rake任务,仅用于生产。对于test,它增强了test:prepare任务。如果您没有运行test:prepare,那么它就依赖于您运行yarn build来确保assets在测试中可用。