capistrano-nuxt2 0.2.17
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +222 -0
- data/Rakefile +3 -0
- data/lib/capistrano/nuxt2/base_helpers.rb +120 -0
- data/lib/capistrano/nuxt2/certbot.rb +1 -0
- data/lib/capistrano/nuxt2/nginx.rb +1 -0
- data/lib/capistrano/nuxt2/nginx_helpers.rb +56 -0
- data/lib/capistrano/nuxt2/nuxt.rb +1 -0
- data/lib/capistrano/nuxt2/nuxt3.rb +1 -0
- data/lib/capistrano/nuxt2/proxy_nginx.rb +1 -0
- data/lib/capistrano/nuxt2/version.rb +5 -0
- data/lib/capistrano/nuxt2/vue.rb +1 -0
- data/lib/capistrano/nuxt2.rb +9 -0
- data/lib/capistrano/tasks/certbot.rake +256 -0
- data/lib/capistrano/tasks/nginx.rake +209 -0
- data/lib/capistrano/tasks/nuxt.rake +159 -0
- data/lib/capistrano/tasks/nuxt3.rake +332 -0
- data/lib/capistrano/tasks/proxy_nginx.rake +415 -0
- data/lib/capistrano/tasks/vue.rake +125 -0
- data/lib/generators/capistrano/nuxt2/templates/nginx/https_ssl_options.erb +29 -0
- data/lib/generators/capistrano/nuxt2/templates/nginx.conf.erb +176 -0
- data/lib/generators/capistrano/nuxt2/templates/nginx_app_conf.erb +46 -0
- data/lib/generators/capistrano/nuxt2/templates/nginx_proxy_conf.erb +137 -0
- data/lib/generators/capistrano/nuxt2/templates/nuxt3_ssr_service.erb +38 -0
- data/lib/tasks/capistrano/nuxt2_tasks.rake +4 -0
- metadata +124 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
require 'capistrano/nuxt2/base_helpers'
|
|
2
|
+
include Capistrano::Nuxt2::BaseHelpers
|
|
3
|
+
|
|
4
|
+
namespace :load do
|
|
5
|
+
task :defaults do
|
|
6
|
+
|
|
7
|
+
set :nuxt3_stat_file, -> { "_builded_app" }
|
|
8
|
+
set :nuxt3_logs_file, -> { "_builded_logs" }
|
|
9
|
+
set :nuxt3_done_file, -> { "_builded_frontend" }
|
|
10
|
+
|
|
11
|
+
set :nuxt3_use_nvm, -> { false }
|
|
12
|
+
set :nuxt3_nvm_path, -> { "~/.nvm" }
|
|
13
|
+
set :nuxt3_nvm_version, -> { "20.19.0" }
|
|
14
|
+
set :nuxt3_nvm_script, -> { "$HOME/.nvm/nvm.sh" }
|
|
15
|
+
|
|
16
|
+
set :nuxt3_app_roles, -> { :app }
|
|
17
|
+
|
|
18
|
+
# Which deploy:published hook runs:
|
|
19
|
+
# :ssr -> rebuild_app (build + sync .output + restart Nitro service) [App default]
|
|
20
|
+
# :static -> rebuild_static (generate + sync public, served by nginx) [Website]
|
|
21
|
+
set :nuxt3_deploy_mode, -> { :ssr }
|
|
22
|
+
|
|
23
|
+
# Nuxt 3 build output lives in `.output/` (not `dist/`):
|
|
24
|
+
# .output/server/index.mjs -> Nitro SSR entrypoint
|
|
25
|
+
# .output/public/ -> static assets (also the `nuxt generate` result)
|
|
26
|
+
set :nuxt3_build_dir, -> { ".output" }
|
|
27
|
+
# Shared dir the built `.output/` is rsynced into for the SSR service.
|
|
28
|
+
set :nuxt3_output_folder, -> { "output" }
|
|
29
|
+
|
|
30
|
+
## Maybe nonsense .. builds `APP_NAME_STG_DEPLOY_MODE`
|
|
31
|
+
set :nuxt3_stage_env_var, -> { build_deploy_env_var }
|
|
32
|
+
|
|
33
|
+
# === SSR (Nitro Node service) ===
|
|
34
|
+
set :nuxt3_ssr_roles, -> { :app }
|
|
35
|
+
set :nuxt3_ssr_service_file, -> { "#{fetch(:application)}_#{fetch(:stage)}_nuxt3_ssr" }
|
|
36
|
+
set :nuxt3_ssr_service_old, -> { "nuxt3_ssr_#{fetch(:application)}_#{fetch(:stage)}" }
|
|
37
|
+
set :nuxt3_systemd_path, -> { "/lib/systemd/system" }
|
|
38
|
+
set :nuxt3_pid_path, -> { "#{shared_path}/pids" }
|
|
39
|
+
set :nuxt3_ssr_user, -> { fetch(:user, 'deploy') }
|
|
40
|
+
set :nuxt3_ssr_host, -> { "127.0.0.1" }
|
|
41
|
+
# PLACEHOLDER default – override per stage (analog :nginx_upstream_port).
|
|
42
|
+
# Point the proxy here: set :nginx_upstream_port, fetch(:nuxt3_ssr_port)
|
|
43
|
+
set :nuxt3_ssr_port, -> { 3500 }
|
|
44
|
+
# Extra `Environment=` lines for the unit, e.g. { "API_BASE" => "https://..." }
|
|
45
|
+
set :nuxt3_ssr_env, -> { {} }
|
|
46
|
+
set :nuxt3_ssr_log_lines, -> { 100 }
|
|
47
|
+
# Auto-restart the Nitro service from the deploy:published hook.
|
|
48
|
+
# Set to `false` for the FIRST deploy (the systemd unit doesn't exist yet,
|
|
49
|
+
# so a restart would fail) — deploy once, then `nuxt3:ssr:configure` to
|
|
50
|
+
# create+enable+start the unit, then flip this back to `true`.
|
|
51
|
+
set :nuxt3_ssr_hooks, -> { true }
|
|
52
|
+
|
|
53
|
+
# Static mode: run rebuild_static from the deploy:published hook.
|
|
54
|
+
set :nuxt3_static_hooks, -> { true }
|
|
55
|
+
|
|
56
|
+
append :linked_files, fetch(:nuxt3_stat_file), fetch(:nuxt3_logs_file), fetch(:nuxt3_done_file)
|
|
57
|
+
append :linked_dirs, 'node_modules'
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
namespace :nuxt3 do
|
|
64
|
+
|
|
65
|
+
desc "output env var and stage"
|
|
66
|
+
task :output_env do
|
|
67
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
68
|
+
puts "🔧 Nuxt 3 stage: #{fetch(:stage)}"
|
|
69
|
+
puts "🔧 Nuxt 3 deploy mode: #{fetch(:nuxt3_stage_env_var)}"
|
|
70
|
+
puts "🔧 Nuxt 3 SSR upstream: #{fetch(:nuxt3_ssr_host)}:#{fetch(:nuxt3_ssr_port)}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
desc "Install dependencies"
|
|
75
|
+
task :install_dependencies do
|
|
76
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
77
|
+
within release_path do
|
|
78
|
+
execute :echo, "'installing|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
79
|
+
execute :rm, "-rf node_modules/*"
|
|
80
|
+
execute :rm, "-rf #{shared_path}/node_modules/*"
|
|
81
|
+
if fetch(:nuxt3_use_nvm, false)
|
|
82
|
+
env_vars = fetch(:default_env).map { |k, v| "#{k}=#{v}" }.join(" ")
|
|
83
|
+
execute %(bash -lc '#{nuxt3_nvm_prefix} && cd #{release_path} && env #{env_vars} npm install')
|
|
84
|
+
else
|
|
85
|
+
execute :npm, "install"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
desc "Build Nuxt 3 app (SSR → .output/server + .output/public)"
|
|
93
|
+
task :build do
|
|
94
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
95
|
+
within release_path do
|
|
96
|
+
execute :echo, "'building|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
97
|
+
if fetch(:nuxt3_use_nvm, false)
|
|
98
|
+
env_vars = fetch(:default_env).map { |k, v| "#{k}=#{v}" }.join(" ")
|
|
99
|
+
execute %(bash -lc '#{nuxt3_nvm_prefix} && cd #{release_path} && env #{env_vars} ./node_modules/.bin/nuxt build')
|
|
100
|
+
else
|
|
101
|
+
execute :npm, "run build"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
desc "Generate static Nuxt 3 site (prerender → .output/public)"
|
|
109
|
+
task :generate do
|
|
110
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
111
|
+
within release_path do
|
|
112
|
+
execute :echo, "'generating|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
113
|
+
execute :echo, "'Deploy - Render - LOGS :: #{ Time.now.strftime("%d.%m.%Y - %H:%M") } ::' > #{shared_path}/#{fetch(:nuxt3_logs_file)}"
|
|
114
|
+
if fetch(:nuxt3_use_nvm, false)
|
|
115
|
+
env_vars = fetch(:default_env).map { |k, v| "#{k}=#{v}" }.join(" ")
|
|
116
|
+
execute %(bash -lc '#{nuxt3_nvm_prefix} && cd #{release_path} && env #{env_vars} ./node_modules/.bin/nuxt generate')
|
|
117
|
+
else
|
|
118
|
+
execute :npm, "run generate 2>&1 | tee -a #{shared_path}/#{fetch(:nuxt3_logs_file)}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
desc "Sync full .output/ to shared (for SSR / Nitro service)"
|
|
126
|
+
task :sync_output do
|
|
127
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
128
|
+
execute :echo, "'syncing|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
129
|
+
execute :rsync, "-a --delete #{release_path}/#{fetch(:nuxt3_build_dir)}/ #{shared_path}/#{fetch(:nuxt3_output_folder)}/"
|
|
130
|
+
execute :echo, "'success|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
131
|
+
execute :touch, "#{shared_path}/#{fetch(:nuxt3_done_file)}"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
desc "Sync static .output/public/ to shared www (for nginx static serving)"
|
|
137
|
+
task :sync_static do
|
|
138
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
139
|
+
execute :echo, "'syncing|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
140
|
+
execute :rsync, "-a --delete #{release_path}/#{fetch(:nuxt3_build_dir)}/public/ #{shared_path}/www/"
|
|
141
|
+
execute :echo, "'success|deploy' > #{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
142
|
+
execute :touch, "#{shared_path}/#{fetch(:nuxt3_done_file)}"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
desc "Fix permissions (just in case)"
|
|
148
|
+
task :fix_permissions do
|
|
149
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
150
|
+
execute :sudo, :chown, "-R #{fetch(:user)}:#{fetch(:user)} #{release_path}"
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
desc "Setup defaults for Nuxt 3 app"
|
|
156
|
+
task :setup_app do
|
|
157
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
158
|
+
ensure_shared_www_path
|
|
159
|
+
ensure_shared_log_path
|
|
160
|
+
ensure_shared_output_path
|
|
161
|
+
ensure_shared_pids_path
|
|
162
|
+
execute :touch, "#{shared_path}/#{fetch(:nuxt3_stat_file)}"
|
|
163
|
+
execute :touch, "#{shared_path}/#{fetch(:nuxt3_logs_file)}"
|
|
164
|
+
execute :touch, "#{shared_path}/#{fetch(:nuxt3_done_file)}"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
desc "Install required node version with nvm"
|
|
170
|
+
task :install_nvm_node do
|
|
171
|
+
on roles(fetch(:nuxt3_app_roles)) do
|
|
172
|
+
if fetch(:nuxt3_use_nvm, false)
|
|
173
|
+
execute %(bash -lc 'source #{fetch(:nuxt3_nvm_script)} && nvm install #{fetch(:nuxt3_nvm_version)}')
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
desc "Rebuild Nuxt 3 SSR app (install → build → sync .output → restart service)"
|
|
180
|
+
task :rebuild_app do
|
|
181
|
+
invoke "nuxt3:install_dependencies"
|
|
182
|
+
invoke "nuxt3:build"
|
|
183
|
+
invoke "nuxt3:sync_output"
|
|
184
|
+
invoke "nuxt3:ssr:restart"
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
desc "Rebuild static Nuxt 3 site (install → generate → sync public)"
|
|
188
|
+
task :rebuild_static do
|
|
189
|
+
invoke "nuxt3:install_dependencies"
|
|
190
|
+
invoke "nuxt3:generate"
|
|
191
|
+
invoke "nuxt3:sync_static"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
desc "Regenerate static Nuxt 3 site (generate → sync public)"
|
|
195
|
+
task :regenerate_app do
|
|
196
|
+
invoke "nuxt3:generate"
|
|
197
|
+
invoke "nuxt3:sync_static"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## ── SSR Nitro Node service (mirrors recipes2go puma/sidekiq) ──
|
|
202
|
+
namespace :ssr do
|
|
203
|
+
|
|
204
|
+
def upload_nuxt3_ssr_service
|
|
205
|
+
puts "📤 Uploading Nuxt 3 SSR systemd service..."
|
|
206
|
+
ensure_shared_output_path
|
|
207
|
+
ensure_shared_pids_path
|
|
208
|
+
template2go("nuxt3_ssr_service", "/tmp/nuxt3_ssr.service")
|
|
209
|
+
execute :sudo, :mv, "/tmp/nuxt3_ssr.service", "#{fetch(:nuxt3_systemd_path)}/#{fetch(:nuxt3_ssr_service_file)}.service"
|
|
210
|
+
execute :sudo, "systemctl daemon-reload"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
desc "Upload only the Nuxt 3 SSR systemd service file"
|
|
214
|
+
task :upload_service do
|
|
215
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
216
|
+
upload_nuxt3_ssr_service
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
desc "Setup SSR service: upload unit (but don't enable yet)"
|
|
221
|
+
task :setup do
|
|
222
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
223
|
+
upload_nuxt3_ssr_service
|
|
224
|
+
puts "✅ Nuxt 3 SSR service setup completed. Service is NOT yet enabled or started."
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
desc "Activate and start the SSR service"
|
|
229
|
+
task :activate do
|
|
230
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
231
|
+
ensure_shared_pids_path
|
|
232
|
+
invoke "nuxt3:ssr:enable"
|
|
233
|
+
invoke "nuxt3:ssr:start"
|
|
234
|
+
puts "✅ Nuxt 3 SSR service activated and running!"
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
desc "Upload SSR service file, then enable it"
|
|
239
|
+
task :configure do
|
|
240
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
241
|
+
invoke "nuxt3:ssr:setup"
|
|
242
|
+
invoke "nuxt3:ssr:activate"
|
|
243
|
+
invoke "nuxt3:ssr:enable_if_needed"
|
|
244
|
+
puts "✅ Nuxt 3 SSR service configured and enabled!"
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
desc "Deploy SSR service (upload & start)"
|
|
249
|
+
task :deploy do
|
|
250
|
+
invoke "nuxt3:ssr:configure"
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
%w[start stop restart enable disable is-enabled].each do |command|
|
|
254
|
+
desc "#{command.capitalize} Nuxt 3 SSR service"
|
|
255
|
+
task command.gsub(/-/, '_') do
|
|
256
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
257
|
+
ensure_shared_pids_path if %w[start restart enable].include?(command)
|
|
258
|
+
execute :sudo, :systemctl, command, fetch(:nuxt3_ssr_service_file)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
desc "Enable SSR service if it's not already enabled"
|
|
264
|
+
task :enable_if_needed do
|
|
265
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
266
|
+
if test("systemctl is-enabled #{fetch(:nuxt3_ssr_service_file)} || echo disabled") == "disabled"
|
|
267
|
+
info "🔧 Enabling #{fetch(:nuxt3_ssr_service_file)} service..."
|
|
268
|
+
execute :sudo, "systemctl enable --now #{fetch(:nuxt3_ssr_service_file)}"
|
|
269
|
+
else
|
|
270
|
+
info "✅ #{fetch(:nuxt3_ssr_service_file)} is already enabled, skipping."
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
desc "Remove old-style SSR service files (nuxt3_ssr_APP_NAME)"
|
|
276
|
+
task :remove_old_services do
|
|
277
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
278
|
+
old_service_file = fetch(:nuxt3_ssr_service_old)
|
|
279
|
+
old_path = "/etc/systemd/system"
|
|
280
|
+
remove_app_service("Nuxt 3 SSR", fetch(:nuxt3_systemd_path), old_service_file)
|
|
281
|
+
remove_app_service("Nuxt 3 SSR", old_path, old_service_file)
|
|
282
|
+
remove_app_service("Nuxt 3 SSR", old_path, fetch(:nuxt3_ssr_service_file))
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
desc "Check SSR service status"
|
|
287
|
+
task :check_status do
|
|
288
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
289
|
+
execute :sudo, "systemctl status #{fetch(:nuxt3_ssr_service_file)} --no-pager"
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
desc "Get logs for the SSR service"
|
|
294
|
+
task :logs do
|
|
295
|
+
on roles fetch(:nuxt3_ssr_roles) do
|
|
296
|
+
execute :sudo, "journalctl -u #{fetch(:nuxt3_ssr_service_file)} -rn #{fetch(:nuxt3_ssr_log_lines, 100)}"
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
namespace :deploy do
|
|
305
|
+
after 'deploy:published', :rebuild_nuxt3_app do
|
|
306
|
+
if fetch(:nuxt3_deploy_mode) == :static
|
|
307
|
+
# Static: no node service, so the build+sync is the whole story.
|
|
308
|
+
invoke "nuxt3:rebuild_static" if fetch(:nuxt3_static_hooks)
|
|
309
|
+
else
|
|
310
|
+
# SSR: always build+sync .output, but only auto-restart the Nitro
|
|
311
|
+
# service when hooks are on. On the FIRST deploy the systemd unit does
|
|
312
|
+
# not exist yet → a bare `ssr:restart` would fail. Set
|
|
313
|
+
# `nuxt3_ssr_hooks=false` for the first deploy, then run
|
|
314
|
+
# `cap <stage> nuxt3:ssr:configure` (uploads + enables + starts the unit
|
|
315
|
+
# against the just-synced output), then flip `nuxt3_ssr_hooks=true` so
|
|
316
|
+
# subsequent deploys restart cleanly. Same pattern as puma/sidekiq hooks.
|
|
317
|
+
if fetch(:nuxt3_ssr_hooks)
|
|
318
|
+
invoke "nuxt3:rebuild_app"
|
|
319
|
+
else
|
|
320
|
+
invoke "nuxt3:install_dependencies"
|
|
321
|
+
invoke "nuxt3:build"
|
|
322
|
+
invoke "nuxt3:sync_output"
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
desc 'Server setup tasks'
|
|
330
|
+
task :setup do
|
|
331
|
+
invoke 'nuxt3:setup_app'
|
|
332
|
+
end
|