WebFaction
Community site: login faq

I have a rails 4 application that I am trying to deploy on webfaction. The app resides on bitbucket. Also, as per the webfaction documents, the app has to be deployed in the '/home/username/webapps/app' path. I have all my database.yml setting(for all envs) in secrets.yml which has been copied to the shared_path/config.

As per the documentation specified http://docs.webfaction.com/software/rails.html, the some environment variables have to be set. Webfaction needs you to set the env variables which are destroyed after the ssh session is over. I have tried to set them in the 'set_env_variables' task.

the directory structure is as:

$ pwd
/home/username/webapps/appname
$ ls
bin  gems  hello_world  lib  nginx  releases  scm  shared  src  tmp
$ls gems/
bin  build_info  cache  doc  extensions  gems  specifications
$ ls gems/gems/
actionmailer-4.1.8         bundler-1.7.9               jbuilder-2.2.5      rack-test-0.6.2        sass-rails-4.0.5       tilt-1.4.1 ...
$ cd hello_world/
[hello_world]$ bundle
-bash: bundle: command not found
$ cd ..
$ pwd
/home/username/webapps/appname
$ export PATH=$PWD/bin:$PATH
$ export GEM_HOME=$PWD/gems
$ export RUBYLIB=$PWD/lib
$ cd hello_world/
$ bundle
Using rake 10.4.2
...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

It specifies that we need to set the env variables.

Here 'hello_world' is a sample rails application that webfaction has provided. I would be removing it. nginx-passenger are provided too. My deployment script is as

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'

set :domain, 'webabc.webfaction.com'
set :deploy_to, '/home/username/webapps/appname'
set :repository, 'git@bitbucket.org:username/appname.git'
set :branch, 'master'

set :shared_paths, ['config/secrets.yml', 'log', 'tmp']
set :user, 'ssh-username'    # Username in the server to SSH to.

task :environment do
end

task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/tmp"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/tmp"]

  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]

  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]

  queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
  queue  %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/secrets.yml'."]
end

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    invoke :'set_env_variables'
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    to :launch do
      queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
      queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
      invoke :restart
    end
  end
end

desc "Set the environment variables."
task :set_env_variables => :environment do
  queue! "cd /home/username/webapps/appname"
  queue! "export GEM_HOME=$PWD/gems"
  queue! "export RUBYLIB=$PWD/lib"
  queue! "export PATH=$PWD/bin:$PATH"
  queue! "export LD_LIBRARY_PATH=$HOME/lib/"
end

When I do 'mina deploy --verbose --trace', I get

** Invoke deploy (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute deploy
** Invoke set_env_variables (first_time)
** Invoke environment 
** Execute set_env_variables
** Invoke git:clone (first_time)
** Execute git:clone
** Invoke deploy:link_shared_paths (first_time)
** Execute deploy:link_shared_paths
** Invoke bundle:install (first_time)
** Execute bundle:install
** Invoke rails:db_migrate (first_time)
** Execute rails:db_migrate
** Invoke rails:assets_precompile (first_time)
** Execute rails:assets_precompile
** Invoke deploy:cleanup (first_time)
** Execute deploy:cleanup
** Invoke restart (first_time)
** Invoke environment 
** Execute restart

-----> Creating a temporary build path
   $ touch "deploy.lock"
   $ mkdir -p "$build_path"
   $ cd "$build_path"

   Setting environment variables
   $ cd /home/username/webapps/appname
   $ export GEM_HOME=$PWD/gems
   $ export RUBYLIB=$PWD/lib
   $ export PATH=$PWD/bin:$PATH
   $ export LD_LIBRARY_PATH=$HOME/lib/

-----> Fetching new git commits
   $ (cd "/home/username/webapps/appname/scm" && git fetch "git@bitbucket.org:username/appname.git" "master:master" --force)

-----> Using git branch 'master'
   $ git clone "/home/username/webapps/appname/scm" . --recursive --br       Cloning into '.'...
   $ git clone "/home/username/webapps/appname/scm" . --recursive --branch "master"
   done.

-----> Using this git commit

   $ git --no-pager log --format='%aN (%h):%n> %s' -n 1
   Prasad Surase (ce1654d):
   > Some git commit message
   $ rm -rf .git

-----> Symlinking shared paths
   $ mkdir -p "./config"
   bash: line 130: bundle: command not found
   $ mkdir -p "."
   $ rm -rf "./config/secrets.yml"
   $ ln -s "/home/username/webapps/appname/shared/config/secrets.yml" "./config/secrets.yml"
   $ rm -rf "./log"
   $ ln -s "/home/username/webapps/appname/shared/log" "./log"
   $ rm -rf "./tmp"
   $ ln -s "/home/username/webapps/appname/shared/tmp" "./tmp"

-----> Installing gem dependencies using Bundler
   $ mkdir -p "/home/username/webapps/appname/shared/bundle"
   $ mkdir -p "./vendor"
   $ ln -s "/home/username/webapps/appname/shared/bundle" "./vendor/bundle"
   $ bundle install --without development:test --path "./vendor/bundle" --deployment
!     ERROR: Deploy failed.

-----> Cleaning up build
   $ rm -rf "$build_path"
   Unlinking current
   $ rm -f "deploy.lock"
   OK

!     Command failed.
   Failed with status 19

The https://community.webfaction.com/questions/5186/capistrano-cant-find-bundle link specifies the solution for capistrano deployment script. How can i fix it for mina?

asked 13 Dec '14, 04:56

prasad surase
1113
accept rate: 0%

edited 16 Dec '14, 16:50


It sounds like your question is, "why are the environment variables not being set correctly even though I've set them in the set_env_variables task?". This seems like more of a question for the Mina community, since we're not very familiar with mina and haven't used it before.

That said, if I had to take a guess, it looks like you're running invoke :set_env_variables immediately before restarting the server - but that needs to actually happen earlier in the queue. It definitely should come before the invoke :'bundle:install' task, and probably be the very first thing done.

Are you able to see the bash script produced by mina and run on the server? Where do those export lines appear? Ideally, they should be appearing right at the top of the script.

permanent link

answered 15 Dec '14, 07:15

ryans ♦♦
5.0k93360
accept rate: 43%

I moved the 'set_env_variables' task from the 'launch' block to 'deploy'. The error seems to be because the task isn't specified in single quotes. Thanks.

(15 Dec '14, 08:18) prasad surase
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×32
×6

question asked: 13 Dec '14, 04:56

question was seen: 3,542 times

last updated: 16 Dec '14, 16:50

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM