capistrano-spa 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +4 -0
- data/capistrano-spa.gemspec +22 -0
- data/lib/capistrano/spa.rb +1 -0
- data/lib/capistrano/tasks/spa.rake +65 -0
- data/lib/capistrano-spa.rb +0 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 33e81a7627dc79c0c3e40d41b17d307958996a30
|
|
4
|
+
data.tar.gz: 62df7aea1a418e6ba9b1cbfca7c9c9e87c7793eb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a743db04e9d1656bdf090ca64ab5465a3308e30c0324cb1e5fbb8a4b42cc698b67d81b9e3446c0d4242eb4f92d69386e08b4b1404704e9bda6205886a12ab4cc
|
|
7
|
+
data.tar.gz: be66fb55246bb9cdbbbc20c26c564e57105d7cf89e7a4003c1aed5bc7d9bea7564a9aab54ed319182b8aa810f604d936838b998535acdbc0820ce48630145a16
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2017 Efigence
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Capistrano::SPA
|
|
2
|
+
|
|
3
|
+
Want to deploy a single-page-application (which uses your rails api) along with your rails backend?
|
|
4
|
+
|
|
5
|
+
#### Requirements
|
|
6
|
+
|
|
7
|
+
* using capistrano v3
|
|
8
|
+
* keeping front-end app in separate repository
|
|
9
|
+
* not keeping `public` directory inside your rails app repository
|
|
10
|
+
|
|
11
|
+
#### Installation
|
|
12
|
+
|
|
13
|
+
1. Add to Gemfile: `gem "capistrano-spa"`
|
|
14
|
+
2. Require in Capfile: `require 'capistrano/spa'`
|
|
15
|
+
|
|
16
|
+
#### Usage
|
|
17
|
+
|
|
18
|
+
Preferred way is to use it with [capistrano rsync](https://github.com/Bladrak/capistrano-rsync) extension.
|
|
19
|
+
|
|
20
|
+
Task `spa:all` consists of 4 tasks:
|
|
21
|
+
|
|
22
|
+
1. `spa:create_cache` - clones your SPA app into `YOUR_RAILS_APP/tmp` (or other dir of your choice)
|
|
23
|
+
2. `spa:update_cache` - updates spa cache dir, if already been cloned
|
|
24
|
+
3. `spa:build`: builds the SPA app with command you've passed (defaults to `yarn install && yarn build`)
|
|
25
|
+
4. `spa:copy_to_rsync_dir`: copies the built package (that usually means `dist`) into the `public` folder of rsync cache directory of your Rails application
|
|
26
|
+
|
|
27
|
+
You need to call the Capistrano task provided by this gem by yourself (this way you can call it anytime you need - depending on your deploy strategy). If you're using `capistrano-rsync`, then proper way to do it is after rails rsync cache dir has been prepared - it's going to append content of SPA app into `public` dir just before it's rsync'ed to server.
|
|
28
|
+
|
|
29
|
+
`after 'rsync:stage_done', 'spa:all'`
|
|
30
|
+
|
|
31
|
+
If you need asset pipeline's assets on production, then it's advised to precompile then locally just after running `spa:all`. This way rails assets will get appended to public folder before rsync'ing data to server. As an alternative to `capistrano/rails/migrations`, you can do it like:
|
|
32
|
+
|
|
33
|
+
# Precompile webpack assets locally
|
|
34
|
+
namespace :assets do
|
|
35
|
+
task :compile do
|
|
36
|
+
run_locally do
|
|
37
|
+
with rails_env: fetch(:stage) do
|
|
38
|
+
Dir.chdir fetch(:rsync_stage) do
|
|
39
|
+
execute 'cp config/database.dev.yml config/database.yml'
|
|
40
|
+
execute :bundle, 'exec bin/rails assets:precompile'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
after 'spa:all', 'assets:compile'
|
|
48
|
+
|
|
49
|
+
#### Configuration
|
|
50
|
+
|
|
51
|
+
* `:spa_repo_url` - required
|
|
52
|
+
* `:spa_cache_dir`, defaults to: `tmp/spa`
|
|
53
|
+
* `:spa_branch`, , defaults to: `master`
|
|
54
|
+
* `:spa_build_dir`, defaults to: `dist`
|
|
55
|
+
* `:spa_git_remote`, defaults to: `origin`
|
|
56
|
+
* `:rsync_cache_dir`, default to `tmp/deploy`
|
|
57
|
+
* `:spa_build_cmds`, default to: `[[:yarn, "install"], [:yarn, "build"]]`
|
|
58
|
+
|
|
59
|
+
#### Notes
|
|
60
|
+
|
|
61
|
+
If you don't want to use rsync strategy for your rails app, you can skip the last task (`spa:copy_to_rsync_dir`) and move the SPA build to the server by yourself in anyway you like it.
|
|
62
|
+
|
|
63
|
+
Also, depending on your `apache/nginx` server config, `index.html` file might be served automatically, or if it's not on static files whitelist you can either add it to the list or serve `index.html` from controller, like:
|
|
64
|
+
|
|
65
|
+
root "welcome#index"
|
|
66
|
+
|
|
67
|
+
def index
|
|
68
|
+
render file: 'public/index.html', layout: false
|
|
69
|
+
end
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = "capistrano-spa"
|
|
7
|
+
gem.version = '0.0.1'
|
|
8
|
+
gem.authors = ["Jacek Grzybowski"]
|
|
9
|
+
gem.email = ["jacek213@gmail.com"]
|
|
10
|
+
gem.description = %q{Capistrano tasks for Single Page Apps deployment}
|
|
11
|
+
gem.summary = %q{Capistrano tasks for Single Page Apps deployment}
|
|
12
|
+
gem.homepage = "https://github.com/efigence/capistrano-spa"
|
|
13
|
+
|
|
14
|
+
gem.licenses = ["MIT"]
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($/)
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
gem.add_dependency 'capistrano', '~> 3.1'
|
|
21
|
+
gem.add_dependency 'capistrano-bundler', '~> 1.1'
|
|
22
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
load File.expand_path("../tasks/spa.rake", __FILE__)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
namespace :load do
|
|
2
|
+
task :defaults do
|
|
3
|
+
set :spa_cache_dir, "tmp/spa"
|
|
4
|
+
set :spa_branch, "master"
|
|
5
|
+
set :spa_build_dir, "dist"
|
|
6
|
+
set :spa_git_remote, "origin"
|
|
7
|
+
set :rsync_cache_dir, fetch(:rsync_stage, "tmp/deploy")
|
|
8
|
+
set :spa_build_cmds, [
|
|
9
|
+
[:yarn, "install"],
|
|
10
|
+
[:yarn, "build"],
|
|
11
|
+
]
|
|
12
|
+
set :spa_repo_url, -> { raise Capistrano::ValidationError, "spa_repo_url param is required!" }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
namespace :spa do
|
|
17
|
+
desc 'Clone SPA repository to cache dir, unless exists already'
|
|
18
|
+
task :create_cache do
|
|
19
|
+
next if File.directory?(fetch(:spa_cache_dir))
|
|
20
|
+
|
|
21
|
+
run_locally do
|
|
22
|
+
execute :git,
|
|
23
|
+
:clone,
|
|
24
|
+
fetch(:spa_repo_url),
|
|
25
|
+
fetch(:spa_cache_dir),
|
|
26
|
+
'--quiet --depth=1 --no-single-branch'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
desc 'Pull latest changes into SPA cache dir'
|
|
31
|
+
task :update_cache do
|
|
32
|
+
target = "#{fetch(:spa_git_remote)}/#{fetch(:spa_branch)}"
|
|
33
|
+
run_locally do
|
|
34
|
+
within fetch(:spa_cache_dir) do
|
|
35
|
+
execute :git, :fetch, '--quiet --all --prune --depth=1'
|
|
36
|
+
execute :git, :checkout, fetch(:spa_branch), '--quiet'
|
|
37
|
+
execute :git, :reset, target, '--hard'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
desc 'Build SPA application'
|
|
43
|
+
task :build do
|
|
44
|
+
run_locally do
|
|
45
|
+
within fetch(:spa_cache_dir) do
|
|
46
|
+
fetch(:spa_build_cmds).each do |cmd|
|
|
47
|
+
execute *cmd
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
desc 'Copy files to local rsync cache dir'
|
|
54
|
+
task :copy_to_rsync_dir do
|
|
55
|
+
destination_dir = "#{fetch(:rsync_cache_dir)}/public"
|
|
56
|
+
build_dir = "#{fetch(:spa_cache_dir)}/#{fetch(:spa_build_dir)}"
|
|
57
|
+
|
|
58
|
+
run_locally do
|
|
59
|
+
execute :rm, '-rf', destination_dir
|
|
60
|
+
execute :cp, '-r', build_dir, destination_dir
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
task :all => [:create_cache, :update_cache, :build, :copy_to_rsync_dir]
|
|
65
|
+
end
|
|
File without changes
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: capistrano-spa
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jacek Grzybowski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-30 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.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: capistrano-bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.1'
|
|
41
|
+
description: Capistrano tasks for Single Page Apps deployment
|
|
42
|
+
email:
|
|
43
|
+
- jacek213@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- Gemfile
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- capistrano-spa.gemspec
|
|
54
|
+
- lib/capistrano-spa.rb
|
|
55
|
+
- lib/capistrano/spa.rb
|
|
56
|
+
- lib/capistrano/tasks/spa.rake
|
|
57
|
+
homepage: https://github.com/efigence/capistrano-spa
|
|
58
|
+
licenses:
|
|
59
|
+
- MIT
|
|
60
|
+
metadata: {}
|
|
61
|
+
post_install_message:
|
|
62
|
+
rdoc_options: []
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
requirements: []
|
|
76
|
+
rubyforge_project:
|
|
77
|
+
rubygems_version: 2.6.8
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: Capistrano tasks for Single Page Apps deployment
|
|
81
|
+
test_files: []
|