capistrano-craft 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 249fbb6884c17a8c88689bb3766cf51d64ecd3d6
4
- data.tar.gz: 77503ac4c7d107900c120cca8ca06f4d97feaa4a
2
+ SHA256:
3
+ metadata.gz: 8bd49dc866da5b1f1b81620fff6c77d952e8d5067f3f6bc1268026eb87016f07
4
+ data.tar.gz: 29e36ef83ca0703c993e80f48051a9e8b5fcdf289881122f96f2ad28b5464b7c
5
5
  SHA512:
6
- metadata.gz: 52ac278d6f8e8460c6cc3c5ef5315621d10f16b4be981bd9fae1913774afc8158a1d26785357a4ccaa075e2cee7ae2540ead7bc5bfcb89f0f584deb0215b38a6
7
- data.tar.gz: 8da018126d8717da21f1fcf9bd3d4eb670f11bc7dfbce5af5a3e63e850f8994a9299599730eafcc7c0f61d6986b8f78b1dc009c0f5e87229288f90cf075e62b0
6
+ metadata.gz: 75b24eee818dd00358fe1cdf9694167ccaa1827b0281e2cfdae67b6e0ee3f01a51a46d15dd290d722cbd98d30ec5cabafac7bd44b7836e5bd73abe0ce75276a6
7
+ data.tar.gz: 33313144755a227f0940fe9715dcc1c6548176630291e78a0739ed88413c3aed86fd906bcb4b19cf1dd78d67f80bf6c9862d7f103480c8bfc121aa3029ab5138
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ # Release Notes for Capistrano Craft
2
+
3
+ ## 0.3.0 - 2020-08-13
4
+
5
+ - Better compatibility with Craft 3.5
6
+ - Project config automatically applied after deployment. A backup command is executed first as an insurance against database corruption
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in capitrano-craft.gemspec
4
4
  gemspec
5
+
6
+ gem "rspec"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-craft (0.1.3)
4
+ capistrano-craft (0.3.0)
5
5
  capistrano (~> 3.1)
6
6
  capistrano-composer (~> 0.0.6)
7
7
 
@@ -10,21 +10,35 @@ GEM
10
10
  specs:
11
11
  airbrussh (1.4.0)
12
12
  sshkit (>= 1.6.1, != 1.7.0)
13
- capistrano (3.11.2)
13
+ capistrano (3.12.1)
14
14
  airbrussh (>= 1.0.0)
15
15
  i18n
16
16
  rake (>= 10.0.0)
17
17
  sshkit (>= 1.9.0)
18
18
  capistrano-composer (0.0.6)
19
19
  capistrano (>= 3.0.0.pre)
20
- concurrent-ruby (1.1.5)
21
- i18n (1.7.0)
20
+ concurrent-ruby (1.1.6)
21
+ diff-lcs (1.3)
22
+ i18n (1.8.5)
22
23
  concurrent-ruby (~> 1.0)
23
24
  net-scp (2.0.0)
24
25
  net-ssh (>= 2.6.5, < 6.0.0)
25
26
  net-ssh (5.2.0)
26
- rake (13.0.0)
27
- sshkit (1.20.0)
27
+ rake (13.0.1)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.1)
33
+ rspec-support (~> 3.9.1)
34
+ rspec-expectations (3.9.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.2)
41
+ sshkit (1.21.0)
28
42
  net-scp (>= 1.1.2)
29
43
  net-ssh (>= 2.8.0)
30
44
 
@@ -33,6 +47,7 @@ PLATFORMS
33
47
 
34
48
  DEPENDENCIES
35
49
  capistrano-craft!
50
+ rspec
36
51
 
37
52
  BUNDLED WITH
38
53
  2.0.2
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Capistrano::Craft
2
2
 
3
- As of November 2019 this is very still very much under development. Please make sure you have appropriate backups to avoid any potential data loss.
4
-
5
3
  This gem automates the deployment of Craft CMS apps with Capistrano. It will automatically detect local and remote environment settings to make synchronizing of database and assets straightforward.
6
4
 
5
+ - [x] Support for asset and database synchronization
6
+ - [x] Support for PostgreSQL databases
7
+ - [ ] Support for MySQL databases
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -18,10 +20,13 @@ Or install system wide:
18
20
 
19
21
  ## Usage
20
22
 
23
+ For a beginners guide to deploying your site (especially useful if you have little to no experience with Ruby) please see this blog article: https://cdyer.co.uk/blog/deploying-craft-cms-to-a-vps-server-with-capistrano
24
+
21
25
  The setting you will likely need to customize is:
