Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add capistrano3 #616

Closed
wants to merge 1 commit into from
Closed

Conversation

v-fedorov
Copy link
Contributor

Adds updated commands for capistrano3

remove database_yml command
@tvdeyen
Copy link
Member

tvdeyen commented Aug 5, 2014

Hey @v-fedorov
I guess you already using this in production and can confirm that this is working?
Since I don't have a chance to test this, I will merge this in, if you can confirm that this is working in production.

@tvdeyen tvdeyen added this to the 3.1 milestone Aug 5, 2014
@v-fedorov
Copy link
Contributor Author

I haven't had a chance to test all of them on production but the new markup should be correct.
here is the following that I can confirm are working.

shared_folders:create
shared_folders:symlink
db:seed
db:dump

I'm not 100% on the imports and exports, its been a little while since I tested these but I will give it another look.
Also if you noticed I removed the task for creating the database.yml file because I couldn't figure out how the new CLI ask commands worked.

I will go through these again tonight and give you a definite by the time its morning for you :)

@tvdeyen
Copy link
Member

tvdeyen commented Aug 19, 2014

Hi @v-fedorov

I tried to test this locally in the github.com/magiclabs/alchemy3-demo, but could not get this working.

I upgraded to capistrano 3 following this guide: http://capistranorb.com/documentation/upgrading/

The tasks cap alchemy:db:dump failed with having no Gemfile. Looking in the logs reveals, that the current_path (I also tried release_path) return nil:

INFO[dc857da4] Running bundle exec rake alchemy:db:dump on server1904.railsvserver.de
DEBUG[dc857da4] Command: cd  && ( DUMP_FILENAME=db/dumps/2014-08-18-23-28.sql RAILS_ENV= bundle exec rake alchemy:db:dump )
DEBUG[dc857da4]     Could not locate Gemfile
cap aborted!

Other tasks have these problems as well.

I guess something is missing, either in the upgrade guide or in the way we load/initialize the capistrano tasks in Alchemy.

This is my local Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

require 'capistrano/rails'
require 'alchemy/capistrano3'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

This my deploy.rb file:

# config valid only for Capistrano 3.1
lock '3.2.1'

set :application, 'alchemy3-demo'
set :repo_url,    'git://github.com/magiclabs/alchemy3-demo.git'
set :branch,      :stable

role :app, %w{[email protected]}
role :web, %w{[email protected]}
role :db,  %w{[email protected]}

set :deploy_to, '/var/www/alchemy-edge-demo'

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart
end

Do you have a sample app where these tasks are working? That would be great.

Thanks

@v-fedorov
Copy link
Contributor Author

This is my Capfile (The alchemy capistrano3 tasks are added locally)

# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/thin'
#require 'alchemy/capistrano3'
set :application, "demo"
set :scm, :git
set :repo_url, "[email protected]:demo/demo.git"
set :branch, "master"
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

I think adding

require 'capistrano/rbenv'

or

require 'capistrano/rvm'

here is my gemfile for reference

source 'https://rubygems.org'
gem 'rails', '4.0.3'
gem 'alchemy_cms', github: 'magiclabs/alchemy_cms', branch: '3.0-stable'
gem 'alchemy-devise', github: 'magiclabs/alchemy-devise', branch: '2.0-stable'
gem 'mysql2'
gem 'sass-rails', '~> 4.0.0'
gem 'bootstrap-sass', '~> 3.1.1'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'capistrano', '~> 3.0', require: false, group: :development
gem 'thin'
gem 'pry'

group :development do
  gem 'capistrano-rails', require: false
  gem 'capistrano-bundler', require: false
  gem 'capistrano-rbenv', require: false
  gem 'capistrano-thin', require: false
end

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  gem 'sdoc', require: false
end

@tvdeyen tvdeyen self-assigned this Aug 19, 2014
@tvdeyen
Copy link
Member

tvdeyen commented Aug 19, 2014

Thanks, I having a look into it right now. Got it working somehow now.

I guess capistrano 3 is very buggy or I am getting something wrong:

cap -T

returns errors, with database adapter not specified. Debugging the Rails.env gives test O.O

while running:

cap production -T

works. 👏

But this is not of our concern. Will have the capistrano3 support soon.

