I wanted to use Capistrano to deploy on my django app on my webfaction server but due to my purist tendencies, I wanted to do it in Fabric, in a way that Capistrano does. The thing that I liked most about about Capistrano is that automatically retrieves a repo's content and pushes it to a server.
The fabric recipes I have seen so far required me to do things "the git way", manually entering git commands to work with the repo, etc.
Is there a way to deploy a Django app in Fabric (or any other python package) "the Capistrano" way?
Sie Note: In case I really have to work with Capistrano, is there a way to bypass the assets precompile task and the rake db:migrate task?
Ive successfully used the scripts from here to deploy to webfaction.
If you want to bypass the assets compilation, just don't write this line in your recipe :
load 'deploy/assets'
If you don't want to run migration, just never type the migration command
cap deploy:migrate
If you want to remove some other behaviors (symlink, restart, update code to server) write chosen parts from this :
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart do ; end
task :update_code do ; end #override this task to prevent capistrano to upload on servers
task :symlink do ; end #don't create the current symlink to the last release
end
for anyone who stumbles across this, here is a capistrano recipe that is so basic :
http://ygamretuta.me/2012/07/18/deploy-django-1-4-webfaction-capistrano/
Related
I have a rake task, which extends environment, where I call MyWorker.perform_at ...
This has no effect from the rake task. It's as if it's a NO-OP.
I have verified that the same code works in the app, and in the Rails console.
I've put logging into my config/initializers/sidekiq.rb file as a sanity-check that it's getting run and doing what I expect.
Am I missing something?
Check that you are not requiring 'sidekiq/testing' or rspec-sidekiq somewhere so your jobs; That changes the way sidekiq runs so that the jobs end up in an array instead of in Redis. Some other rake task might be including something like that, or check your gemfile to make sure those are only included in the :test group.
I'm trying to deploy my Rails 4 app using Capistrano 3. I'm getting error messages in running the db:migrations (i've been sloppy, sorry). Is there a way to have Capistrano deploy the app (at least the first time) using db:schema:load?
An excerpt of my deploy.rb:
namespace :deploy do
%w[start stop restart].each do |command|
desc 'Manage Unicorn'
task command do
on roles(:app), in: :sequence, wait: 1 do
execute "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
end
end
end
I'm not sure how to override Capistrano 3's default behaviour. Can someone tell me how to add this to my script?
For first time deploys, I generally hack around it by logging into the server, cding into the release directory (which will have the deployed code at this point), and then manually running RAILS_ENV=yourenv bundle exec rake db:setup.
In Capistrano 3.10.1 with a Rails 5.1.6 application,
~/Documents/p.rails/perla-uy[staging]$ bundle exec cap staging deploy:updating
gives me enough to shell-in and run the db:structure:load or db:schema:load task manually. In the secure shell session to the host, switch to the newly created release directory and:
dclo#localhost:~/perla-uy/releases/20180412133715$ bundle install --without development test --deployment
dclo#localhost:~/perla-uy/releases/20180412133715$ bundle exec rails db:schema:load
Shelling into a (successful or failed) deploy that has tried deploy:migrate isn't quite the same.
Note: I have RAILS_ENV=production and RAILS_MASTER_KEY=... set-up by the shell login.
I cannot figure out why I am getting a 404 error at http://rachaelsalter.github.io
I am using Middleman and the middleman-deploy gem. Everything seemed to work fine with the deploy and I have an index.html file.
Any help would be very much appreciated.
You're pushing to a user repository (userName.github.io), so you need to deploy your generated code to master branch. See github pages documentation.
In your config.rb file, you must change deploy.branch variable witch is gh-pages by default, to master
activate :deploy do |deploy|
deploy.method = :git
deploy.branch = 'master'
# ... other deploy setup
end
If you're versioning your sources, you will have to move them to another branch like sources.
I'm using Codeship for continuous deployment. My app is setup so that the main app loads a few engines, and the engines isolate specific functionality. Each engine might have various rspec tests related to it's isolated functionality. Codeship spins up a copy of my app, runs a few commands, and deploys the code if everything works. Those few commands need to run all my tests. bundle exec rake or bundle exec rspec no longer work, as they only run the tests on my main container app (none of the engines).
I ended up created the following shell script that loops through the directories inside my gems directory, and calls bundle install and bundle exec rspec:
retval=0
for dir in gems/*/
do
dir=${dir%*/}
echo "## ${dir##*/} Tests"
cd gems/${dir##*/}
bundle install
if ! bundle exec rspec spec/ --format documentation --fail-fast;
then
retval=1
break
fi
cd ../../
done
exit $retval
This works well. All my tests are executed, and it exits with an error if any tests fail. In an effort to see if there was a better way to accomplish this, I tried moving this functionality into a rake tasks. I attempted a couple methods. I used the FileUtility methods to loop through the directories and the System method to call the same bundle install and bundlee exec rspec as above. The commands are called, but when it is ran from the rake tasks, their is a problem with the factories. If Engine A calls factories from Engine B, the returned values are nil. I'm calling shared factories this way (example from Engine A):
FactoryGirl.define do
factory :Model, class: EngineB::Model do
end
end
Sorry this is long winded. To sum up my questions:
1) Is the shell script a good way to manage tests? I haven't ran into any issues with it yet.
2) Do you know why calling that shell script from a rake task causes the factories to return nil values?
3) Do you know why mimicking the shell functionality in a rake tasks also results in the factories returning nil values? (probably same problem as above)
4) Is there a better way to share factories? I've placed all models that are referenced in multiple engines in one engine.
At present, I have it setup so that capistrano git pulls the latest code on production servers, bundle installs and asset precompiles it individually on each web server.
The problem that I am running into is that occationally it will take a long time and take up a lot of resources that impacts the performance on the production servers.
I am looking for guidelines on how best to do this.
If anyone has experience with this and can share their opinions, I would really appreciate it.
I am looking to see if this is a good/bad idea and what are common pitfalls I should watch out for.
I would also appreciate any link to blog post/tutorial/documentation that could help with this.
Thanks for reading.
Ankit.
Here is my work around. Try adding it in namespace :deploy
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, :except => { :no_release => true } do
unless skip_assets
%x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
run_local "bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
servers = find_servers_for_task(current_task)
port_option = port ? "-e 'ssh -p #{port}'" : ''
servers.each do |server|
%x{rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{port_option} public/assets #{user}##{server}:#{shared_path}}
end
%x{bundle exec rake assets:clean RAILS_ENV=#{rails_env}}
end
end
end
def run_local(cmd)
system cmd
if($?.exitstatus != 0) then
puts 'exit code: ' + $?.exitstatus.to_s
exit
end
end