puma-redeploy 0.3.3 → 0.3.4

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: 487d73d4431d3a6bf5efd0fae10ef34628480e90d4bfba3e501f3dd4c4123bf1
4
- data.tar.gz: 7e5eced22b688086dc465444863b86fed4c7c2a601a69d9cfd13333ee303da9d
3
+ metadata.gz: 9c3ab66d43e2e0873f599be9539d9ed53a3cb9e6903559d14e99e6621948bb1a
4
+ data.tar.gz: 16cb84d8f89796065d3447d28af9bbfefd8b9cfc7c628536010d7053402e7ee7
5
5
  SHA512:
6
- metadata.gz: 0d32a5449f932d6a16677bccfd42dad90d5f70f44622506471f2310bce41291411941a506c445c9bb8ae06af5d48e5e439e0af23fb6c889f3055da7ec902f03e
7
- data.tar.gz: 7c1f4c155218fd70add589f7b13f57ed5c1fe36c93c90118c0e32dba4dedb221fc7303521f9f9ff2b578449a1c4933f98a5d351a1ad208e9e19d8756755ea7b1
6
+ metadata.gz: 378a9de4c851ed162ef10c3c8fe374cc9a0d54aeca59c09f94059c1371c1bad4915863a9b69f8ad7140f93a35e56efc607c5e0a4701be88859cf24f99093e27d
7
+ data.tar.gz: ba10ba1dd934b22cc087b81a1086481c0b08bb33d47c6939c2f06a13eefd9aa0a19fa0767fef1388cc7643be7a34ec88047d787bb62b2edcdb146e9f2b22626d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.3.4
4
+
5
+ **Features:**
6
+
7
+ - Add support to run commands prior to redeploy using a yaml watch file. This is useful for running a migration or bundle gems.
8
+
3
9
  ## v0.3.3
4
10
 
5
11
  **Fixes and enhancements:**
data/README.md CHANGED
@@ -51,18 +51,24 @@ redeploy_watch_delay 15
51
51
 
52
52
  ```
53
53
 
54
- The watch file must contain the path to the current archive. This can be a file path or S3 URL.
55
-
54
+ The watch file can contain an optional list of commands to run and the required archive_location. The archive_location can be a file path or S3 URL
56
55
  For example when using a file:
57
- ```
58
- /app/pkg/test_app_0.0.3.zip
56
+ ```yaml
57
+ ---
58
+ commands:
59
+ - bundle
60
+ archive_location: /app/pkg/test_app_0.0.3.zip
59
61
  ```
60
62
 
61
63
  For example when using S3:
62
- ```
63
- s3://puma-test-app-archives/test_app_0.0.3.zip
64
+ ```yaml
65
+ ---
66
+ commands:
67
+ - bundle
68
+ archive_location: s3://puma-test-app-archives/test_app_0.0.3.zip
64
69
  ```
65
70
 
71
+
66
72
  ### Archive Loader
67
73
  The `archive-loader` is a cli used to fetch and deploy the application archive prior to starting the puma server. This is useful when the application code does not exist in the runtime container.
68
74
 
@@ -76,9 +82,10 @@ Usage: archive-loader [options]. Used to load the archive prior to starting the
76
82
 
77
83
  For example this will fetch and unzip the application archive and then start puma.
78
84
  ```shell
