Dependencies cache in Wercker - ruby-on-rails

I'm using Wercker on my Ruby on Rails project. My wercker.yml looks like this:
box: ruby
services:
- postgres
build:
steps:
- script:
name: Nokogiri fix
code: bundle config build.nokogiri --use-system-libraries
- bundle-install
- rails-database-yml
- script:
name: Set up db
code: bundle exec rake db:schema:load RAILS_ENV=test
- script:
name: rspec
code: bundle exec rspec
after-steps:
- slack-notifier:
url: $SLACK_URL
channel: notifications
username: werckerbot
The problem is that wercker every time download gems with bundle install instead of get them from cache. With that my build takes almost 2 minutes instead of a few seconds... How can I fix that?

Related

Travis CI Ruby exited with 1

I built a new rails app and when I have configured the .travis.yml file it exits with one all the time.
Here is my travis configuration:
language: ruby
node_js:
- 12
cache:
bundler: true
yarn: true
services:
- redis-server
sudo: required
before_install:
- sudo apt-get update
- sudo apt-get install google-chrome-stable
addons:
postgresql: '9.6'
before_script:
- psql -c 'create database product_hunt_clone_test;' -U postgres
script:
- bundle install
- bundle exec rake db:schema:load
- bundle exec rake db:test:prepare
- SECRET_KEY_BASE=a RAILS_ENV=production bundle exec rake assets:precompile
- bundle exec rake test
- bundle exec rake test:system
and here are the errors travis is giving me:
screenshot from travis console
You have apparently create the initial application using the --skip-sprockets parameter. As such, you have disable the use of the assets pipeline in your application and with that have disable the need (and possibility) to run rake assets:precompile.
If you do need assets pipeline (and thus the rails-sprockets gem), you can re-enable it by adding
gem "sprockets-rails"
to your Gemfile and uncommenting the line
# require "sprockets/railtie"
in your config/application.rb file. You would also need to create the asset files as necessary. Please refer to the documentation for the assets pipeline for details.
If you actually want to skip the assets pipeline, you can just remove the call to the assets:precompile task from your .travis.yml.
Are you correctly installing your gems (with bundle install) before executing your rake commands? Seems like you would need sprockets before compiling the assets.

Wercker CI config for rails 5.1 + reactjs with webpacker gem

I struggle setting up Wercker on a rails / Webpacker project.
I first had to add steps to install node, then another to pre-compile react packs, then to install yarn. First it was good but then I added dependencies to the project and know I'm stuck on 3 dependencies with the same error message :
ERROR in ./app/javascript/app/index.js
Module not found: Error: Can't resolve 'redux-thunk' in '/pipeline/source/app/javascript/app'
# ./app/javascript/app/index.js 5:0-32
# ./app/javascript/packs/app.js
That's happening only with redux-thunk, react-redux-i18n and react-spinkit
I've tried to add a step yarn install which passes through the process but doesn't solve the problem.
Here is my wercker.yml:
# wercker.yml
box: ruby:2.4.1
services:
- redis
- postgres
build:
steps:
- louischavane/install-phantomjs#0.0.5
- rails-database-yml
- script:
name: nokogiri tricks
code: bundle config build.nokogiri --use-system-libraries
- bundle-install
- bigtruedata/install-node#2.1.1
- akupila/yarn#0.2.0
- script:
name: yarn-install
code: yarn install
- script:
name: pre-compile react packs
code: NODE_ENV=test bundle exec rails webpacker:compile
- script:
name: run migration
code: rake db:migrate RAILS_ENV=test
- script:
name: load fixture
code: rake db:fixtures:load RAILS_ENV=test
- script:
name: run rubocop
code: bundle exec rubocop
- script:
name: test
code: bundle exec rake test RAILS_ENV=test
Found a way around adding a step to remove node modules before pre-compiling :
- script:
name: delete node modules
code: rm -rf node_modules
UPDATE
I now have a clean Wercker setup handling tests, system tests with chrome headless, rubocop, eslint and stylelint. You can find it here: https://gist.github.com/adesurirey/7c013bfa1a9bed9d56ffea54db5d6288

How to specify to Travis to use a specific bundler which I have used on local development?

