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

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"

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.

Rails 5 - Circle CI - Heroku - Run migrations after deploy

After deploying to Heroku, I want the migrations to run after deployment. Tried following configuration in circle.yml -
deployment:
staging:
branch: <branch_name>
heroku:
appname: <appname
commands:
- heroku run rake db:migrate --app alldaydr:
timeout: 400
- bundle exec rake swagger:docs
commands:
- git push git#heroku.com:<appname> $CIRCLE_SHA1:master
- heroku run rake db:migrate --app <appname>
It deploys successfully but doesn't run migrations. Any help/idea?
Here is my configuration that works below. I have just one commands instruction and run rake migration just after push to Heroku. You can also get a hint of what's happening from the deploy logs on CircleCI.
deployment:
production:
branch: <branch-name>
commands:
- "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
- git push git#heroku.com:<appname> $CIRCLE_SHA1:refs/heads/master
- heroku run rake db:migrate --app <appname>:
timeout: 400 # if your deploys take a long time
- heroku run rake swagger:docs --app <appname>
Refer to CircleCI's documentation for more

How can I precompile assets using Travis CI?

In the rails guides they have an example on how to precompile assets with Capistrano. It is as simple as adding load 'deploy/assets' to the Capfile. I simply want to achieve the same effect, precompiling assets, while using Travis CI instead. This is what I've done so far:
script/travis.sh:
run "bundle exec rake assets:precompile"
.travis.yml:
before_install:
- chmod +x script/travis.sh
script: script/travis.sh
language: ruby
rvm:
- 2.2
deploy:
provider: heroku
When this is built on Travis it fails and I get this from the log:
$ script/travis.sh
script/travis.sh: line 1: run: command not found
The command "script/travis.sh" exited with 127.
I also want to add that my shell script knowledge is very limited.
I'm not entirely sure, but I'm leaning towards the run command not being available in the travis shell, as against Capistrano. I'd say you should probably just leave your travis.sh as:
bundle exec rake assets:precompile
And try again. Let me know the results of that

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.

inclusion filter with ruby on rails rspec on travis-ci

I'm trying to do integration testing on travis-ci. I want to be able to run an inclusion filter on travis. in a gist, I want to be able to run fast tests locally while travis-ci tests the fast tests and slow tests including internet dependent tests. I have tried using --tag ~slow_tests under .travis.yml but it gives me an error. here is my .yml file.
language: ruby
rvm:
- 1.9.3
env:
- DB=sqlite
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate spec --tag ~slow_tests
services:
- redis-server
invalid option: --tag
129
130The command "RAILS_ENV=test bundle exec rake --trace db:migrate spec --tag ~slow_tests" exited with 1.
The problem you have is that the --tag option is being interpreted by rake which has no such option. So you need a way to pass the command line options through to RSpec. You can do that with the SPEC_OPTS environment variable:
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate spec SPEC_OPTS="--tag ~slow_tests"

Resources