caput 0.9.5 → 0.9.7

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
2
  SHA256:
3
- metadata.gz: 8f70afda0863b53a3471a330a939a2a16e6c11bf54bf091cde7f868ec8d24af8
4
- data.tar.gz: 18b1cad9051efcaaa9f98f8f9cfb3f34283b94e02d8a49451bcb8df7264ba43f
3
+ metadata.gz: 2ac684204558dde49abeacec8c4f9d208cdf6f343952ba1055f9eeb17556bb4c
4
+ data.tar.gz: d48dd167c60706289e1b957ed2af737822b741b2cca3425fb384f1fc70d3e96d
5
5
  SHA512:
6
- metadata.gz: c68f1efe34c294399396b0b04b2fd5284ee88e08b9c36a4696dcd11a979e21eab145e8f76152d65f35580b3f86edc20e784d26d9b481172b9537ecbbf477ec85
7
- data.tar.gz: 670fcae494a9817033ab253ec75eade086399cf314691417a0ceb1326c7a217a7fd3e94ae1a2dd3bbdb958604322b40c92714496ac4c203ca5f110a14aadb112
6
+ metadata.gz: fe9bae1509657360e2f54d27f3c7367c971357f5a24894f01e51f2b70e8662bf0ff7b4635e2fb36b4bfb3c727fbae554aa6a3649bec14f7df4286d93f1fe247a
7
+ data.tar.gz: 7182daf83c4216718aba8b8a6a8914b435f425ab11c8463e9048084f493843d96ab46e54f5aa0bdf8c373f6c27344d4287175342b1e697149180eaa875eb133b
data/README.md CHANGED
@@ -51,6 +51,35 @@ Edit `caput.conf` with the correct values for your setup:
51
51
 
52
52
  > Make sure MySQL and Nginx are installed on the server. Caput will notify you if these dependencies are missing.
53
53
 
54
+ If not already the case, update the config/database.yml file to use MySQL for storage instead of the default Sqlite3. The below section can be used as a template.
55
+
56
+ ```production:
57
+ primary: &production_primary
58
+ adapter: mysql2
59
+ encoding: utf8mb4
60
+ database: <%= Rails.application.credentials.dig(:mysql, :database) %>
61
+ username: <%= Rails.application.credentials.dig(:mysql, :username) %>
62
+ password: <%= Rails.application.credentials.dig(:mysql, :password) %>
63
+ host: localhost
64
+ port: 3306
65
+ cache:
66
+ <<: *production_primary
67
+ queue:
68
+ <<: *production_primary
69
+ cable:
70
+ <<: *production_primary
71
+ ```
72
+
73
+ The above also requires the database information is added to the Rails credentials file by running rails credentials:edit and adding a MySQL section.
74
+
75
+ ```mysql:
76
+ database: <DATABASE NAME>
77
+ username: <DATABASE USERNAME>
78
+ password: <DATABASE PASSWORD>
79
+ ```
80
+
81
+ The database name is typically the application name suffixed with '_production'.
82
+
54
83
  ### 3. Prepare the server
55
84
 
56
85
  Run:
@@ -61,7 +90,7 @@ caput server
61
90
 
62
91
  Caput will:
63
92
 
64
- - Validate prerequisites (MySQL client/server, Nginx, setup user, DNS)
93
+ - Validate prerequisites (MySQL client/server, Nginx, setup user, DNS)
65
94
  - Create the Capistrano-compatible folder structure
66
95
  - Set up a **systemd service** for Puma to serve requests in the background
67
96
  - Configure permissions for the `deploy` user
@@ -81,7 +110,12 @@ This will:
81
110
  - Add Capistrano configuration and necessary files to your local Rails repository
82
111
  - Make the repository ready for deployments
83
112
 
84
- > Currently, `caput server` and `caput local` must be run separately, in that order. In the future, these may be combined into a single `caput setup` command.
113
+ ### 5. Deploy the application
114
+
115
+ Once the above has been performed, the application can be deployed using standard Capistrano commands.
116
+
117
+ ```cap production deploy
118
+ ```
85
119
 
86
120
  ---
87
121
 
data/lib/caput/config.rb CHANGED
@@ -36,7 +36,7 @@ module Caput
36
36
 
37
37
  # Ruby version to use with rbenv. This version will be installed via rbenv on the server.
38
38
  # It needs to match the RUBY version used by the Ruby on Rails application being deployed.
39
- RUBY_VERSION="3.2.2"
39
+ RUBY_VERSION="3.3.6"
40
40
 
41
41
  # Path on the server where app will be deployed. This will be the root directory on the
42
42
  # server where the Ruby on Rails application will be deployed by Capistrano.
data/lib/caput/local.rb CHANGED
@@ -35,7 +35,6 @@ module Caput
35
35
 
36
36
  FileUtils.mkdir_p('config/deploy')
37
37
  deploy_rb = 'config/deploy.rb'
38
- backup_file(deploy_rb)
39
38
  File.open(deploy_rb, 'a') do |f|
40
39
  f.puts <<~DEPLOY
41
40
 
