capistrano-hyperf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba1cdfda93527d54d5a58ba672ddbadd15306c1da191a118c7502edd3227c342
4
+ data.tar.gz: adf7955ade166131c57f5f37654cc8afad06cb498bdfc7468aa33c05eaf3cbde
5
+ SHA512:
6
+ metadata.gz: 707249b8a5ba8478e52a4641618e6c327d059b502a80f3857aac1908dc584cf8a80fc99a73d51f95c0077aa7fb68b6204518fa97e2dc0080dcb68050b183e883
7
+ data.tar.gz: 9ecd20ca5d2c5872738a6a29763a61747b8ef7ba27ad534460008d3fa3ca6a5c23f158317a9ef301ab47368e3d7bb497a5759816f137dae8f7085451140ff674
data/.editorconfig ADDED
@@ -0,0 +1,18 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
13
+
14
+ [*.rake]
15
+ indent_size = 2
16
+
17
+ [*.rb]
18
+ indent_size = 2
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-bundler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Gang Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # Capistrano::Hyperf
2
+
3
+ Deploy Hyperf applications with Capistrano 3.x
4
+
5
+ ## Installation
6
+
7
+ If managing your Capistrano deploy as a ruby project, add this line to your
8
+ application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'capistrano', '~> 3.0.0'
12
+ gem 'capistrano-hyperf'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```shell
18
+ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```shell
24
+ gem install capistrano-hyperf
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Require the module in your `Capfile`:
30
+
31
+ ```ruby
32
+ require 'capistrano/hyperf'
33
+ ```
34
+
35
+ ### Configuration
36
+
37
+ The gem makes the following configuration variables available (shown with defaults).
38
+
39
+ ```ruby
40
+ # Which roles to consider as hyperf roles
41
+ set :hyperf_roles, :all
42
+
43
+ # The hyperf flags to include on bin/hyperf.php commands by default
44
+ set :hyperf_run_flags, ""
45
+
46
+ # Which roles to use for running migrations
47
+ set :hyperf_migration_roles, :all
48
+
49
+ # The hyperf flags to include on commands when running migrations
50
+ set :hyperf_migration_run_flags, "--force"
51
+
52
+ # Whether to upload the dotenv file on deploy
53
+ set :hyperf_upload_dotenv_file_on_deploy, true
54
+
55
+ # Which dotenv file to transfer to the server
56
+ set :hyperf_dotenv_file, '.env'
57
+
58
+ # The user that the server is running under (used for ACLs)
59
+ set :hyperf_server_user, 'www-data'
60
+
61
+ # Ensure the dirs in :linked_dirs exist?
62
+ set :hyperf_ensure_linked_dirs_exist, true
63
+
64
+ # Link the directores in hyperf_linked_dirs?
65
+ set :hyperf_set_linked_dirs, true
66
+
67
+ # Linked directories for a standard hyperf application
68
+ set :hyperf_linked_dirs, [
69
+ 'runtime/logs',
70
+ ]
71
+
72
+ # Ensure the paths in :file_permissions_paths exist?
73
+ set :hyperf_ensure_acl_paths_exist, true
74
+
75
+ # Set ACLs for the paths in hyperf_acl_paths?
76
+ set :hyperf_set_acl_paths, true
77
+
78
+ # Paths that should have ACLs set for a standard hyperf application
79
+ set :hyperf_acl_paths, [
80
+ 'runtime/logs',
81
+ ]
82
+ ```
83
+
84
+ ### Tasks
85
+
86
+ The following tasks are added to your deploy automagically when adding
87
+ capistrano/hyperf to your deploy.
88
+
89
+ ```ruby
90
+ before 'deploy:starting', 'hyperf:resolve_linked_dirs'
91
+ before 'deploy:starting', 'hyperf:resolve_acl_paths'
92
+ after 'deploy:starting', 'hyperf:ensure_linked_dirs_exist'
93
+ after 'deploy:updating', 'hyperf:ensure_acl_paths_exist'
94
+ before 'deploy:updated', 'deploy:set_permissions:acl'
95
+ before 'deploy:updated', 'hyperf:upload_dotenv_file'
96
+ ```
97
+
98
+ #### Task Descriptions
99
+
100
+ ```ruby
101
+ # Determine which folders, if any, to use for linked directories.
102
+ invoke 'hyperf:resolve_linked_dirs'
103
+
104
+ # Determine which paths, if any, to have ACL permissions set.
105
+ invoke 'hyperf:resolve_acl_paths'
106
+
107
+ # Ensure that linked dirs exist.
108
+ invoke 'hyperf:ensure_linked_dirs_exist'
109
+
110
+ # Ensure that ACL paths exist.
111
+ invoke 'hyperf:ensure_acl_paths_exist'
112
+
113
+ # Upload dotenv file for release.
114
+ invoke 'hyperf:upload_dotenv_file'
115
+
116
+ # Execute a provided hyperf command.
117
+ # Replace :command_name with the command to execute
118
+ invoke 'hyperf:run[:command_name]'
119
+
120
+ # Run the database migrations.
121
+ invoke 'hyperf:migrate'
122
+
123
+ # Rollback the last database migration.
124
+ invoke 'hyperf:migrate_rollback'
125
+ ```
126
+
127
+ ## Contributing
128
+
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gokure/capistrano-hyperf.
130
+
131
+ ## License
132
+
133
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capistrano-hyperf'
7
+ spec.version = '0.1.0'
8
+ spec.authors = ['Gang Wu']
9
+ spec.email = ['gokure@gmail.com']
10
+
11
+ spec.summary = 'Hyperf specific deployment options for Capistrano 3.x'
12
+ spec.description = 'Hyperf deployment for Capistrano 3.x'
13
+ spec.homepage = 'https://github.com/gokure/capistrano-hyperf'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'capistrano', '>= 3.0.0'
22
+ spec.add_dependency 'capistrano-composer', '>= 0.0.6'
23
+ spec.add_dependency 'capistrano-file-permissions', '>= 1.0.0'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ require 'capistrano/composer'
2
+ require 'capistrano/file-permissions'
3
+
4
+ load File.expand_path('tasks/hyperf.rake', __dir__)
@@ -0,0 +1,169 @@
1
+ include Comparable
2
+
3
+ namespace :load do
4
+ task :defaults do
5
+ # Which roles to consider as hyperf roles
6
+ set :hyperf_roles, :all
7
+
8
+ # The hyperf flags to include on bin/hyperf.php commands by default
9
+ set :hyperf_run_flags, ""
10
+
11
+ # Which roles to use for running migrations
12
+ set :hyperf_migration_roles, :all
13
+
14
+ # The hyperf flags to include on commands when running migrations
15
+ set :hyperf_migration_run_flags, "--force"
16
+
17
+ # Whether to upload the dotenv file on deploy
18
+ set :hyperf_upload_dotenv_file_on_deploy, true
19
+
20
+ # Which dotenv file to transfer to the server
21
+ set :hyperf_dotenv_file, '.env'
22
+
23
+ # The user that the server is running under (used for ACLs)
24
+ set :hyperf_server_user, 'www-data'
25
+
26
+ # Ensure the dirs in :linked_dirs exist?
27
+ set :hyperf_ensure_linked_dirs_exist, true
28
+
29
+ # Link the directores in hyperf_linked_dirs?
30
+ set :hyperf_set_linked_dirs, true
31
+
32
+ # Linked directories for a standard hyperf application
33
+ set :hyperf_linked_dirs, [
34
+ 'runtime/logs',
35
+ ]
36
+
37
+ # Ensure the paths in :file_permissions_paths exist?
38
+ set :hyperf_ensure_acl_paths_exist, true
39
+
40
+ # Set ACLs for the paths in hyperf_acl_paths?
41
+ set :hyperf_set_acl_paths, true
42
+
43
+ # Paths that should have ACLs set for a standard hyperf application
44
+ set :hyperf_acl_paths, [
45
+ 'runtime/logs',
46
+ ]
47
+ end
48
+ end
49
+
50
+ namespace :hyperf do
51
+ desc 'Determine which folders, if any, to use for linked directories.'
52
+ task :resolve_linked_dirs do
53
+ hyperf_linked_dirs = fetch(:hyperf_linked_dirs)
54
+ if fetch(:hyperf_set_linked_dirs)
55
+ set :linked_dirs, fetch(:linked_dirs, []).push(*hyperf_linked_dirs)
56
+ end
57
+ end
58
+
59
+ desc 'Determine which paths, if any, to have ACL permissions set.'
60
+ task :resolve_acl_paths do
61
+ next unless fetch(:hyperf_set_acl_paths)
62
+ hyperf_acl_paths = fetch(:hyperf_acl_paths)
63
+ set :file_permissions_paths, fetch(:file_permissions_paths, [])
64
+ .push(*hyperf_acl_paths)
65
+ .uniq
66
+ set :file_permissions_users, fetch(:file_permissions_users, [])
67
+ .push(fetch(:hyperf_server_user))
68
+ .uniq
69
+ end
70
+
71
+ desc 'Ensure that linked dirs exist.'
72
+ task :ensure_linked_dirs_exist do
73
+ next unless fetch(:hyperf_ensure_linked_dirs_exist)
74
+
75
+ on roles fetch(:hyperf_roles) do
76
+ fetch(:linked_dirs).each do |path|
77
+ within shared_path do
78
+ execute :mkdir, '-p', path
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ desc 'Ensure that ACL paths exist.'
85
+ task :ensure_acl_paths_exist do
86
+ next unless fetch(:hyperf_set_acl_paths) &&
87
+ fetch(:hyperf_ensure_acl_paths_exist)
88
+
89
+ on roles fetch(:hyperf_roles) do
90
+ fetch(:file_permissions_paths).each do |path|
91
+ within release_path do
92
+ execute :mkdir, '-p', path
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ desc 'Upload dotenv file for release.'
99
+ task :upload_dotenv_file do
100
+ next unless fetch(:hyperf_upload_dotenv_file_on_deploy)
101
+
102
+ dotenv_file = fetch(:hyperf_dotenv_file)
103
+
104
+ run_locally do
105
+ if dotenv_file.empty? || test("[ ! -e #{dotenv_file} ]")
106
+ raise Capistrano::ValidationError,
107
+ "Must prepare dotenv file [#{dotenv_file}] locally before deploy!"
108
+ end
109
+ end
110
+
111
+ on roles fetch(:hyperf_roles) do
112
+ upload! dotenv_file, "#{release_path}/.env"
113
+ end
114
+ end
115
+
116
+ desc 'Execute a provided hyperf command.'
117
+ task :run, [:command_name] do |_t, args|
118
+ ask(:cmd, 'list') # Ask only runs if argument is not provided
119
+ command = args[:command_name] || fetch(:cmd)
120
+
121
+ on roles fetch(:hyperf_roles) do
122
+ within release_path do
123
+ execute :php,
124
+ "bin/hyperf.php",
125
+ command,
126
+ *args.extras,
127
+ fetch(:hyperf_run_flags)
128
+ end
129
+ end
130
+
131
+ # Enable task hyperf to be ran more than once
132
+ Rake::Task['hyperf:run'].reenable
133
+ end
134
+
135
+ desc 'Run the database migrations.'
136
+ task :migrate do
137
+ hyperf_roles = fetch(:hyperf_roles)
138
+ hyperf_run_flags = fetch(:hyperf_run_flags)
139
+
140
+ set(:hyperf_roles, fetch(:hyperf_migration_roles))
141
+ set(:hyperf_run_flags, fetch(:hyperf_migration_run_flags))
142
+
143
+ Rake::Task['hyperf:run'].invoke(:migrate)
144
+
145
+ set(:hyperf_roles, hyperf_roles)
146
+ set(:hyperf_run_flags, hyperf_run_flags)
147
+ end
148
+
149
+ desc 'Rollback the last database migration.'
150
+ task :migrate_rollback do
151
+ hyperf_roles = fetch(:hyperf_roles)
152
+ hyperf_run_flags = fetch(:hyperf_run_flags)
153
+
154
+ set(:hyperf_roles, fetch(:hyperf_migration_roles))
155
+ set(:hyperf_run_flags, fetch(:hyperf_migration_run_flags))
156
+
157
+ Rake::Task['hyperf:run'].invoke('migrate:rollback')
158
+
159
+ set(:hyperf_roles, hyperf_roles)
160
+ set(:hyperf_run_flags, hyperf_run_flags)
161
+ end
162
+
163
+ before 'deploy:starting', 'hyperf:resolve_linked_dirs'
164
+ before 'deploy:starting', 'hyperf:resolve_acl_paths'
165
+ after 'deploy:starting', 'hyperf:ensure_linked_dirs_exist'
166
+ after 'deploy:updating', 'hyperf:ensure_acl_paths_exist'
167
+ before 'deploy:updated', 'deploy:set_permissions:acl'
168
+ before 'deploy:updated', 'hyperf:upload_dotenv_file'
169
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-hyperf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gang Wu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-composer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-file-permissions
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Hyperf deployment for Capistrano 3.x
84
+ email:
85
+ - gokure@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - capistrano-hyperf.gemspec
97
+ - lib/capistrano-hyperf.rb
98
+ - lib/capistrano/hyperf.rb
99
+ - lib/capistrano/tasks/hyperf.rake
100
+ homepage: https://github.com/gokure/capistrano-hyperf
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.0.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Hyperf specific deployment options for Capistrano 3.x
123
+ test_files: []