2013-11-03 20:30:48,342 [INFO] (30173 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: /usr/bin/ruby1.9 /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Command failed with status (): [/usr/bin/ruby1.9 /usr/bin/rake assets:prec...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Rake task failed to run, skipping asset compilation.
How do I precompile assets on AWS Elastic Beanstalk ?
I am getting following error
Precompilation of assets can be done at deployment time, and to do it, go to the root of your Rails project and create a .ebextensions directory with a .config file in it. You can specify precompilation there. I'm running a Rails app with Elastic Beanstalk and had problems with fonts not being shown. Here's my .ebextensions/ruby.config file:
packages:
yum:
git: []
container_commands:
01_assets:
command: RAILS_ENV=production bundle exec rake assets:precompile
leader_only: true
You can customise the system by running scripts before or after your application deployment.
Basically, you need to create a .ebextensions directory in your source code and insert your commands and customisation steps in a YAML syntax.
The documentation explains the details.
Beware that these commands are run as 'root' with no environment variable setup. If you need variables like PATH or other, it is up to you to position them.
Here is a sample I wrote for an application which required a NodeJS module installation from the source.
packages:
yum:
gcc: []
gcc-c++: []
container_commands:
10_pre_install_sqlite3:
command: "/opt/elasticbeanstalk/node-install/node-v0.10.21-linux-x64/bin/npm install sqlite3#2.1.16 --build-from-source"
cwd: "/tmp/deployment/application"
env:
HOME: "/root"
PATH: "/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin"
Related
I have CodeDeploy pull code from my GitHub repo. In the deployment Commit ID (for GitHub) I have specified the Commit ID that I want to deploy. My repo has the following structure:
my-service/
README.md
.gitignore
scripts/
deploy.sh
src/
<lots of code here>
pm2.dev.json
appspec.yml
My appspec.yml file looks like:
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu
hooks:
BeforeInstall:
- location: scripts/deploy.sh
timeout: 300
runas: root
My scripts/deploy.sh looks like:
sudo npm install pm2 -g
pwd
pm2 start /home/ubuntu/my-service/pm2.dev.json
When I run the CodeDeployment deployment for this, it fails with the following error:
Script at specified location: scripts/deploy.sh run as user root failed with exit code 1
When I look at the logs I see:
LifecycleEvent - BeforeInstall
Script - scripts/deploy.sh
[stderr]npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
[stdout]changed 182 packages, and audited 183 packages in 8s
[stdout]
[stdout]12 packages are looking for funding
[stdout] run `npm fund` for details
[stdout]
[stdout]found 0 vulnerabilities
[stdout]/opt/codedeploy-agent
[stderr][PM2][ERROR] File /home/ubuntu/my-service/pm2.dev.json not found
Sure enough when I look in /home/ubuntu/my-service, I do not see a pm2.dev.json file, because this server had been manually configured several weeks ago before a pm2.dev.json file was added to the project. I would have expected CodeDeploy to have written whats in the repo to the server under /home/ubuntu.
Can anyone spot anything wrong with my appspec.yml or other configuration? Could it be a bad GitHub setup?
Had to change BeforeInstall to Install.
BeforeInstall runs before it copies over the source code (specified under files/source). But Install run just after that copy occurs, hence files will be available on the file system.
I'm using the directions provided here to try and deploy static code from a github push to an s3 bucket. The problem is on a build I get the following errors:
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/home/travis/.rvm/gems/ruby-2.4.1#global/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
The command "rake" exited with 1.
It seems since I don't have a language set that I am defaulting to ruby and it is trying to build with a makefile. Thing is: I don't have any code to build. I don't need to do anything in any language. Just upload the code to S3. So is there a way to not run an actual build and have this work?
My .travis.yml looks like:
deploy:
provider: s3
access_key_id: myaccesskey
secret_access_key:
secure: myverylongsecurysecretkey
bucket: searchlist.org
acl: public_read
on:
repo: myuser/myrepo
For historical reasons, Travis CI assumes your build is a Ruby app/lib. If your repo requires something else, you need to override these defaults.
Either
language: generic # no-frills build
⋮
or
# Ruby, but override default steps
install: skip
script: skip
⋮
I am using the following configurations in my deploy.rb file for capistrano:
require 'bundler/capistrano'
require 'rvm/capistrano'
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :default_environment, {
'PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194/bin:/home/deployment/.rvm/bin:$PATH",
'RUBY_VERSION' => 'ruby 1.9.3',
'GEM_HOME' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'GEM_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'BUNDLE_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
}
But when I run cap deploy:update I get this:
* executing "cd /var/www/currienet/marketplace/releases/20120928140140 && /home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle install --gemfile /var/www/currienet/marketplace/releases/20120928140140/Gemfile --path /var/www/currienet/marketplace/shared/bundle --deployment --quiet --without development test"
That is, it's not setting the bundle path (the --path argument) to what I want it to be.
I've tried a number of tutorials, including the rvm capistrano tutorial but nothing seems to work. It continues to use the capistrano default.
Capistrano also creates an application with the following .bundler/config
BUNDLE_FROZEN: '1'
BUNDLE_PATH: /var/www/currienet/marketplace/shared/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_WITHOUT: development:test
Development Machine: Windows 7, bundler (1.0.22), capistrano (2.12.0), rvm-capistrano (1.2.7), rails (3.2.8), (no rvm)
Production: Debian, bundler (1.2.1) (no capistrano), (no rvm-capistrano), rails (3.2.8), rvm 1.16.5
Thanks to Joseph Holsten's blog I was able to ascertain my problem was I was not defining the bundler variables in my deploy.rb before I required 'bundler/capistrano'. I also needed to define the bundle_dir variable, to create code that looks like the following:
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :bundle_dir, "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
require 'bundler/capistrano'
I have a problem with Capistrano deploying to a server with RVM and gemsets
executing `deploy:assets:precompile'
* executing "cd /var/app/releases/20111229233555 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
*** [err ::] rake aborted!
*** [err ::] Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
*** [deploy:update_code] rolling back
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2#mygemset' -c 'cd /var/app/releases/20111229234715 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
This is my Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_bin_path, "$HOME/.rvm/bin"
set :rvm_ruby_string, '1.9.2#mygemset'
set :rvm_type, :user
load 'deploy/assets'
When I log in as the very same user which is used by Capistrano the failing command is executed without any problems.
It seems that Capistrano is using some other environment.
Here is my ~/.rvmrc file:
rvm_gemset_create_on_use_flag=1 rvm_trust_rvmrcs_flag=1
Is there a way how to check which ruby and gemset is used at the execution time?
node.js is and V8 are installed on the system, and all needed gems are in Gemfile:
here is my rvm info:
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "x86_64-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]"
homes:
gem: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset"
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset/bin/rake"
setting up PATH in the deploy.rb solved this issue:
default_environment['PATH'] = "/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH"
it's a Gentoo distribution and the PATH var seems to be empty when using cap deploy, so I copied the content of server PATH and now it works
This issue went away for me when I installed nodejs (using apt-get) on my server. As I stated in this Stackoverflow answer, it's the most practical choice because you don't need to include any dependencies in your Gemfile.
While trying to do an assets:precompile for a production website I've encountered this error for the first time.
rake assets:precompile undefined method directory? for nil:NilClass
I have successfully updated the website and done a assets:precompile many times before.
The full example:
# RAILS_ENV=production rake assets:precompile --trace
/usr/local/rvm/gems/ruby-1.9.2-p290#pm/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/gems/ruby-1.9.2-p290#pm/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
rake aborted!
undefined method `directory?' for nil:NilClass
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I'm looking forward to someone's insight in this one, I've been racking my brain and Googling answers for hours.
This is what happens when the file system can't find one of the assets it thinks its supposed to precompile. This happened to me when my VM could not find one of the files in my shared folder (Weird VMware issue where it appeared in the directory listing but the file did not actually exist)
I had created a symbolic link to a non-existent file by mistake in the assets/javascript directory. Removing the link fixed the problem. Note that I do have other links in the assets directory so links in general are not a problem.
In my case, I had this issue when deploying an application in Heroku.
And one of my files was symlinked to somewhere outside the GIT repository, so the file was not present int 'master'.
I then had to remove the symbolic link (rm .../file) then copy the original file (cp file1 .../file) and finally add it to the repository (git -a -m "Added a forgotten file")