22
26
  ```
23
27
  # This should be your command to compile assets for production
24
- set :craft_compile_assets, "npm run production --production --silent"
28
+ set :craft_compile_assets, true
29
+ set :craft_compile_assets_command, "npm install && npm run production --production --silent"
25
30
  ```
26
31
 
27
32
  If you are using PHP-FPM it is necessary to restart it after deployment. Currently capistrano-craft doesn't handle this for you and you may need to add something along the lines of the following to your `deploy.rb` file.
@@ -38,7 +43,7 @@ end
38
43
 
39
44
  ### Compiling Assets
40
45
 
41
- Change `:craft_compile_assets` to be your production asset compilation command. By default, it is assumed your project has a `package.json` file and `npm install` will be run first. The default asset compilcation command is `npm run production --production --silent`
46
+ Change `:craft_compile_assets_command` to be your production asset compilation command. By default, it is assumed your project has a `package.json` file and `npm install` will be run first. The default asset compilcation command is `npm run production --production --silent`. You can disable asset compilation altogether by settng `:craft_compile_assets` to `false`.
42
47
 
43
48
  ### Synchronize Database
44
49
 
@@ -65,7 +70,8 @@ set :craft_local_backups, "backups"
65
70
  set :craft_remote_backups, "shared/backups"
66
71
 
67
72
  # assets
68
- set :craft_compile_assets, "npm run production --production --silent"
73
+ set :craft_compile_assets, true
74
+ set :craft_compile_assets_command, "yarn install && yarn run production"
69
75
 
70
76
  # console
71
77
  set :craft_console_path, -> { "craft" }
@@ -17,7 +17,8 @@ set :craft_local_backups, "backups"
17
17
  set :craft_remote_backups, "shared/backups"
18
18
 
19
19
  # assets
20
- set :craft_compile_assets, "production"
20
+ set :craft_compile_assets, true
21
+ set :craft_compile_assets_command, "yarn install && yarn run production"
21
22
 
22
23
  # console
23
24
  set :craft_console_path, -> { "craft" }
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Craft
3
- VERSION = "0.1.3"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -47,55 +47,88 @@ module Capistrano
47
47
  File.join(fetch(:craft_local_backups), "#{backup_date.join('-')}_#{backup_time.join('-')}.sql")
48
48
  end
49
49
 
50
- def postgres_dump(env, output)
50
+ def postgres_dump(env, config, output)
51
51
  execute SSHKit::Command.new <<-EOCOMMAND
52
52
  source "#{env}"
53
- PGPASSWORD=$DB_PASSWORD pg_dump -U $DB_USER -h $DB_SERVER -p $DB_PORT -F p --no-owner $DB_DATABASE > #{output}
53
+ PGPASSWORD=$DB_PASSWORD pg_dump -U $DB_USER -h #{config[:host]} -p #{config[:port]} -F p --no-owner #{config[:database]} > #{output}
54
54
  EOCOMMAND
55
55
  end
56
56
 
57
57
  def mysql_dump(env, output)
58
58
  end
59
59
 
60
- def postgres_restore(env, input)
60
+ def postgres_restore(env, config, input)
61
61
  execute SSHKit::Command.new <<-EOCOMMAND
62
62
  source "#{env}"
63
- PGPASSWORD=$DB_PASSWORD dropdb -U $DB_USER -h $DB_SERVER -p $DB_PORT $DB_DATABASE
64
- PGPASSWORD=$DB_PASSWORD createdb -U $DB_USER -h $DB_SERVER -p $DB_PORT $DB_DATABASE
65
- PGPASSWORD=$DB_PASSWORD psql -U $DB_USER -d $DB_DATABASE -h $DB_SERVER -p $DB_PORT -q < "#{input}"
63
+ PGPASSWORD=$DB_PASSWORD dropdb -U $DB_USER -h #{config[:host]} -p #{config[:port]} #{config[:database]}
64
+ PGPASSWORD=$DB_PASSWORD createdb -U $DB_USER -h #{config[:host]} -p #{config[:port]} #{config[:database]}
65
+ PGPASSWORD=$DB_PASSWORD psql -U $DB_USER -d #{config[:database]} -h #{config[:host]} -p #{config[:port]} -q < "#{input}"
66
66
  EOCOMMAND
67
67
  end
68
68
 
69
69
  def mysql_restore(env, input)
70
70
  end
71
71
 
72
- def craft_database(env)
73
- driver = capture SSHKit::Command.new <<-EOCOMMAND
72
+ def database_config(env)
73
+ config = capture SSHKit::Command.new <<-EOCOMMAND
74
74
  source "#{env}"