Thanks for your help so far.

@tvdeyen
Copy link
Member

tvdeyen commented Aug 21, 2014

Ok. I it working now.

I started to refactor the code even more to meet Capistrano DSL.

Will publish a new branch soon.

@tvdeyen
Copy link
Member

tvdeyen commented Aug 22, 2014

Since I don't have the time in the moment to finish this task I will write down what I have achieved for now. I don't think, that supporting Capistrano 3 is not critical at the moment. Capistrano 2 is still serving well.

If anyone needs to use Capistrano 3, then please help us implementing this and keep this in mind:

1. We need to find a better way to get/set Alchemy mount point.

We use the mount point to create the picture cache folder, to avoid possible naming issues. The folder is simply called pictures and stays in public folder. So, we thought it was a good idea to "namespace" the folder depending from Alchemy's mount point. We could have used alchemy, but because the folder is in the public space, we didn't want to allow to smell Alchemy (http://hawksworx.com/blog/i-can-smell-your-cms-a-talk-at-fronteers/)

But, do we really need this? Because, if we keep it, we need to load up the whole environment on every cap deploy (what even causes Capistrano 3 to break somehow). So we can't load up the environment anymore. It was bad practice anyway.

A Possible solution:

We ask the user about the mount point, but this only has to happen once, because we don't want to bother the user to enter the Alchemy mount point on every single deploy. So, let's store it in a Capistrano variable (alchemy_mount_point). Then, we need either to tell all users to update their deploy.rb files (they have to anyways, while upgrading to Capistrano 3), or we need to find a way to inject this into the deploy.rb file while cap install.

Fine.

2. Use linked_dirs and linked_files

Capistrano 3 has a fancy new feature (linked_dirs and linked_files), that helps to keep shared folders upon deploys. Great, Alchemy does have shared folders, that need to be synced on every deploy. So let's embrace this new feature and remove alchemy:shared_folders tasks.

Important notice: The shared Alchemy folders include the above mentioned picture cache folder, that is dependent from Alchemy's mount point. So, we need to find a solution for 1. and then refactor this whole shared folder tasks (https://github.com/magiclabs/alchemy_cms/blob/master/lib/alchemy/capistrano.rb#L19-L53)

Also important: We need to ensure, that using linked_dirs and linked_files do not overwrite existing settings from the host app. I don't know if Capistrano handles this and we can just use

set :linked_files, %w(config/database.yml)

or if we need to ensure to append them like this:

set :linked_files, -> {
  fetch(:linked_files, []) + %w(config/database.yml)
}

3. Remove or keep creating of database.yml?

We have a task to create the database.yml file while setting up (installing) the Capistrano deploy receipt. Is this good, or does this belong into the main app and the developer has to take care of this? We think, this is such a crucial security thing to be aware of, we wanted this to be in the core. But maybe a official Capistrano plugin would be a better solution?

Anyhow. I published my branch, based on the work of @v-fedorov

https://github.com/magiclabs/alchemy_cms/tree/capistrano3

Feel free to contribute.

Thanks 💯

@tvdeyen tvdeyen removed their assignment Aug 22, 2014
@tvdeyen tvdeyen removed this from the 3.1 milestone Aug 22, 2014
@tvdeyen
Copy link
Member

tvdeyen commented Aug 22, 2014

One additional thought:

We should remove the Capistrano 2 support with 3.1 then.

@v-fedorov
Copy link
Contributor Author

Thomas, great thoughts.
I currently have an alchemy app being shipped through capistrano 3 so I will see if i can make some updates.

@tvdeyen tvdeyen added this to the 3.1 milestone Aug 22, 2014
@tvdeyen tvdeyen mentioned this pull request Sep 3, 2014
@tvdeyen tvdeyen modified the milestone: 3.1 Nov 25, 2014
@tvdeyen
Copy link
Member

tvdeyen commented Jan 8, 2015

I refactored the Mount Point reader, so 1.) should be obsolete.

@tvdeyen
Copy link
Member

tvdeyen commented Apr 13, 2015

This PR is stalled. I'll close this for now. Please feel free to open a new one, if needed.

@tvdeyen tvdeyen closed this Apr 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants