capistrano-dockerbuild 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +17 -0
- data/capistrano-dockerbuild.gemspec +3 -3
- data/lib/capistrano/dockerbuild.rb +21 -0
- data/lib/capistrano/tasks/docker.rake +38 -16
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7580dbb05690bf6529b2fa5c84cf8c31c8d38b3335858af7aa3afdfcda8a8d7d
|
4
|
+
data.tar.gz: 691b01a48a7ff2aca50ca20ddcfd93275bc5b77ce27f43e7843564fbeac61d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5a7110eb23e53fd10aa05df4520690637e41a08847b788dd510f7b6ec5b8f48a2ff8919431873ce3e0f15b68ad5e07d0296aff8d4f13503bfacb38946eb0751
|
7
|
+
data.tar.gz: a94036ec200c90d80fe321cbb1519e52c933a09d2db08a292d4375b96fd32a072e4c622af238faa85b2d39aa0a6c85255c5be52ea65f69a1abc38fbcb46183f6
|
data/README.md
CHANGED
@@ -50,7 +50,24 @@ Use common variables
|
|
50
50
|
| docker_remote_tag | no | `-> { fetch(:docker_tag) }` | Use by `docker push docker_registry/docker_remote_repository_name:{{docker_remote_tag}}` |
|
51
51
|
| docker_remote_tag_full | no | `-> { "#{fetch(:docker_registry) &.+ "/"}#{fetch(:docker_remote_repository_name)}:#{fetch(:docker_remote_tag)}" }` | Use by `docker push {{docker_remote_tag_full}}` |
|
52
52
|
| keep_docker_image_count | no | 10 | |
|
53
|
+
| git_http_username | no | nil | See below |
|
54
|
+
| git_http_password | no | nil | See below |
|
53
55
|
|
56
|
+
If you want to use GitHub Apps installation access token or something to authorize repository access using HTTPS protocol. You can set variables in your config/deploy.rb:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
set :git_http_username, -> { ENV["GIT_HTTP_USERNAME"] }
|
60
|
+
set :git_http_password, -> { ENV["GIT_HTTP_PASSWORD"] }
|
61
|
+
set :repo_url, -> do
|
62
|
+
if fetch(:git_http_username) && fetch(:git_http_password)
|
63
|
+
"https://github.com/owner/repo.git"
|
64
|
+
else
|
65
|
+
"git@github.com:owner/repo.git"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
Update remote URL always if you set proper value to all of `repo_url`, `git_http_username`, and `git_http_password`.
|
54
71
|
|
55
72
|
## Tasks
|
56
73
|
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "capistrano-dockerbuild"
|
7
|
-
spec.version = "0.1
|
7
|
+
spec.version = "0.2.1"
|
8
8
|
spec.authors = ["joker1007"]
|
9
9
|
spec.email = ["kakyoin.hierophant@gmail.com"]
|
10
10
|
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_runtime_dependency "capistrano", ">= 3.2"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
-
spec.add_development_dependency "rake", "~>
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.3"
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
27
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "uri"
|
3
|
+
|
1
4
|
class Capistrano::Dockerbuild < Capistrano::Plugin
|
2
5
|
def set_defaults
|
3
6
|
set_if_empty :docker_build_cmd, -> { [:docker, "build", "-t", fetch(:docker_tag_full), "."] }
|
@@ -7,7 +10,10 @@ class Capistrano::Dockerbuild < Capistrano::Plugin
|
|
7
10
|
set_if_empty :docker_remote_repository_name, -> { fetch(:docker_repository_name) }
|
8
11
|
set_if_empty :docker_remote_tag, -> { fetch(:docker_tag) }
|
9
12
|
set_if_empty :docker_remote_tag_full, -> { "#{fetch(:docker_registry) &.+ "/"}#{fetch(:docker_remote_repository_name)}:#{fetch(:docker_remote_tag)}" }
|
13
|
+
set_if_empty :docker_latest_tag, false
|
10
14
|
set_if_empty :keep_docker_image_count, 10
|
15
|
+
set_if_empty :git_gc_prune_date, "3.days.ago"
|
16
|
+
set_if_empty :docker_build_no_worktree, false
|
11
17
|
end
|
12
18
|
|
13
19
|
def define_tasks
|
@@ -18,4 +24,19 @@ class Capistrano::Dockerbuild < Capistrano::Plugin
|
|
18
24
|
raise "Need to set :docker_build_base_dir" unless fetch(:docker_build_base_dir)
|
19
25
|
Pathname(fetch(:docker_build_base_dir))
|
20
26
|
end
|
27
|
+
|
28
|
+
def git_repo_url
|
29
|
+
if fetch(:git_http_username) && fetch(:git_http_password)
|
30
|
+
URI.parse(repo_url).tap do |repo_uri|
|
31
|
+
repo_uri.user = fetch(:git_http_username)
|
32
|
+
repo_uri.password = CGI.escape(fetch(:git_http_password))
|
33
|
+
end.to_s
|
34
|
+
elsif fetch(:git_http_username)
|
35
|
+
URI.parse(repo_url).tap do |repo_uri|
|
36
|
+
repo_uri.user = fetch(:git_http_username)
|
37
|
+
end.to_s
|
38
|
+
else
|
39
|
+
repo_url
|
40
|
+
end
|
41
|
+
end
|
21
42
|
end
|
@@ -5,18 +5,28 @@ namespace :docker do
|
|
5
5
|
task :check do
|
6
6
|
on fetch(:docker_build_server_host) do
|
7
7
|
execute :mkdir, "-p", dockerbuild_plugin.docker_build_base_path.dirname.to_s
|
8
|
-
execute :git, :'ls-remote',
|
8
|
+
execute :git, :'ls-remote', dockerbuild_plugin.git_repo_url, "HEAD"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
desc "Clone the repo to docker build base directory"
|
13
13
|
task :clone => [:'docker:check'] do
|
14
14
|
on fetch(:docker_build_server_host) do
|
15
|
-
if
|
16
|
-
|
15
|
+
if fetch(:docker_build_no_worktree)
|
16
|
+
if test " [ -f #{dockerbuild_plugin.docker_build_base_path}/.git/HEAD ] "
|
17
|
+
info "The repository is at #{dockerbuild_plugin.docker_build_base_path}"
|
18
|
+
else
|
19
|
+
within dockerbuild_plugin.docker_build_base_path.dirname do
|
20
|
+
execute :git, :clone, dockerbuild_plugin.git_repo_url, dockerbuild_plugin.docker_build_base_path.to_s
|
21
|
+
end
|
22
|
+
end
|
17
23
|
else
|
18
|
-
|
19
|
-
|
24
|
+
if test " [ -f #{dockerbuild_plugin.docker_build_base_path}/HEAD ] "
|
25
|
+
info t(:mirror_exists, at: dockerbuild_plugin.docker_build_base_path.to_s)
|
26
|
+
else
|
27
|
+
within dockerbuild_plugin.docker_build_base_path.dirname do
|
28
|
+
execute :git, :clone, "--mirror", dockerbuild_plugin.git_repo_url, dockerbuild_plugin.docker_build_base_path.to_s
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
@@ -26,6 +36,7 @@ namespace :docker do
|
|
26
36
|
task update_mirror: :'docker:clone' do
|
27
37
|
on fetch(:docker_build_server_host) do
|
28
38
|
within dockerbuild_plugin.docker_build_base_path do
|
39
|
+
execute :git, :remote, "set-url", :origin, dockerbuild_plugin.git_repo_url
|
29
40
|
execute :git, :remote, :update, "--prune"
|
30
41
|
end
|
31
42
|
end
|
@@ -35,20 +46,26 @@ namespace :docker do
|
|
35
46
|
task :build => [:'docker:update_mirror'] do
|
36
47
|
on fetch(:docker_build_server_host) do
|
37
48
|
within dockerbuild_plugin.docker_build_base_path do
|
38
|
-
|
39
|
-
|
49
|
+
if fetch(:docker_build_no_worktree)
|
50
|
+
commands = "sha1=$(git rev-parse #{fetch(:branch)}); git reset --hard ${sha1}; #{fetch(:docker_build_cmd).map {|c| c.to_s.shellescape }.join(" ")}"
|
51
|
+
execute(:flock, "capistrano_dockerbuild.lock", "-c", "'#{commands}'")
|
52
|
+
else
|
53
|
+
timestamp = Time.now.to_i
|
54
|
+
git_sha1 = `git rev-parse #{fetch(:branch)}`.chomp
|
55
|
+
worktree_dir_name = "worktree-#{git_sha1}-#{timestamp}"
|
40
56
|
|
41
|
-
|
57
|
+
execute(:git, :worktree, :add, worktree_dir_name, git_sha1)
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
59
|
+
begin
|
60
|
+
within worktree_dir_name do
|
61
|
+
execute(*fetch(:docker_build_cmd))
|
62
|
+
end
|
63
|
+
ensure
|
64
|
+
execute(:rm, "-rf", worktree_dir_name)
|
65
|
+
execute(:git, :worktree, :prune)
|
66
|
+
# Execute "git gc" manually to avoid "There are too many unreachable loose objects" warning
|
67
|
+
execute(:git, :gc, "--auto", "--prune=#{fetch(:git_gc_prune_date)}")
|
46
68
|
end
|
47
|
-
ensure
|
48
|
-
execute(:rm, "-rf", worktree_dir_name)
|
49
|
-
execute(:git, :worktree, :prune)
|
50
|
-
# Execute "git gc" manually to avoid "There are too many unreachable loose objects" warning
|
51
|
-
execute(:git, :gc, "--auto", "--prune=3.days.ago")
|
52
69
|
end
|
53
70
|
end
|
54
71
|
end
|
@@ -58,6 +75,11 @@ namespace :docker do
|
|
58
75
|
on fetch(:docker_build_server_host) do
|
59
76
|
execute(:docker, :tag, fetch(:docker_tag_full), fetch(:docker_remote_tag_full))
|
60
77
|
execute(:docker, :push, fetch(:docker_remote_tag_full))
|
78
|
+
if fetch(:docker_latest_tag)
|
79
|
+
latest_tag = "#{fetch(:docker_registry) &.+ "/"}#{fetch(:docker_remote_repository_name)}:latest"
|
80
|
+
execute(:docker, :tag, fetch(:docker_tag_full), latest_tag)
|
81
|
+
execute(:docker, :push, latest_tag)
|
82
|
+
end
|
61
83
|
end
|
62
84
|
end
|
63
85
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-dockerbuild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
description: Capistrano task definition for `docker build`
|
56
56
|
email:
|
57
57
|
- kakyoin.hierophant@gmail.com
|
@@ -73,7 +73,7 @@ homepage: https://github.com/reproio/capistrano-dockerbuild
|
|
73
73
|
licenses:
|
74
74
|
- MIT
|
75
75
|
metadata: {}
|
76
|
-
post_install_message:
|
76
|
+
post_install_message:
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|
79
79
|
- lib
|
@@ -88,9 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
|
92
|
-
|
93
|
-
signing_key:
|
91
|
+
rubygems_version: 3.5.9
|
92
|
+
signing_key:
|
94
93
|
specification_version: 4
|
95
94
|
summary: Capistrano task definition for `docker build`
|
96
95
|
test_files: []
|