75
- echo $DB_DRIVER
75
+ echo "$DB_DSN,$DB_DRIVER,$DB_SERVER,$DB_PORT,$DB_DATABASE"
76
76
  EOCOMMAND
77
77
 
78
- case driver.strip
79
- when "pgsql" then return :pgsql
80
- when "mysql" then return :mysql
78
+ params = config.split(",")
79
+ parsed = {}
80
+
81
+ if params[0].length > 0
82
+ # Using the newer style DB_DSN config style
83
+ dsn = params[0].split(":")
84
+
85
+ # Split in config chunks eg. host=<host>
86
+ database = dsn[1].split(";").map { |str|
87
+ tuple = str.split("=")
88
+ [tuple[0], tuple[1]]
89
+ }.to_h
90
+
91
+ parsed = {
92
+ driver: dsn[0],
93
+ host: database["host"],
94
+ port: database["port"],
95
+ database: database["dbname"]
96
+ }
81
97
  else
82
- raise "Unable to determine database driver: \"#{driver.strip}\""
98
+ # Using the older style config style
99
+ parsed = {
100
+ driver: params[1],
101
+ host: params[2],
102
+ port: params[3],
103
+ database: params[4]
104
+ }
83
105
  end
106
+
107
+ case parsed[:driver].strip
108
+ when "pgsql" then parsed[:driver] = :pgsql
109
+ when "mysql" then parsed[:driver] = :mysql
110
+ else
111
+ raise "Unable to determine database driver: \"#{parsed[:driver].strip}\""
112
+ end
113
+
114
+ return parsed
84
115
  end
85
116
 
86
117
  def database_dump(env, input)
87
- if craft_database(env) == :pgsql
88
- postgres_dump(env, input)
118
+ config = database_config(env)
119
+ if config[:driver] == :pgsql
120
+ postgres_dump(env, config, input)
89
121
  else
90
- mysql_dump(env, input)
122
+ mysql_dump(env, config, input)
91
123
  end
92
124
  end
93
125
 
94
126
  def database_restore(env, input)
95
- if craft_database(env) == :pgsql
96
- postgres_restore(env, input)
127
+ config = database_config(env)
128
+ if config[:driver] == :pgsql
129
+ postgres_restore(env, config, input)
97
130
  else
98
- mysql_restore(env, input)
131
+ mysql_restore(env, config, input)
99
132
  end
100
133
  end
101
134
  end
@@ -26,6 +26,16 @@ namespace :craft do
26
26
  end
27
27
  end
28
28
 
29
+ namespace :config do
30
+ desc "Apply the project config to database after running Craft backup command"
31
+ task :apply do
32
+ on release_roles(fetch(:craft_deploy_roles)) do
33
+ craft_console "backup/db"
34
+ craft_console "project-config/apply"
35
+ end
36
+ end
37
+ end
38
+
29
39
  namespace :assets do
30
40
  desc "Synchronise assets between local and remote server"
31
41
  task :sync do
@@ -26,7 +26,7 @@ namespace :db do
26
26
  download! remote_backup_file, local_backup_file
27
27
 
28
28
  # Remove temp file
29
- execute "rm #{backup_file}"
29
+ execute "rm #{remote_backup_file}"
30
30
 
31
31
  set :backup_filename, local_backup_file
32
32
  end
@@ -5,14 +5,16 @@ namespace :deploy do
5
5
 
6
6
  desc 'Compile assets'
7
7
  task :compile_assets do
8
- on release_roles(fetch(:craft_deploy_roles)) do
9
- within release_path do
10
- execute :yarn, "install"
11
- execute :yarn, "run", fetch(:craft_compile_assets)
8
+ if fetch(:craft_compile_assets)
9
+ on release_roles(fetch(:craft_deploy_roles)) do
10
+ within release_path do
11
+ execute "cd #{release_path} && #{fetch(:craft_compile_assets_command)}"
12
+ end
12
13
  end
13
14
  end
14
15
  end
15
16
 
16
17
  after 'deploy:updated', 'deploy:compile_assets'
18
+ after 'deploy:finished', 'craft:config:apply'
17
19
  after 'deploy:finished', 'craft:cache:clear'
18
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-craft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Dyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-13 00:00:00.000000000 Z
11
+ date: 2020-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -46,6 +46,8 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".rspec"
50
+ - CHANGELOG.md
49
51
  - CODE_OF_CONDUCT.md
50
52
  - Gemfile
51
53
  - Gemfile.lock
@@ -82,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
84
  - !ruby/object:Gem::Version
83
85
  version: '0'
84
86
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.6.14.3
87
+ rubygems_version: 3.0.3
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Capistrano Craft - Easy deployment of Symfony 4 apps with Ruby over SSH