79
- archive-loader -a /app -w /app/pkg/watch.me && bundle exec puma -C config/puma.rb
85
+ archive-loader -a /app -w /app/pkg/watch.yml && bundle exec puma -C config/puma.rb
80
86
  ```
81
87
 
88
+
82
89
  ## Development
83
90
 
84
91
  After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests and `rake rubocop` to check for rubocop offences.
data/bin/archive-loader CHANGED
@@ -9,7 +9,12 @@ require 'optparse'
9
9
  def deploy_archive(app_dir, watch_file, logger)
10
10
  handler = Puma::Redeploy::DeployerFactory.create(target: app_dir, watch_file:,
11
11
  logger:)
12
- handler.deploy(source: handler.archive_file)
12
+
13
+ watch_file_data = handler.watch_file_data
14
+
15
+ archive_file = handler.archive_file(watch_file_data[:archive_location])
16
+
17
+ handler.deploy(source: archive_file)
13
18
  end
14
19
 
15
20
  def option_parser(opts)
@@ -27,9 +27,15 @@ def monitor_loop(handler, delay, launcher, logger)
27
27
 
28
28
  next unless handler.needs_redeploy?
29
29
 
30
- logger.info "Puma phased_restart begin file=#{handler.watch_file} archive=#{handler.archive_file}"
30
+ watch_file_data = handler.watch_file_data
31
31
 
32
- handler.deploy(source: handler.archive_file)
32
+ archive_file = handler.archive_file(watch_file_data[:archive_location])
33
+
34
+ logger.info "Puma phased_restart begin file=#{handler.watch_file} archive=#{archive_file}"
35
+
36
+ Puma::Redeploy::CommandRunner.new(commands: watch_file_data[:commands], logger:).run
37
+
38
+ handler.deploy(source: archive_file)
33
39
 
34
40
  launcher.phased_restart
35
41
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
+ require 'yaml'
4
5
 
5
6
  module Puma
6
7
  module Redeploy
@@ -24,6 +25,15 @@ module Puma
24
25
 
25
26
  def_delegators :@deployer, :deploy
26
27
 
28
+ def watch_file_data
29
+ watch_file_content = read_watch_object
30
+ results = YAML.safe_load(watch_file_content, symbolize_names: true)
31
+ return results if results.is_a?(Hash)
32
+
33
+ # old style where the file contains only the archive location
34
+ { commands: [], archive_location: results }
35
+ end
36
+
27
37
  private
28
38
 
29
39
  attr_accessor :logger
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module Puma
6
+ module Redeploy
7
+ # Runs commands before redeploy process
8
+ class CommandRunner
9
+ attr_reader :commands, :runner
10
+
11
+ def initialize(commands:, logger:, runner: Open3)
12
+ @logger = logger
13
+ @commands = commands || []
14
+ @runner = runner
15
+ end
16
+
17
+ def run
18
+ commands.each do |command|
19
+ @logger.info "running command: #{command}"
20
+ stdout, stderr, status = runner.capture3(command)
21
+ @logger.info "command stdout: #{stdout}"
22
+ @logger.info "command status: #{status.exitstatus}"
23
+ @logger.error "command stderr: #{stderr}" if status.exitstatus != 0
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -11,12 +11,18 @@ module Puma
11
11
  @touched_at = touched_at
12
12
  end
13
13
 
14
- def archive_file
15
- File.read(watch_file).strip
14
+ def archive_file(archive_location)
15
+ archive_location
16
16
  end
17
17
 
18
18
  private
19
19
 
20
+ def read_watch_object
21
+ File.read(watch_file).strip
22
+ rescue StandardError => e
23
+ logger.warn "Error reading watch file #{watch_file}. Error:#{e.message}"
24
+ end
25
+
20
26
  def touched_at
21
27
  if File.exist?(watch_file)
22
28
  File.mtime(watch_file)
@@ -16,11 +16,10 @@ module Puma
16
16
  @touched_at = touched_at
17
17
  end
18
18
 
19
- def archive_file
20
- s3_url = read_watch_object
21
- return unless s3_url
19
+ def archive_file(archive_location)
20
+ return unless archive_location
22
21
 
23
- archive_bucket_name, archive_object_key = s3_object_reference(s3_url)
22
+ archive_bucket_name, archive_object_key = s3_object_reference(archive_location)
24
23
 
25
24
  response = s3_client.get_object(bucket: archive_bucket_name, key: archive_object_key)
26
25
 
@@ -29,7 +28,7 @@ module Puma
29
28
  File.binwrite(file_name, response.body.read)
30
29
  file_name
31
30
  rescue StandardError => e
32
- logger.warn "Error reading fetching archive file for #{s3_url}. Error:#{e.message}"
31
+ logger.warn "Error reading fetching archive file for #{archive_location}. Error:#{e.message}"
33
32
  end
34
33
 
35
34
  private
@@ -49,7 +48,7 @@ module Puma
49
48
 
50
49
  object.body.read.strip
51
50
  rescue StandardError => e
52
- logger.warn "Error reading url from watch file #{bucket_name}/#{object_key}. Error:#{e.message}"
51
+ logger.warn "Error reading watch file #{bucket_name}/#{object_key}. Error:#{e.message}"
53
52
  end
54
53
 
55
54
  def touched_at
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Puma
4
4
  module Redeploy
5
- VERSION = '0.3.3'
5
+ VERSION = '0.3.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma-redeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbeauvais
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-04 00:00:00.000000000 Z
11
+ date: 2024-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -50,6 +50,7 @@ files:
50
50
  - lib/puma-redeploy.rb
51
51
  - lib/puma/plugin/redeploy.rb
52
52
  - lib/puma/redeploy/base_handler.rb
53
+ - lib/puma/redeploy/command_runner.rb
53
54
  - lib/puma/redeploy/deployer_factory.rb
54
55
  - lib/puma/redeploy/dsl.rb
55
56
  - lib/puma/redeploy/file_handler.rb