Deploying application updates
Relevant selection for this article:
In the previous step, you deployed an application to your production server for the first time. But what do you do when you have updated your app, and need to deploy updates? You will learn that on this page.
Transferring latest code
. Build and upload new package
In order to provide you appropriate instructions, please choose your Meteor version:
Inside your application's code directory, on your local computer, use the meteor bundle
meteor build
command to create a Meteor package tarball of the latest application code.
local-computer$ meteor bundle package.tar.gz
local-computer$ meteor build --server-only ../new_package && mv ../new_package/*.tar.gz ./package.tar.gz
Copy the package to your production server, for example using scp
:
local-computer$ scp -i your_ec2_key.pem package.tar.gz myappuser@yourserver.com:
local-computer$ scp package.tar.gz myappuser@yourserver.com:
Replace myappuser
with name of the application's OS user account.
. Login to the server as the application's user
On Cloud 66, the firewall is closed by default for your security. To ssh into your server, you must first open a temporary connection:
Login to your server with SSH:
local-computer$ ssh -i your_ec2_key.pem myappuser@yourserver.com
local-computer$ ssh myappuser@yourserver.com
Replace myappuser
with name of the application's OS user account.
. Extract package
Extract the package to a temporary location, for example /var/www/yourapp/tmp
.
$ mkdir -p /var/www/myapp/tmp $ cd /var/www/myapp/tmp $ tar xzf ~/package.tar.gz
Replace myapp
and myappuser
with your app's name and your app user account's name.
The extracted package is now located in /var/www/myapp/tmp/bundle
.
. Copy over Passengerfile.json
The Passengerfile.json that you created for the app is not inside the extracted package, so copy it over.
$ cp /var/www/myapp/bundle/Passengerfile.json /var/www/myapp/tmp/bundle/
. Pull latest code from Git
Go to your application's code directory on the server, then use Git to pull the latest code:
$ cd /var/www/myapp/code $ git pull
Prepare application
. Switch to the appropriate Ruby interpreter
If you have multiple Ruby interpreters on your system, then you must ensure that your shell has activated the same Ruby interpreter that you used when you first deployed your app.
For example, if you are using RVM to manage Ruby interpreters, run the following (assuming your app is supposed to use Ruby 2.5.1).
$ rvm use ruby-2.5.1
. Install app dependencies
Your application's gem dependencies may have changed, so we should install any updated gem dependencies. Run:
$ bundle config set --local deployment 'true'
$ bundle config set --local without 'development test'
$ bundle install
Your application's npm dependencies may have changed, so we should install any updated npm dependencies while removing any now-extraneous dependencies. Run:
$ npm install --production $ npm prune --production
Your application's npm dependencies may have changed, so we should install any updated npm dependencies while removing any now-extraneous dependencies. Run:
$ cd /var/www/myapp/tmp/bundle/programs/server $ npm install --production $ npm prune --production
Your application's dependencies may have changed. Please install them now. How to do that depends on your application, so any instructions are outside the scope of this document.
. Compile Rails assets and run database migrations
If your app is a Rails app, then you need to compile the latest Rails assets and run any database migrations. If your app is not a Rails app, please skip to the next step.
$ bundle exec rake assets:precompile db:migrate RAILS_ENV=production
Activate application updates
Passenger may still be serving an old instance of your application. Now that all application updates have been prepared, it is time to activate the newly uploaded application package.
Rename the old application directory to something different, and move the new application directory to where the old application directory was:
$ mv /var/www/myapp/bundle /var/www/myapp/bundle.old $ mv /var/www/myapp/tmp/bundle /var/www/myapp/bundle
Tell Passenger to restart the application so that the updates take effect.
$ passenger-config restart-app /var/www/myapp/bundle
Wait a few seconds (for Passenger to do its job), then remove the old application directory:
$ rm -rf /var/www/myapp/bundle.old
Restart application
Passenger may still be serving an old instance of your application. Now that all application updates have been prepared, tell Passenger to restart your application so that the updates take effect.
$ passenger-config restart-app $(pwd)
Conclusion
Congratulations, you have successfully deployed your web application using Passenger!
To fully master Passenger, please take a look at the advanced guides.