I am using Travis CI for continuous development on my application.
When I push to GitHub and gitignore my my Gemfile.lock from being pushed to GitHub, then Travis will work fine and install all dependencies, but when Travis (.travis.yml) is ready to push to Heroku, I get a This Travis Build Error
Picture of the error
Heroku Build Log Error
I understand the error being its requiring the Gemfile.lock file to be pushed alongside the code, but if I push Gemfile.lock with the rest of the code to GitHub, my Travis will not build at all and will throw Bundler Error being Gemlock file corrupt. The only solution I did to solve that was to remove Gemfile.lock being pushed to GitHub.
Having figured out my problem, how do I solve this by stating the
exact bundler I want my Travis to use, or is there any other thing I
could do to solve this?
Travis (.travis.yml)
language: ruby
rvm:
- 2.2.4
env:
global:
- secure: {{ I have my travis encrypted key here }}
- secure: {{ I another travis encrypted key here }}
- DB=sqlite
- DB=mysql
- DB=postgresql
- secure: {{ I have another travis encrypted key here }}
deploy:
provider: heroku
api_key:
secure: {{ I have heroku api key encrypted key here }}
app: lawville
on:
repo: AfolabiOlaoluwa/LawVille
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
before_script:
- mysql -e 'create database strano_test'
- psql -c 'create database strano_test' -U postgres
I manipulated this by including before_install script in my travis.yml.
Here is the code:
before_install:
- gem install -v 1.10.6 bundler --no-rdoc --no-ri
- bundle _1.10.6_ install
With this script my travis file did as expected using bundler version I set in travis.

images are missing in heroku when rails project is deployed using travis

I am trying to deploy a rails project into heroku using travis. Build is successful and tests are also passing. Deployment is also successful. but when I test the heroku app, I find that image files in my app/assets/images directory are not getting displayed in the deployed application.
Here is my .travis.yml file.
language: ruby
rvm:
- 2.2.3
gemfile:
- gemfiles/Gemfile.rails-4.2.5
env:
- DB=sqlite
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- RAILS_ENV=test bundle exec rspec -f d
install:
- bundle install
deploy:
provider: heroku
skip_cleanup: true
app: <my app name>
api_key:
secure: <proper key>
on:
gemfile: gemfiles/Gemfile.rails-4.2.5
strategy: git
run:
- "rake db:migrate"
Can somebody help me understand why image files are missing. I can see them in my github application folder. but they are not getting deployed properly by travis to heroku.
thanks
I see you are usign Rails 4, are you sure to be setting serve_static_assets = true in production.rb?
Refer to Rails 4 images not loading on heroku.
Also, make sure to precompile your assets as you deploy from Travis CI. So add under deploy: run:
deploy:
...
run:
- "rake db:migrate"
- "RAILS_ENV=production bundle exec rake assets:precompile"

Is it possible to set up travis to run tests for several languages?

I have a rails project and am running tests for my JavaScript test (Jasmine) through Karma
.travis.yml file
language: ruby
rvm:
- 2.0.0
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate test
- karma start --single-run --browsers PhantomJS test/karma/config/unit.js
Travis fails saying it does not find karma. is there a way to define node_js as another language and install karma on the build VM?
It is not possible yet to have several languages on travis configuration file.
On the other hand, all environments run node.js. The following script does the trick:
language: ruby
rvm:
- 2.0.0
before_script:
- npm install karma
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate test
- karma start --single-run --browsers PhantomJS test/karma/config/unit.js
Help found on an old thread in a google group
K-Yo's answer got me moving in the right direction, but far short of success. Here is what I needed:
First in my .travis.yml:
language: ruby
rvm:
- 2.1.1
before_script:
- psql -c 'create database spokenvote_test;' -U postgres
- cp config/database.travis.yml config/database.yml
- rake db:test_prep
- npm install karma
- npm install karma-jasmine
- npm install karma-coverage
- npm install karma-phantomjs-launcher
- npm install karma-coffee-preprocessor
script:
- bundle exec rspec spec # basic for ruby
- node_modules/karma/bin/karma start config/karma.conf.js --single-run --browsers PhantomJS
Then I also placed this code in my package.json, though I'm not sure if it was needed:
"devDependencies": {
"karma": "~0.12",
"karma-jasmine": "~0.2",
"karma-coverage": "~0.2.6",
"karma-phantomjs-launcher": "~0.1.4",
"karma-coffee-preprocessor": "~0.2.1"
},
Finally, I learned that Travis is case sensitive, so:
'bower_components/jquery/dist/jquery.min.js',
in my karma.conf.js needed to be:
'bower_components/jQuery/dist/jquery.min.js',
When the language key in .travis.yml is set to node, Travis will run nvm install 0.12 at the beginning of the build. Similarly, for a Ruby project, Travis will run rvm use 2.2.2 --install --binary --fuzzy at the beginning of the build.
I've had success running both commands in a Bash build

Resources