tomo 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92b79ae23f462d987b150fe0537a743f087e150b6947780baa77ea4046e7d9b9
4
- data.tar.gz: 77f301ef039cc4b8e8ed65f4009f0f1e0f3b0edaba7420f7b9994797b78bd53f
3
+ metadata.gz: f9fc9bfe01816992c55105b084e6c9ed40c9f7aa9070e833feebfe4084a66194
4
+ data.tar.gz: be42304890a78153df0cd9589f4c7e01afbbfe1f8fa077ab2d3c879893eab2fc
5
5
  SHA512:
6
- metadata.gz: 312cc7f96ebe0fa19c369fe1bb3ad3c8ea654abfbc8f6d35ec8253f03f8694f4300d6b113d9c17a20ab0473d649b1c0404611f746ffbf563a0c15b8eb35b29e4
7
- data.tar.gz: 737e7aa7cbffe6a048164a6798fc63847ec32478ea81fe63b78fe62b95970f602c6c888b5087a7c03ffe281807182284e1d46ce8e25eff189bc48591a7c598b4
6
+ metadata.gz: 3e34a45b62184a909bfb6d6825110aa56924249acb263f5469e7c470b0393255e73b8a7e40b8aec88a09af8d722edfa4a5fc2d8db49e488039f9f1df541cfa09
7
+ data.tar.gz: cfb514fc60e188e17d81acf2c465608a9b8fce474918a0513f021a1ec02d8817fc997bcb2379bd0a916fabe7baed526737cb0b028d73fa468a7facc67eca7dac
data/README.md CHANGED
@@ -19,6 +19,7 @@ Tomo is a friendly command-line tool for deploying Rails apps. It is a new alter
19
19
 
20
20
  - [Quick start](#quick-start)
21
21
  - [Usage](#usage)
22
+ - [Tutorials](#tutorials)
22
23
  - [Reference documentation](#reference-documentation)
23
24
  - [FAQ](#faq)
24
25
  - [Support](#support)
@@ -94,7 +95,7 @@ Tomo gives you easy-to-use commands for three common use cases:
94
95
  2. `tomo deploy` performs a deployment
95
96
  3. `tomo run` lets you invoke one-off tasks
96
97
 
97
- #### Setup
98
+ ### Setup
98
99
 
99
100
  `tomo setup` prepares the remote host for its first deploy by sequentially running the
100
101
  [setup](https://tomo-deploy.com/configuration#setupblock) list of tasks specified in `.tomo/config.rb`. These tasks typically create directories, initialize data stores, install prerequisite tools, and perform other one-time actions that are necessary before a deploy can take place.
@@ -106,7 +107,7 @@ Out of the box, tomo will:
106
107
  - Create all necessary deployment directories
107
108
  - Create the Rails database, load the schema, and insert seed data
108
109
 
109
- #### Deploy
110
+ ### Deploy
110
111
 
111
112
  Whereas `tomo setup` is typically run once, you can use `tomo deploy` every time you want to deploy a new version of your app. The deploy command will sequentially run the [deploy](https://tomo-deploy.com/configuration#deployblock) list of tasks specified in `.tomo/config.rb`. You can customize this list to meet the needs of your app. By default, tomo runs these tasks:
112
113
 
@@ -117,7 +118,7 @@ Whereas `tomo setup` is typically run once, you can use `tomo deploy` every time
117
118
  5. Restart the app to use the new current release (e.g. [puma:restart](https://tomo-deploy.com/plugins/puma#pumarestart))
118
119
  6. Perform any cleanup (e.g. [bundler:clean](https://tomo-deploy.com/plugins/bundler#bundlerclean))
119
120
 
120
- #### Run
121
+ ### Run
121
122
 
122
123
  Tomo can also `run` individual remote tasks on demand. You can use the `tasks` command to see the list of tasks tomo knows about.
123
124
 
@@ -127,7 +128,7 @@ One of the built-in Rails tasks is `rails:console`, which brings up a fully-inte
127
128
 
128
129
  ![$ tomo run rails:console](./readme_images/tomo-run-rails-console.png)
129
130
 
130
- #### Extending tomo
131
+ ### Extending tomo
131
132
 
132
133
  Tomo has many plugins built-in, but you can easily add your own to extend tomo with custom tasks. By convention, custom plugins are stored in `.tomo/plugins/`. These plugins can define tasks as plain ruby methods. For example:
133
134
 
@@ -155,6 +156,12 @@ And run it!
155
156
 
156
157
  Read the [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/) tutorial for an in-depth guide to extending tomo.
157
158
 
159
+ ## Tutorials
160
+
161
+ - [Deploying Rails From Scratch](https://tomo-deploy.com/tutorials/deploying-rails-from-scratch/)
162
+ - [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/)
163
+ - [Publishing a Plugin](https://tomo-deploy.com/tutorials/publishing-a-plugin/) [TODO]
164
+
158
165
  ## Reference documentation
159
166
 
160
167
  - [Configuration](https://tomo-deploy.com/configuration/)
@@ -173,10 +180,6 @@ Read the [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom
173
180
  - [puma](https://tomo-deploy.com/plugins/puma/)
174
181
  - [rails](https://tomo-deploy.com/plugins/rails/)
175
182
  - [rbenv](https://tomo-deploy.com/plugins/rbenv/)
176
- - Tutorials
177
- - [Deploying Rails From Scratch](https://tomo-deploy.com/tutorials/deploying-rails-from-scratch/)
178
- - [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/)
179
- - [Publishing a Plugin](https://tomo-deploy.com/tutorials/publishing-a-plugin/) [TODO]
180
183
  - API
181
184
  - [Host](https://tomo-deploy.com/api/Host/)
182
185
  - [Logger](https://tomo-deploy.com/api/Logger/)
@@ -17,6 +17,7 @@ module Tomo
17
17
  autoload :Script, "tomo/script"
18
18
  autoload :ShellBuilder, "tomo/shell_builder"
19
19
  autoload :SSH, "tomo/ssh"
20
+ autoload :TaskAPI, "tomo/task_api"
20
21
  autoload :TaskLibrary, "tomo/task_library"
21
22
  autoload :VERSION, "tomo/version"
22
23
 
@@ -20,7 +20,7 @@ module Tomo
20
20
  config_rb = IO.read(path)
21
21
 
22
22
  new.tap do |config|
23
- config.working_dir = File.dirname(path)
23
+ config.path = File.expand_path(path)
24
24
  DSL::ConfigFile.new(config).instance_eval(config_rb, path.to_s, 1)
25
25
  end
26
26
  rescue StandardError, SyntaxError => e
@@ -28,7 +28,7 @@ module Tomo
28
28
  end
29
29
 
30
30
  attr_accessor :environments, :deploy_tasks, :setup_tasks, :hosts, :plugins,
31
- :settings, :task_filter, :working_dir
31
+ :settings, :task_filter, :path
32
32
 
33
33
  def initialize
34
34
  @environments = {}
@@ -59,7 +59,7 @@ module Tomo
59
59
  setup_tasks: setup_tasks,
60
60
  plugins_registry: plugins_registry,
61
61
  hosts: add_log_prefixes(hosts),
62
- settings: settings,
62
+ settings: { tomo_config_file_path: path }.merge(settings),
63
63
  task_filter: task_filter
64
64
  )
65
65
  end
@@ -95,7 +95,7 @@ module Tomo
95
95
 
96
96
  (["core"] + plugins.uniq).each do |plug|
97
97
  if %w[. /].include?(plug[0])
98
- plug = File.expand_path(plug, working_dir) unless working_dir.nil?
98
+ plug = File.expand_path(plug, File.dirname(path)) unless path.nil?
99
99
  plugins_registry.load_plugin_from_path(plug)
100
100
  else
101
101
  plugins_registry.load_plugin_by_name(plug)
@@ -9,20 +9,21 @@ module Tomo::Plugin
9
9
  tasks Tomo::Plugin::Core::Tasks
10
10
 
11
11
  defaults Tomo::SSH::Options::DEFAULTS.merge(
12
- application: "default",
13
- concurrency: 10,
14
- current_path: "%<deploy_to>/current",
15
- deploy_to: "/var/www/%<application>",
16
- keep_releases: 10,
17
- linked_dirs: [],
18
- linked_files: [],
19
- local_user: nil, # determined at runtime
20
- release_json_path: "%<release_path>/.tomo_release.json",
21
- releases_path: "%<deploy_to>/releases",
22
- revision_log_path: "%<deploy_to>/revisions.log",
23
- shared_path: "%<deploy_to>/shared",
24
- tmp_path: "/tmp/tomo",
25
- run_args: [] # determined at runtime
12
+ application: "default",
13
+ concurrency: 10,
14
+ current_path: "%<deploy_to>/current",
15
+ deploy_to: "/var/www/%<application>",
16
+ keep_releases: 10,
17
+ linked_dirs: [],
18
+ linked_files: [],
19
+ local_user: nil, # determined at runtime
20
+ release_json_path: "%<release_path>/.tomo_release.json",
21
+ releases_path: "%<deploy_to>/releases",
22
+ revision_log_path: "%<deploy_to>/revisions.log",
23
+ shared_path: "%<deploy_to>/shared",
24
+ tmp_path: "/tmp/tomo",
25
+ tomo_config_file_path: nil, # determined at runtime
26
+ run_args: [] # determined at runtime
26
27
  )
27
28
  end
28
29
  end
@@ -12,7 +12,9 @@ module Tomo::Plugin::Core
12
12
  result.success?
13
13
  end
14
14
 
15
- def write(text:, to:, append: false, **run_opts)
15
+ def write(text: nil, template: nil, to:, append: false, **run_opts)
16
+ assert_text_or_template_required!(text, template)
17
+ text = merge_template(template) unless template.nil?
16
18
  message = "Writing #{text.bytesize} bytes to #{to}"
17
19
  run(
18
20
  "echo -n #{text.shellescape} #{append ? '>>' : '>'} #{to.shellescape}",
@@ -61,5 +63,11 @@ module Tomo::Plugin::Core
61
63
  def flag?(flag, path, **run_opts)
62
64
  run?("[ #{flag} #{path.to_s.shellescape} ]", **run_opts)
63
65
  end
66
+
67
+ def assert_text_or_template_required!(text, template)
68
+ return if text.nil? ^ template.nil?
69
+
70
+ raise ArgumentError, "specify text: or template:"
71
+ end
64
72
  end
65
73
  end
@@ -2,6 +2,8 @@ require "forwardable"
2
2
 
3
3
  module Tomo
4
4
  class Remote
5
+ include TaskAPI
6
+
5
7
  extend Forwardable
6
8
  def_delegators :ssh, :close, :host
7
9
  def_delegators :shell_builder, :chdir, :env, :prepend, :umask
@@ -33,21 +35,8 @@ module Tomo
33
35
 
34
36
  private
35
37
 
36
- def_delegators :context, :paths, :settings
37
38
  attr_reader :context, :ssh, :shell_builder
38
39
 
39
- def dry_run?
40
- Tomo.dry_run?
41
- end
42
-
43
- def logger
44
- Tomo.logger
45
- end
46
-
47
- def raw(str)
48
- ShellBuilder.raw(str)
49
- end
50
-
51
40
  def remote
52
41
  self
53
42
  end
@@ -16,6 +16,7 @@ module Tomo
16
16
  autoload :SettingsRequiredError, "tomo/runtime/settings_required_error"
17
17
  autoload :TaskAbortedError, "tomo/runtime/task_aborted_error"
18
18
  autoload :TaskRunner, "tomo/runtime/task_runner"
19
+ autoload :TemplateNotFoundError, "tomo/runtime/template_not_found_error"
19
20
  autoload :UnknownTaskError, "tomo/runtime/unknown_task_error"
20
21
 
21
22
  def self.local_user
@@ -0,0 +1,11 @@
1
+ module Tomo
2
+ class Runtime
3
+ class TemplateNotFoundError < Error
4
+ attr_accessor :path
5
+
6
+ def to_console
7
+ "Template not found: #{yellow(path)}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,59 @@
1
+ require "erb"
2
+
3
+ module Tomo
4
+ module TaskAPI
5
+ extend Forwardable
6
+
7
+ private
8
+
9
+ def_delegators :context, :paths, :settings
10
+
11
+ def die(reason)
12
+ Runtime::TaskAbortedError.raise_with(
13
+ reason,
14
+ task: context.current_task,
15
+ host: remote.host
16
+ )
17
+ end
18
+
19
+ def dry_run?
20
+ Tomo.dry_run?
21
+ end
22
+
23
+ def logger
24
+ Tomo.logger
25
+ end
26
+
27
+ def merge_template(path)
28
+ working_path = paths.tomo_config_file&.dirname
29
+ if working_path && path.start_with?(".")
30
+ path = File.expand_path(path, working_path)
31
+ end
32
+
33
+ unless File.file?(path)
34
+ Runtime::TemplateNotFoundError.raise_with(path: path)
35
+ end
36
+ template = IO.read(path)
37
+ ERB.new(template).result(binding)
38
+ end
39
+
40
+ def raw(string)
41
+ ShellBuilder.raw(string)
42
+ end
43
+
44
+ def remote
45
+ context.current_remote
46
+ end
47
+
48
+ def require_setting(*names)
49
+ missing = names.flatten.select { |sett| settings[sett].nil? }
50
+ return if missing.empty?
51
+
52
+ Runtime::SettingsRequiredError.raise_with(
53
+ settings: missing,
54
+ task: context.current_task
55
+ )
56
+ end
57
+ alias require_settings require_setting
58
+ end
59
+ end
@@ -2,7 +2,7 @@ require "forwardable"
2
2
 
3
3
  module Tomo
4
4
  class TaskLibrary
5
- extend Forwardable
5
+ include TaskAPI
6
6
 
7
7
  def initialize(context)
8
8
  @context = context
@@ -10,42 +10,6 @@ module Tomo
10
10
 
11
11
  private
12
12
 
13
- def_delegators :context, :paths, :settings
14
13
  attr_reader :context
15
-
16
- def die(reason)
17
- Runtime::TaskAbortedError.raise_with(
18
- reason,
19
- task: context.current_task,
20
- host: remote.host
21
- )
22
- end
23
-
24
- def dry_run?
25
- Tomo.dry_run?
26
- end
27
-
28
- def logger
29
- Tomo.logger
30
- end
31
-
32
- def raw(string)
33
- ShellBuilder.raw(string)
34
- end
35
-
36
- def remote
37
- context.current_remote
38
- end
39
-
40
- def require_setting(*names)
41
- missing = names.flatten.select { |sett| settings[sett].nil? }
42
- return if missing.empty?
43
-
44
- Runtime::SettingsRequiredError.raise_with(
45
- settings: missing,
46
- task: context.current_task
47
- )
48
- end
49
- alias require_settings require_setting
50
14
  end
51
15
  end
@@ -1,3 +1,3 @@
1
1
  module Tomo
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2019-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -245,6 +245,7 @@ files:
245
245
  - lib/tomo/runtime/settings_required_error.rb
246
246
  - lib/tomo/runtime/task_aborted_error.rb
247
247
  - lib/tomo/runtime/task_runner.rb
248
+ - lib/tomo/runtime/template_not_found_error.rb
248
249
  - lib/tomo/runtime/unknown_task_error.rb
249
250
  - lib/tomo/script.rb
250
251
  - lib/tomo/shell_builder.rb
@@ -260,6 +261,7 @@ files:
260
261
  - lib/tomo/ssh/script_error.rb
261
262
  - lib/tomo/ssh/unknown_error.rb
262
263
  - lib/tomo/ssh/unsupported_version_error.rb
264
+ - lib/tomo/task_api.rb
263
265
  - lib/tomo/task_library.rb
264
266
  - lib/tomo/templates/config.rb.erb
265
267
  - lib/tomo/testing.rb