jekyll-deploy-oss 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/_config.yml +5 -0
- data/jekyll-deploy-oss.gemspec +18 -0
- data/lib/jekyll-deploy-oss.rb +84 -0
- data/lib/oss/deploy.rb +82 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e93226cf9566e0352ab94c0fc37e2cdaf181e5d1e8fe89691af802364879f7ed
|
4
|
+
data.tar.gz: ed92b6c6627938ea599ea27efd441d69fec60b7d240cf875badfea0fe6bda492
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d3d29dff2622f1b91e15cf6c475ba31a7a23e88903165be92383830bbbbd961a82c63d30ee7b7378bb4987a8e38744b1f255379852102dfbb5bcd1cdcbbdc34
|
7
|
+
data.tar.gz: 4739ccd6e13cb34b4f4743087e40dfcc1161b2bcd87821c092fc6ae939e0fae858af4e4d6b045512be53d990a6fd87ee356caa9ca90f31a908e156fe770a11b9
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Sharon Zhang
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# jekyll-deploy-oss
|
data/_config.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "jekyll-deploy-oss"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["erlzhang"]
|
5
|
+
spec.email = ["zhangshiyu1992@hotmail.com"]
|
6
|
+
spec.summary = "Deploy your Jekyll site to Aliyun OSS."
|
7
|
+
spec.description = "Deploy your Jekyll site to Aliyun OSS."
|
8
|
+
spec.homepage = "https://github.com/erlzhang/jekyll-deploy-oss"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files -z`.split("\x0")
|
12
|
+
|
13
|
+
spec.required_ruby_version = ">= 2.4.0"
|
14
|
+
|
15
|
+
spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "aliyun-sdk", "~> 0.7"
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative "./oss/deploy.rb"
|
2
|
+
|
3
|
+
class JekyllDeployOss < Jekyll::Command
|
4
|
+
class << self
|
5
|
+
def init_with_program(prog)
|
6
|
+
prog.command(:deploy) do |c|
|
7
|
+
c.syntax "deploy [options]"
|
8
|
+
c.description 'Deploy Jekyll site to Aliyun OSS.'
|
9
|
+
c.alias :d
|
10
|
+
|
11
|
+
add_options(c)
|
12
|
+
|
13
|
+
c.action do |args, options|
|
14
|
+
deploy_site(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def deploy_site(options)
|
20
|
+
options = Jekyll.configuration({
|
21
|
+
:deploy => options.merge!(ENV)
|
22
|
+
})
|
23
|
+
|
24
|
+
params = options["deploy"]
|
25
|
+
return unless validate_options(params)
|
26
|
+
|
27
|
+
remote_path = Proc.new do |path|
|
28
|
+
object = path.sub(options["destination"], "")
|
29
|
+
object[0] === "/" ? object.sub("/", "") : object
|
30
|
+
end
|
31
|
+
|
32
|
+
paths = get_paths(options)
|
33
|
+
Deploy.new(params).upload(paths, remote_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_paths(options)
|
37
|
+
dir = options["destination"]
|
38
|
+
params = options["deploy"]
|
39
|
+
paths = []
|
40
|
+
if params["paths"]
|
41
|
+
params["paths"].each do |path|
|
42
|
+
paths << File.join(dir, path)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
paths << dir
|
46
|
+
end
|
47
|
+
paths
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_options(cmd)
|
51
|
+
cmd.option "destination", "-d", "--destination DESTINATION",
|
52
|
+
"The files in DESTINATION will be uploaded."
|
53
|
+
cmd.option "OSS_ID", "--id OSS_ID"
|
54
|
+
cmd.option "OSS_SECRET", "--secret OSS_SECRET"
|
55
|
+
cmd.option "endpoint", "--endpoint ENDPOINT"
|
56
|
+
cmd.option "bucket_name", "--bucket BUCKET"
|
57
|
+
cmd.option "paths", "--paths PATH[,PATH2,...]",
|
58
|
+
Array, "The specific files(or folders) will be uploaded."
|
59
|
+
cmd.option "skip_exist", "--skipped", "Skip the exisiting files."
|
60
|
+
cmd.option "expired_in", "--expired DAYS", Integer,
|
61
|
+
"Set the files caches expireds in DAYS days."
|
62
|
+
end
|
63
|
+
|
64
|
+
def required_options
|
65
|
+
["OSS_ID", "OSS_SECRET", "endpoint", "bucket_name"]
|
66
|
+
end
|
67
|
+
|
68
|
+
def validate_options(options)
|
69
|
+
unless options
|
70
|
+
Jekyll.logger.error "ERROR:", "Missing deploy configs!"
|
71
|
+
return false
|
72
|
+
end
|
73
|
+
|
74
|
+
required_options.each do |key|
|
75
|
+
unless options[key]
|
76
|
+
Jekyll.logger.error "ERROR:", "#{key} is required to build!"
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/oss/deploy.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'aliyun/oss'
|
2
|
+
require 'find'
|
3
|
+
require 'date'
|
4
|
+
require 'jekyll'
|
5
|
+
|
6
|
+
class Deploy
|
7
|
+
attr_reader :access_key_id, :access_key_secret, :endpoint, :bucket_name, :expired_in, :skip_exist
|
8
|
+
|
9
|
+
def initialize(params = {})
|
10
|
+
@access_key_id = params["OSS_ID"]
|
11
|
+
@access_key_secret = params["OSS_SECRET"]
|
12
|
+
@endpoint = params["endpoint"]
|
13
|
+
@bucket_name = params["bucket_name"]
|
14
|
+
@expired_in = params["expired_in"] || 365
|
15
|
+
@skip_exist = params["skip_exist"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def client
|
19
|
+
@client ||= Aliyun::OSS::Client.new(
|
20
|
+
endpoint: endpoint,
|
21
|
+
access_key_id: access_key_id,
|
22
|
+
access_key_secret: access_key_secret
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def bucket
|
27
|
+
@bucket ||= client.get_bucket(bucket_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
# 文件列表
|
31
|
+
def objects
|
32
|
+
bucket.list_objects
|
33
|
+
end
|
34
|
+
|
35
|
+
def remote_objects
|
36
|
+
objects.map(&:key)
|
37
|
+
end
|
38
|
+
|
39
|
+
def local_objects(paths)
|
40
|
+
files = []
|
41
|
+
paths.each do |path|
|
42
|
+
if File.file?(path)
|
43
|
+
files << path
|
44
|
+
elsif File.directory?(path)
|
45
|
+
Find.find(path) do |file|
|
46
|
+
files << file if File.file?(file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
files.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
def upload(paths, remote_path)
|
54
|
+
objects = local_objects(paths)
|
55
|
+
objects.each do |object|
|
56
|
+
remote = remote_path.call(object)
|
57
|
+
if skip_exist and remote_objects.include?(remote)
|
58
|
+
Jekyll.logger.info "Skip exist file: #{remote}"
|
59
|
+
next
|
60
|
+
end
|
61
|
+
Jekyll.logger.info "Upload file: #{remote}"
|
62
|
+
bucket.put_object(
|
63
|
+
remote,
|
64
|
+
:file => object,
|
65
|
+
:headers => {
|
66
|
+
"Cache-Control": cache_control,
|
67
|
+
"Expires": expires
|
68
|
+
}
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def cache_control
|
74
|
+
max_age = expired_in.to_i * 24 * 60 * 60
|
75
|
+
"max-age=" + max_age.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def expires
|
79
|
+
expire_date = Date.today + expired_in.to_i
|
80
|
+
expire_date.to_time.getgm
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-deploy-oss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- erlzhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: aliyun-sdk
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.7'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.7'
|
47
|
+
description: Deploy your Jekyll site to Aliyun OSS.
|
48
|
+
email:
|
49
|
+
- zhangshiyu1992@hotmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ".gitignore"
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- _config.yml
|
59
|
+
- jekyll-deploy-oss.gemspec
|
60
|
+
- lib/jekyll-deploy-oss.rb
|
61
|
+
- lib/oss/deploy.rb
|
62
|
+
homepage: https://github.com/erlzhang/jekyll-deploy-oss
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.4.0
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.7.8
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Deploy your Jekyll site to Aliyun OSS.
|
86
|
+
test_files: []
|