capistrano-dockerbuild 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +29 -1
- data/capistrano-dockerbuild.gemspec +1 -1
- data/lib/capistrano/dockerbuild.rb +18 -0
- data/lib/capistrano/tasks/docker.rake +51 -9
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7346efa239fc872e0194afb86f2e155aec196f8ef16490af28dfb16a8e1b726
|
|
4
|
+
data.tar.gz: 647ae21571209763324edb86400d78498bdbd5b5423784530cac71e01544e783
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e3b6d93525ef5baf7d376f9d893f5f0db6227bb4c8fbb04c11f7c92a126e6ec2481c1dfb7c61562004aa58f4391bca3b31f73217df843b0af062032e32514b4
|
|
7
|
+
data.tar.gz: 949edfc5295850a32f6dbef737127ba2d1e700214fb560666936b4a6e6c8f4be3f60846f7c635b394914088afb97ee93270c4bbb382287c4ac285936d2e007e5
|
data/README.md
CHANGED
|
@@ -88,6 +88,8 @@ Use common variables
|
|
|
88
88
|
| keep_docker_image_count | no | 10 | |
|
|
89
89
|
| git_http_username | no | nil | See below |
|
|
90
90
|
| git_http_password | no | nil | See below |
|
|
91
|
+
| git_auth_token | no | nil | See below |
|
|
92
|
+
| update_git_submodule | no | false | Run `git submodule update --init --recursive` after checkout |
|
|
91
93
|
|
|
92
94
|
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:
|
|
93
95
|
|
|
@@ -105,8 +107,32 @@ end
|
|
|
105
107
|
|
|
106
108
|
Update remote URL always if you set proper value to all of `repo_url`, `git_http_username`, and `git_http_password`.
|
|
107
109
|
|
|
110
|
+
Alternatively, you can authenticate via an HTTP `Authorization` header using `:git_auth_token`. This is useful when the build server has no SSH key access to the repository (e.g. using a GitHub Apps installation access token or a personal access token).
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
set :git_auth_token, -> { ENV["GIT_AUTH_TOKEN"] }
|
|
114
|
+
set :repo_url, "git@github.com:owner/repo.git" # SSH or HTTPS both work
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
When `:git_auth_token` is set, `docker:setup` creates a temporary `.gitconfig` on each remote build host containing:
|
|
118
|
+
|
|
119
|
+
- `http.extraheader = Authorization: Basic <token>` — injects the token into every HTTPS git request
|
|
120
|
+
- `url."https://<host>/".insteadOf` rules — rewrites SSH-style URLs (`git@host:` and `ssh://git@host/`) to HTTPS so the token is used regardless of how `repo_url` is written
|
|
121
|
+
|
|
122
|
+
The host is derived automatically from `:repo_url`, so this works with GitHub, GitLab, Bitbucket, or any self-hosted git server.
|
|
123
|
+
|
|
124
|
+
The temporary directory is removed automatically by `docker:clean` after `docker:build`.
|
|
125
|
+
|
|
108
126
|
## Tasks
|
|
109
127
|
|
|
128
|
+
#### docker:setup
|
|
129
|
+
- Create a temporary `.gitconfig` on each remote build host when `:git_auth_token` is set
|
|
130
|
+
- Automatically invoked before `docker:check`
|
|
131
|
+
|
|
132
|
+
#### docker:clean
|
|
133
|
+
- Remove the temporary directory created by `docker:setup`
|
|
134
|
+
- Automatically invoked after `docker:build`
|
|
135
|
+
|
|
110
136
|
#### docker:check
|
|
111
137
|
- Ensure `#{docker_build_base_dir}`
|
|
112
138
|
- Ensure git reachable
|
|
@@ -132,7 +158,9 @@ Update remote URL always if you set proper value to all of `repo_url`, `git_http
|
|
|
132
158
|
|
|
133
159
|
## Task Dependency
|
|
134
160
|
|
|
135
|
-
docker:push => docker:build => docker:update_mirror => docker:clone => docker:check
|
|
161
|
+
docker:push => docker:build => docker:update_mirror => docker:clone => docker:check => docker:setup
|
|
162
|
+
|
|
163
|
+
docker:clean is triggered automatically after docker:build
|
|
136
164
|
|
|
137
165
|
## Development
|
|
138
166
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "cgi"
|
|
2
2
|
require "uri"
|
|
3
|
+
require "securerandom"
|
|
3
4
|
|
|
4
5
|
class Capistrano::Dockerbuild < Capistrano::Plugin
|
|
5
6
|
def set_defaults
|
|
@@ -15,6 +16,7 @@ class Capistrano::Dockerbuild < Capistrano::Plugin
|
|
|
15
16
|
set_if_empty :keep_docker_image_count, 10
|
|
16
17
|
set_if_empty :git_gc_prune_date, "3.days.ago"
|
|
17
18
|
set_if_empty :docker_build_no_worktree, false
|
|
19
|
+
set_if_empty :update_git_submodule, false
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def define_tasks
|
|
@@ -40,4 +42,20 @@ class Capistrano::Dockerbuild < Capistrano::Plugin
|
|
|
40
42
|
repo_url
|
|
41
43
|
end
|
|
42
44
|
end
|
|
45
|
+
|
|
46
|
+
def git_repo_host
|
|
47
|
+
URI.parse(repo_url.sub(/^git@.*/) {|m| "https://#{m}" }).host
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def tmp_home(host)
|
|
51
|
+
@tmp_host ||= {}
|
|
52
|
+
@tmp_host[host.properties.arch] ||= "/tmp/capistrano-dockerbuild-#{SecureRandom.hex(8)}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def git_env(host)
|
|
56
|
+
return {} if fetch(:git_auth_token).to_s.empty?
|
|
57
|
+
|
|
58
|
+
@git_env ||= {}
|
|
59
|
+
@git_env[host.properties.arch] ||= { HOME: tmp_home(host), GIT_CONFIG_NOSYSTEM: "1" }
|
|
60
|
+
end
|
|
43
61
|
end
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
dockerbuild_plugin = self
|
|
2
2
|
|
|
3
3
|
namespace :docker do
|
|
4
|
+
desc "setup temporary gitconfig for HTTP authentication"
|
|
5
|
+
task :setup do
|
|
6
|
+
on roles(:docker_build) do |host|
|
|
7
|
+
unless fetch(:git_auth_token).to_s.empty?
|
|
8
|
+
tmp_home = dockerbuild_plugin.tmp_home(host)
|
|
9
|
+
git_host = dockerbuild_plugin.git_repo_host
|
|
10
|
+
execute :mkdir, "-p", tmp_home
|
|
11
|
+
execute :git, :config, "--file", "#{tmp_home}/.gitconfig", "http.extraheader", "'Authorization: Basic #{fetch(:git_auth_token)}'"
|
|
12
|
+
execute :git, :config, "--file", "#{tmp_home}/.gitconfig", %Q(url."https://#{git_host}/".insteadOf), "git@#{git_host}:"
|
|
13
|
+
execute :git, :config, "--file", "#{tmp_home}/.gitconfig", "--add", %Q(url."https://#{git_host}/".insteadOf), "ssh://git@#{git_host}/"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc "clean up temporary gitconfig"
|
|
19
|
+
task :clean do
|
|
20
|
+
on roles(:docker_build) do |host|
|
|
21
|
+
unless fetch(:git_auth_token).to_s.empty?
|
|
22
|
+
tmp_home = dockerbuild_plugin.tmp_home(host)
|
|
23
|
+
execute :rm, "-rf", tmp_home
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
4
28
|
desc "check directory exist"
|
|
5
|
-
task :
|
|
29
|
+
task check: [:"docker:setup"] do
|
|
6
30
|
on roles(:docker_build) do |host|
|
|
7
|
-
|
|
8
|
-
|
|
31
|
+
with dockerbuild_plugin.git_env(host) do
|
|
32
|
+
execute :mkdir, "-p", dockerbuild_plugin.docker_build_base_path.dirname.to_s
|
|
33
|
+
execute :git, :'ls-remote', dockerbuild_plugin.git_repo_url, "HEAD"
|
|
34
|
+
end
|
|
9
35
|
end
|
|
10
36
|
end
|
|
11
37
|
|
|
@@ -17,7 +43,9 @@ namespace :docker do
|
|
|
17
43
|
info "The repository is at #{dockerbuild_plugin.docker_build_base_path}"
|
|
18
44
|
else
|
|
19
45
|
within dockerbuild_plugin.docker_build_base_path.dirname do
|
|
20
|
-
|
|
46
|
+
with dockerbuild_plugin.git_env(host) do
|
|
47
|
+
execute :git, :clone, dockerbuild_plugin.git_repo_url, dockerbuild_plugin.docker_build_base_path.to_s
|
|
48
|
+
end
|
|
21
49
|
end
|
|
22
50
|
end
|
|
23
51
|
else
|
|
@@ -25,7 +53,9 @@ namespace :docker do
|
|
|
25
53
|
info t(:mirror_exists, at: dockerbuild_plugin.docker_build_base_path.to_s)
|
|
26
54
|
else
|
|
27
55
|
within dockerbuild_plugin.docker_build_base_path.dirname do
|
|
28
|
-
|
|
56
|
+
with dockerbuild_plugin.git_env(host) do
|
|
57
|
+
execute :git, :clone, "--mirror", dockerbuild_plugin.git_repo_url, dockerbuild_plugin.docker_build_base_path.to_s
|
|
58
|
+
end
|
|
29
59
|
end
|
|
30
60
|
end
|
|
31
61
|
end
|
|
@@ -36,8 +66,10 @@ namespace :docker do
|
|
|
36
66
|
task update_mirror: :'docker:clone' do
|
|
37
67
|
on roles(:docker_build) do |host|
|
|
38
68
|
within dockerbuild_plugin.docker_build_base_path do
|
|
39
|
-
|
|
40
|
-
|
|
69
|
+
with dockerbuild_plugin.git_env(host) do
|
|
70
|
+
execute :git, :remote, "set-url", :origin, dockerbuild_plugin.git_repo_url
|
|
71
|
+
execute :git, :remote, :update, "--prune"
|
|
72
|
+
end
|
|
41
73
|
end
|
|
42
74
|
end
|
|
43
75
|
end
|
|
@@ -55,8 +87,11 @@ namespace :docker do
|
|
|
55
87
|
end
|
|
56
88
|
within dockerbuild_plugin.docker_build_base_path do
|
|
57
89
|
if fetch(:docker_build_no_worktree)
|
|
58
|
-
|
|
59
|
-
|
|
90
|
+
submodule_cmd = fetch(:update_git_submodule) ? "; git submodule update --init --recursive" : ""
|
|
91
|
+
commands = "sha1=$(git rev-parse #{fetch(:branch)}); git reset --hard ${sha1}#{submodule_cmd}; #{build_cmd.map {|c| c.to_s.shellescape }.join(" ")}"
|
|
92
|
+
with dockerbuild_plugin.git_env(host) do
|
|
93
|
+
execute(:flock, "capistrano_dockerbuild.lock", "-c", "'#{commands}'")
|
|
94
|
+
end
|
|
60
95
|
else
|
|
61
96
|
timestamp = Time.now.to_i
|
|
62
97
|
git_sha1 = `git rev-parse #{fetch(:branch)}`.chomp
|
|
@@ -66,6 +101,11 @@ namespace :docker do
|
|
|
66
101
|
|
|
67
102
|
begin
|
|
68
103
|
within worktree_dir_name do
|
|
104
|
+
if fetch(:update_git_submodule)
|
|
105
|
+
with dockerbuild_plugin.git_env(host) do
|
|
106
|
+
execute :git, :submodule, :update, "--init", "--recursive"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
69
109
|
execute(*build_cmd)
|
|
70
110
|
end
|
|
71
111
|
ensure
|
|
@@ -136,3 +176,5 @@ namespace :docker do
|
|
|
136
176
|
end
|
|
137
177
|
end
|
|
138
178
|
end
|
|
179
|
+
|
|
180
|
+
after "docker:build", "docker:clean"
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano-dockerbuild
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- joker1007
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: capistrano
|
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
86
|
- !ruby/object:Gem::Version
|
|
87
87
|
version: '0'
|
|
88
88
|
requirements: []
|
|
89
|
-
rubygems_version:
|
|
89
|
+
rubygems_version: 4.0.10
|
|
90
90
|
specification_version: 4
|
|
91
91
|
summary: Capistrano task definition for `docker build`
|
|
92
92
|
test_files: []
|