capistrano-asdf 1.0.0 → 1.1.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: 1c739260d04538643bc1a872b1d04ff441d3f62a8bc8855e990950510b4ca369
4
- data.tar.gz: 3af3ba1475e2eb98d13fd406d5a4c4871ad286842e55f143464b4e4d7ca5c490
3
+ metadata.gz: 277839d3d4ad728956156c2fec0afbcfdf73a755eaa2541aa17a467b98c01a3a
4
+ data.tar.gz: 2d8325ebea40c7a07c3fdf45769dd5ca8100f48843bb571ba2bd902dae377286
5
5
  SHA512:
6
- metadata.gz: b4ff3bb12d5a1e3752d2954b89c82eeda582e990540b07f4af647096714caafcc4c32ffcc142356015f79fe5bd080a1b2e9d27ffab7ca4ae60db7e9825ffdbe7
7
- data.tar.gz: 44cb53b59394977830fa51144ddd69945ead0bc4dd0b95015ac3be3e7807b2f306a8df947f6ff1b3921683e400131e5b868315de34bde821a210008343d5d7c2
6
+ metadata.gz: ce2a4e798d087ddcfda6755ab8e8ec22fbdee55d3449283c5030d468b2e910d0d81966601eb0ec16e6d8f4438ea8860907d09964b3c5859e550fdde00fe853ef
7
+ data.tar.gz: 9d9d82d1d05ad8f3211a3d1bee0adde946990ecd4e0bca2fffdc17b7d60ada50e14202275c63ca21c7afaa1b3b13419d4efb16d2d05b8d1b5699daddc1de9715
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1.0
2
+
3
+ Upload and use an ASDF wrapper to fully load ASDF environnement before executing commands.
4
+ The wrapper is generated in `<shared_path>/asdf-wrapper` by default, but can be generated elsewhere by setting `:asdf_custom_wrapper_path` capistrano variable.
5
+
1
6
  ## 1.0.0
2
7
 
3
8
  Add asdf:install and asdf:add_plugins tasks
data/README.md CHANGED
@@ -84,12 +84,21 @@ This gem adds new tasks `asdf:map_*` before `deploy` task.
84
84
  It loads the ASDF tools environment for capistrano when it wants to run
85
85
  some tools related programs like `rake`, `gem`, `bundle`, `node`, `npm` ...
86
86
 
87
+ ## Generate and upload the ASDF commands wrapper
88
+
89
+ The ASDF wrapper is needed to correctly run the mapped commands.
90
+ Since the wrapper is an executable script, it can be used in Systemd units.
91
+
92
+ $ cap production asdf:upload_wrapper
93
+
94
+ This task is automaticaly called before `asdf:check`
95
+
87
96
  ## Install required tools
88
97
 
89
98
  If you want your tools (ruby, nodejs) to be installed, you can use the `asdf:install` task to
90
99
  preform plugins add and then install of required versions from your `.tool-versions`.
91
100
  `asdf:install` will automaticaly add necessary plugins running `asdf:add_plugins`.
92
- If you want to change the plugins to install you my set `:asdf_tools` accordingly.
101
+ If you want to change the plugins to install you may set `:asdf_tools` accordingly.
93
102
 
94
103
  $ cap production asdf:install
95
104
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "capistrano-asdf"
7
- gem.version = '1.0.0'
7
+ gem.version = '1.1.0'
8
8
  gem.licenses = ['MIT']
9
9
  gem.authors = ["Jean-Baptiste Poix"]
10
10
  gem.email = ["jbpoix@inosophia.com"]
@@ -5,30 +5,66 @@ ASDF_DEFAULT_RUBY_BINS = %w{rake gem bundle ruby rails}
5
5
  # Nodejs related bin
6
6
  ASDF_DEFAULT_NODEJS_BINS = %w{node npm yarn}
7
7
 
8
+ ASDF_DEFAULT_WRAPPER_TEMPALTES = %{
9
+ #!/usr/bin/env bash
10
+
11
+ . @@ASDF_USER_PATH@@/asdf.sh
12
+ exec "$@"
13
+ }
14
+
8
15
  namespace :asdf do
16
+ desc "Upload ASDF wrapper to the target host"
17
+ task :upload_wrapper do
18
+ on roles(fetch(:asdf_roles, :all)) do
19
+ wrapper_content = ASDF_DEFAULT_WRAPPER_TEMPALTES.gsub('@@ASDF_USER_PATH@@', fetch(:asdf_path))
20
+ need_to_upload_wrapper = true
21
+ # Check if the wrapper already exists
22
+ if test("[ -f #{fetch(:asdf_wrapper_path)} ]")
23
+ # Check if md5sum is available on the target host
24
+ if test("which md5sum")
25
+ else
26
+ info "md5sum is not available on the target host, we can't check the wrapper integrity"
27
+ need_to_upload_wrapper = false
28
+ end
29
+ # Check if the wrapper is the same as the one we want to upload using a md5 checksum
30
+ if capture("md5sum #{fetch(:asdf_wrapper_path)}").split.first == Digest::MD5.hexdigest(wrapper_content)
31
+ need_to_upload_wrapper = false
32
+ else
33
+ info "ASDF wrapper already exists on the target host but is different from the one we want to upload"
34
+ end
35
+ end
36
+ if need_to_upload_wrapper
37
+ upload! StringIO.new(wrapper_content), "#{fetch(:asdf_wrapper_path)}"
38
+ execute("chmod +x #{fetch(:asdf_wrapper_path)}")
39
+ else
40
+ info "ASDF wrapper already exists on the target host"
41
+ end
42
+ end
43
+ end
44
+
9
45
  desc "Prints the ASDF tools versions on the target host"
10
46
  task :check do
11
47
  on roles(fetch(:asdf_roles, :all)) do
12
- execute("source #{fetch(:asdf_path)}/asdf.sh; asdf current")
48
+ execute("#{fetch(:asdf_wrapper_path)} asdf current")
13
49
  end
14
50
  end
15
51
 
16
52
  desc "Install ASDF tools versions based on the .tool-versions of your project"
17
53
  task :install do
18
54
  on roles(fetch(:asdf_roles, :all)) do
19
- execute("source #{fetch(:asdf_path)}/asdf.sh; asdf install")
55
+ execute("#{fetch(:asdf_wrapper_path)} asdf install")
20
56
  end
21
57
  end
22
58
 
23
59
  desc "Add ASDF plugins specified in :asdf_tools"
24
60
  task :add_plugins do
25
61
  on roles(fetch(:asdf_roles, :all)) do
26
- already_installed_plugins = capture("source #{fetch(:asdf_path)}/asdf.sh; asdf plugin list")&.split
62
+ already_installed_plugins = capture("#{fetch(:asdf_wrapper_path)} asdf plugin list")&.split
27
63
  fetch(:asdf_tools)&.each do |asdf_tool|
28
64
  if already_installed_plugins.include?(asdf_tool)
29
65
  info "#{asdf_tool} Already installed"
30
66
  else
31
- execute("source #{fetch(:asdf_path)}/asdf.sh; asdf plugin add #{asdf_tool}")
67
+ execute("#{fetch(:asdf_wrapper_path)} asdf plugin add #{asdf_tool}")
32
68
  end
33
69
  end
34
70
  end
@@ -37,7 +73,7 @@ namespace :asdf do
37
73
  task :map_ruby_bins do
38
74
  if fetch(:asdf_tools).include?('ruby')
39
75
  fetch(:asdf_map_ruby_bins).each do |mapped_command|
40
- SSHKit.config.command_map.prefix[mapped_command.to_sym].unshift("source #{fetch(:asdf_path)}/asdf.sh;")
76
+ SSHKit.config.command_map.prefix[mapped_command.to_sym].unshift("#{fetch(:asdf_wrapper_path)}")
41
77
  end
42
78
  end
43
79
  end
@@ -45,7 +81,7 @@ namespace :asdf do
45
81
  task :map_nodejs_bins do
46
82
  if fetch(:asdf_tools).include?('nodejs')
47
83
  fetch(:asdf_map_nodejs_bins).each do |mapped_command|
48
- SSHKit.config.command_map.prefix[mapped_command.to_sym].unshift("source #{fetch(:asdf_path)}/asdf.sh;")
84
+ SSHKit.config.command_map.prefix[mapped_command.to_sym].unshift("#{fetch(:asdf_wrapper_path)}")
49
85
  end
50
86
  end
51
87
  end
@@ -54,6 +90,7 @@ end
54
90
 
55
91
  before 'asdf:install', 'asdf:add_plugins'
56
92
  after 'deploy:check', 'asdf:check'
93
+ before 'asdf:check', 'asdf:upload_wrapper'
57
94
 
58
95
  Capistrano::DSL.stages.each do |stage|
59
96
  after stage, 'asdf:map_ruby_bins'
@@ -66,6 +103,9 @@ namespace :load do
66
103
  asdf_path = fetch(:asdf_custom_path)
67
104
  asdf_path ||= ASDF_USER_PATH
68
105
  }
106
+ set :asdf_wrapper_path, -> {
107
+ fetch(:asdf_custom_wrapper_path) || "#{shared_path}/asdf-wrapper"
108
+ }
69
109
 
70
110
  set :asdf_tools, fetch(:asdf_tools, ASDF_DEFAULT_TOOLS)
71
111
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-asdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Poix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-01 00:00:00.000000000 Z
11
+ date: 2023-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.7.3
78
+ rubygems_version: 2.7.6
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: ASDF integration for Capistrano