I have been trying to deploy meteor app (a rocketcht app
) through capistrano . For that the steps I have followed are
1. cloning the project :
This step includes cloning the project in the local computer .
2. Bundling the project :
since meteor
command takes longer time to run the project ( around 10+ min ) so we cannot afford to bundle the project during the deployment time . so as a workaround we bundle the project in local system within project directory with similar os architecture as the staging server using meteor bundle bundle.tgz
. After bundling the project we sent the bundle file to the s3 bucket .
Till these 2 steps we have not done any automation . This was a manual and one time process ( till yesterday thats what I thought until I ran into some issue which I will discuss below ) .
Now the automation comes into play . Though there are several deployment tools for meteor deployment but We decided to use capistrano for following reasons :
- We are more familiar with this tool as our previous deployment was by capistrano .
- We had already figured out the technique for multiserver deployment using aws tags which help us to deploy in server generating dynamic ip .
- MUP was one alternative but not sure how to deploy code for server having dynamic ip (
autoscaling
). - Another alternatives are galaxy , phanthom but have not tried .
The deployment with capistrano involved the following steps :
- The bundle file is pulled by the server where the code is deployed .
- Once the code is pulled , the bundle file , which is a compressed file (which was previously pushed into the s3 bucket manually ) is pulled by the server and is placed inside the project directory which is then extracted and a new directory named as
bundle
is created . - Next step includes entering inside the bundle directory and running
meteor npm install
. - Another step includes , restarting node server inside the
bundle
directory which runsnode main.js
which is managed by supervisord , a process management tool .
so the gist strategy for deployment is :
- bundle your app ( this is actually the meteor bundle command)
- Copy over your bundle to your staging server
- Start the bundle as a node-app and use supervisord to manage the node process .
So our main problem is :
The Dev team has written some code inside rocketchat/packages/rocketchat-api/server/routes.coffee
for login feature . While bundling the project along with this custom written code and starting the app with node
command this custom code does not work .
so my concern here is :
- Does
meteor build
command bundles the custom written code too ? - should we need to use
meteor
command instead of runningnode main.js
inside thebundle
directory command for those custom written code to take effect ?
capistrano task :
namespace :cf do
desc "Incremental Asset Upload"
task :s3upload do
run_locally do
execute "meteor build --directory . --architecture os.linux.x86_64"
execute "aws s3api put-object --acl public-read --bucket test --key #{fetch(:application)}/#{fetch(:stage)}/bundle --body bundle"
end
desc "Pull and deflate assets"
task :decompress do
on roles(:app) do |server|
execute "wget https://s3.amazonaws.com/#{fetch(:application)}/#{fetch(:stage)}/bundle -O /tmp/bundle"
execute "tar -xzvf /tmp/bundle.tgz -C #{release_path}/public"
execute "chmod 755 -R #{release_path}/public/bundle"
execute "cd #{release_path} && meteor npm install"
end
end
end
My process monitoring tool configuration goes as :
supervisord.conf
[program:node] environment=HOME="/home/deploy",PORT="3000",ROOT_URL="http://localhost:3000",MONGO_URL="mongodb://localhost:27017/rocketchat_staging" directory=/home/deploy/rocketchat/current/bundle command=/usr/bin/node main.js autorestart=true redirect_stderr=true user=deploy stderr_logfile = /var/log/supervisord/node_stderr.log stdout_logfile = /var/log/supervisord/node-stdout.log
Thank you in advance !!