@@ -48,6 +47,7 @@ module Caput
48
47
  set :puma_pid, "#{deploy_path}/shared/tmp/pids/puma.pid"
49
48
  ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
50
49
  set :linked_files, fetch(:linked_files, []).push('config/master.key')
50
+ set :linked_dirs, fetch(:linked_dirs, []).push('storage')
51
51
  DEPLOY
52
52
  end
53
53
 
@@ -73,10 +73,5 @@ module Caput
73
73
  end
74
74
  end
75
75
 
76
- def backup_file(path)
77
- return unless File.exist?(path)
78
- bak = "#{path}.bak"
79
- FileUtils.cp(path, bak)
80
- end
81
76
  end
82
77
  end
data/lib/caput/server.rb CHANGED
@@ -104,11 +104,65 @@ module Caput
104
104
  if [ -d "#{deploy_path}" ]; then
105
105
  echo "Deploy directories already exist"
106
106
  else
107
- sudo mkdir -p "#{deploy_path}/shared/tmp/pids" "#{deploy_path}/shared/tmp/sockets" "#{deploy_path}/shared/log"
107
+ sudo mkdir -p \
108
+ "#{deploy_path}/shared/tmp/pids" \
109
+ "#{deploy_path}/shared/tmp/sockets" \
110
+ "#{deploy_path}/shared/log" \
111
+ "#{deploy_path}/shared/storage" \
112
+ "#{deploy_path}/shared/config"
108
113
  sudo chown -R #{deploy_user}:#{deploy_user} "#{deploy_path}"
109
114
  fi
110
115
  BASH
111
116
 
117
+ puts "Upload master key if it exists"
118
+ master_path = "config/master.key"
119
+ if File.exist?(master_path)
120
+ remote.upload_file!(master_path, "/tmp/master.key")
121
+ remote.exec!("sudo mv /tmp/master.key #{deploy_path}/shared/config/master.key")
122
+ remote.exec!("sudo chmod 0400 #{deploy_path}/shared/config/master.key")
123
+ else
124
+ puts "Note: No master key exists in local directory"
125
+ end
126
+
127
+ puts "\nCreate MySQL user if it doesn't exist"
128
+
129
+ # Get username and password from the local configuration file
130
+ require 'active_support'
131
+ require 'active_support/encrypted_configuration'
132
+ require 'yaml'
133
+ rails_root = Dir.pwd
134
+ credentials_path = File.join(rails_root, 'config', 'credentials.yml.enc')
135
+ master_key_path = File.join(rails_root, 'config', 'master.key')
136
+ master_key = ENV['RAILS_MASTER_KEY'] || (File.exist?(master_key_path) && File.read(master_key_path).strip)
137
+ raise "Master key not found in ENV['RAILS_MASTER_KEY'] or #{master_key_path}" unless master_key
138
+
139
+ # Create encrypted configuration
140
+ conf = ActiveSupport::EncryptedConfiguration.new(
141
+ config_path: credentials_path,
142
+ key_path: master_key_path,
143
+ env_key: 'RAILS_MASTER_KEY',
144
+ raise_if_missing_key: true
145
+ )
146
+
147
+ creds = YAML.safe_load(conf.read)
148
+ mysql_database = creds.dig('mysql', 'database')
149
+ mysql_username = creds.dig('mysql', 'username')
150
+ mysql_password = creds.dig('mysql', 'password')
151
+
152
+ sql = <<~SQL
153
+ CREATE DATABASE IF NOT EXISTS #{mysql_database};
154
+ CREATE USER IF NOT EXISTS #{mysql_username}@localhost IDENTIFIED BY '#{mysql_password}';
155
+ GRANT ALL PRIVILEGES ON #{mysql_database}.* TO #{mysql_username}@localhost;
156
+ FLUSH PRIVILEGES;
157
+ SQL
158
+
159
+ # Escape quotes for bash
160
+ escaped_sql = sql.strip.gsub('"', '\"').gsub('$', '\$')
161
+
162
+ # Build the full command to run on the remote server
163
+ cmd = %Q(sudo mysql -e "#{escaped_sql}")
164
+ remote.exec!(cmd)
165
+
112
166
  puts "\nInstall Nginx site config..."
113
167
  nginx_conf = <<~NGINX
114
168
  server {
@@ -150,6 +204,8 @@ module Caput
150
204
  Type=simple
151
205
  User=#{deploy_user}
152
206
  WorkingDirectory=#{deploy_path}/current
207
+ Environment="RAILS_ENV=production"
208
+ Environment="RACK_ENV=production"
153
209
  ExecStart=#{deploy_path}/shared/bin/start_puma.sh
154
210
  Restart=always
155
211
 
@@ -230,6 +286,7 @@ module Caput
230
286
  BASH
231
287
 
232
288
  puts "\nServer preparation complete."
289
+ puts "\nBefore deploying, please verify that the deploy user has access to the the code repository."
233
290
  end
234
291
 
235
292
  def check_sudo!(user, server)
data/lib/caput/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Caput
2
- VERSION = '0.9.5'
2
+ VERSION = '0.9.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caput
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Bergek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-09 00:00:00.000000000 Z
11
+ date: 2025-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor