deploy

Deploy the current project to remote host(s).

Usage

$ tomo deploy [--dry-run] [options]

Sequentially run the deploy list of tasks specified in .tomo/config.rb to deploy the project to a remote host. In practice, a deploy will usually consist of the following steps:

  1. Create a release (using the git:create_release task)
  2. Build the project (e.g. bundler:install, rails:assets_precompile)
  3. Migrate data to the meet the requirements of the new release (e.g. rails:db_migrate)
  4. Make the new release the “current” one (core:symlink_current)
  5. Restart the app to use the new current release (e.g. puma:restart)
  6. Perform any cleanup (e.g. bundler:clean)

During a deploy, tomo will initialize the :release_path setting based on the current date and time (e.g. /var/www/my-app/releases/20190616214752). Any tasks that copy files into a release (git:create_release), or run inside the release (bundler:install, rails:assets_precompile, rails:db_migrate, etc.) will operate using this path. As a result, every tomo deploy will create a new entry in the releases directory, and the current symlink will point to the release that is currently active, i.e. the most recent successful deploy.

The directory structure on the remote host looks like this:

/var/www/my-app
├── git_repo/
├── releases/
|   ├── 20190614192115/
|   ├── 20190615034736/
|   └── 20190616214752/
├── shared/
|   ├── bundle/
|   ├── log/
|   ├── node_modules/
|   └── public/
|       └── assets/
├── current -> /var/www/my-app/releases/20190616214752
└── revisions.log

This structure is customizable; see the core plugin settings for details.

Tip: run tomo deploy --debug --dry-run to see an in-depth explanation of the settings and execution plan that will be used for the deployment.

Options

Option Purpose
-e ENVIRONMENT, --environment ENVIRONMENT If the configuration contains multiple environments, specify the ENVIRONMENT that should be used (e.g. production). The host(s) and settings can be different per environment.
-s NAME=VALUE, --setting NAME=VALUE Override the setting NAME with the given VALUE. Refer to the settings overrides documentation for a detailed explanation.
--[no-]dry-run Simulate running tasks instead of using real SSH.
-c PATH, --config PATH Override the PATH where the configuration file is loaded from. (Default: .tomo/config.rb).
--[no-]color By default, tomo automatically determines whether to use color output based on the capabilities of the terminal. Use this option to override this behavior and force tomo to enable or disable color output.
--[no-]debug Enables verbose logging output that is helpful for troubleshooting. This includes runtime information such as the environment variables on the remote host and all tomo settings. Each SSH command executed by tomo is also logged in detail.
--[no-]trace Normally if a tomo command fails, a concise and helpful error message is printed. If --trace is specified, tomo will also print the full backtrace.
-h, --help Prints the help for this tomo command, similar to what you see on this page.

Example

Given the following configuration:

host "deployer@localhost", port: 32809

deploy do
  run "env:update"
  run "git:create_release"
  run "core:symlink_shared"
  run "core:write_release_json"
  run "bundler:install"
  run "rails:db_migrate"
  run "rails:db_seed"
  run "rails:assets_precompile"
  run "core:symlink_current"
  run "puma:restart"
  run "puma:check_active"
  run "core:clean_releases"
  run "bundler:clean"
  run "core:log_revision"
end

Then a deploy would produce:

$ tomo deploy
tomo deploy v1.0.0
→ Connecting to deployer@localhost:32829
• env:update
• git:create_release
cd /var/www/rails-new/git_repo && export GIT_SSH_COMMAND=ssh\ -o\ PasswordAuthentication\=no\ -o\ StrictHostKeyChecking\=no && git remote update --prune
Fetching origin
cd /var/www/rails-new/git_repo && export GIT_SSH_COMMAND=ssh\ -o\ PasswordAuthentication\=no\ -o\ StrictHostKeyChecking\=no && git log -n1 --date=iso --pretty=format:"%H/%cd/%ae" main --
Writing 60 bytes to /var/www/rails-new/git_repo/info/attributes
mkdir -p /var/www/rails-new/releases/20191019200551
cd /var/www/rails-new/git_repo && export GIT_SSH_COMMAND=ssh\ -o\ PasswordAuthentication\=no\ -o\ StrictHostKeyChecking\=no && git archive main | tar -x -f - -C /var/www/rails-new/releases/20191019200551
• core:symlink_shared
mkdir -p /var/www/rails-new/shared/log /var/www/rails-new/shared/node_modules /var/www/rails-new/shared/public/assets /var/www/rails-new/shared/tmp/cache /var/www/rails-new/shared/tmp/pids /var/www/rails-new/shared/tmp/sockets /var/www/rails-new/releases/20191019200551/public /var/www/rails-new/releases/20191019200551/tmp
cd /var/www/rails-new/releases/20191019200551 && rm -rf log node_modules public/assets tmp/cache tmp/pids tmp/sockets
ln -sf /var/www/rails-new/shared/log /var/www/rails-new/releases/20191019200551/log
ln -sf /var/www/rails-new/shared/node_modules /var/www/rails-new/releases/20191019200551/node_modules
ln -sf /var/www/rails-new/shared/public/assets /var/www/rails-new/releases/20191019200551/public/assets
ln -sf /var/www/rails-new/shared/tmp/cache /var/www/rails-new/releases/20191019200551/tmp/cache
ln -sf /var/www/rails-new/shared/tmp/pids /var/www/rails-new/releases/20191019200551/tmp/pids
ln -sf /var/www/rails-new/shared/tmp/sockets /var/www/rails-new/releases/20191019200551/tmp/sockets
• core:write_release_json
Writing 299 bytes to /var/www/rails-new/releases/20191019200551/.tomo_release.json
• bundler:install
cd /var/www/rails-new/releases/20191019200551 && bundle check
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
The Gemfile's dependencies are satisfied
• rails:db_migrate
cd /var/www/rails-new/releases/20191019200551 && bundle exec rails db:migrate
• rails:db_seed
cd /var/www/rails-new/releases/20191019200551 && bundle exec rails db:seed
• rails:assets_precompile
cd /var/www/rails-new/releases/20191019200551 && bundle exec rails assets:precompile
yarn install v1.16.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > webpack-dev-server@3.8.1" has unmet peer dependency "webpack@^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
Done in 30.68s.
I, [2019-10-19T20:06:30.645395 #33263]  INFO -- : Writing /var/www/rails-new/releases/20191019200551/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
I, [2019-10-19T20:06:30.645832 #33263]  INFO -- : Writing /var/www/rails-new/releases/20191019200551/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
Compiling…
Compiled all packs in /var/www/rails-new/releases/20191019200551/public/packs

WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

  npm install --save core-js@2    npm install --save core-js@3
  yarn add core-js@2              yarn add core-js@3


• core:symlink_current
ln -sf /var/www/rails-new/releases/20191019200551 /var/www/rails-new/current-0d3d2f7a6648294a
mv -fT /var/www/rails-new/current-0d3d2f7a6648294a /var/www/rails-new/current
• puma:restart
systemctl --user start puma_rails-new.socket
systemctl --user restart puma_rails-new.service
• puma:check_active
Checking if puma is active and listening on port 3000...
systemctl --user is-active puma_rails-new.service
curl -sS --connect-timeout 1 --max-time 10 http://localhost:3000 > /dev/null
systemctl --user status puma_rails-new.service
● puma_rails-new.service
   Loaded: loaded (enabled; vendor preset: enabled)
   Active: active (running)
• core:clean_releases
readlink /var/www/rails-new/current
cd /var/www/rails-new/releases && ls -A1
• bundler:clean
cd /var/www/rails-new/releases/20191019200551 && bundle clean
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
• core:log_revision
Writing 100 bytes to /var/www/rails-new/revisions.log
✔ Deployed rails-new to deployer@localhost:32829