Class: Capistrano::Dockerbuild
- Inherits:
-
Plugin
- Object
- Plugin
- Capistrano::Dockerbuild
- Defined in:
- lib/capistrano/dockerbuild.rb
Instance Method Summary collapse
- #define_tasks ⇒ Object
- #docker_build_base_path ⇒ Object
-
#docker_build_lock_path ⇒ Object
Lock serializing access to the shared repo dir at docker_build_base_path across concurrent deploys on the same build host (see README for the race).
- #git_env(host) ⇒ Object
- #git_repo_host ⇒ Object
- #git_repo_url ⇒ Object
- #set_defaults ⇒ Object
- #tmp_home(host) ⇒ Object
Instance Method Details
#define_tasks ⇒ Object
23 24 25 |
# File 'lib/capistrano/dockerbuild.rb', line 23 def define_tasks eval_rakefile File.("../tasks/docker.rake", __FILE__) end |
#docker_build_base_path ⇒ Object
27 28 29 30 |
# File 'lib/capistrano/dockerbuild.rb', line 27 def docker_build_base_path raise "Need to set :docker_build_base_dir" unless fetch(:docker_build_base_dir) Pathname(fetch(:docker_build_base_dir)) end |
#docker_build_lock_path ⇒ Object
Lock serializing access to the shared repo dir at docker_build_base_path across concurrent deploys on the same build host (see README for the race).
Keyed by basename, not a fixed name, so unrelated consumers sharing a parent directory don't serialize against each other.
37 38 39 40 |
# File 'lib/capistrano/dockerbuild.rb', line 37 def docker_build_lock_path base = docker_build_base_path base.dirname.join("capistrano_dockerbuild.#{base.basename}.lock").to_s end |
#git_env(host) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/capistrano/dockerbuild.rb', line 66 def git_env(host) return {} if fetch(:git_auth_token).to_s.empty? @git_env ||= {} @git_env[host.properties.arch] ||= { HOME: tmp_home(host), GIT_CONFIG_NOSYSTEM: "1" } end |
#git_repo_host ⇒ Object
57 58 59 |
# File 'lib/capistrano/dockerbuild.rb', line 57 def git_repo_host URI.parse(repo_url.sub(/^git@.*/) {|m| "https://#{m}" }).host end |
#git_repo_url ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/capistrano/dockerbuild.rb', line 42 def git_repo_url if fetch(:git_http_username) && fetch(:git_http_password) URI.parse(repo_url).tap do |repo_uri| repo_uri.user = fetch(:git_http_username) repo_uri.password = CGI.escape(fetch(:git_http_password)) end.to_s elsif fetch(:git_http_username) URI.parse(repo_url).tap do |repo_uri| repo_uri.user = fetch(:git_http_username) end.to_s else repo_url end end |
#set_defaults ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/capistrano/dockerbuild.rb', line 7 def set_defaults set_if_empty :docker_tag, -> { fetch(:application) + ":" + fetch(:branch) } set :docker_tag_with_arch, ->(host) do arch_suffix = host.properties.arch ? "-#{host.properties.arch}" : "" fetch(:docker_tag) + arch_suffix end set_if_empty :docker_build_cmd, ->(host) do [:docker, :build, "-t", fetch(:docker_tag_with_arch).call(host), "."] end set_if_empty :docker_latest_tag, false set_if_empty :keep_docker_image_count, 10 set_if_empty :git_gc_prune_date, "3.days.ago" set_if_empty :docker_build_no_worktree, false set_if_empty :update_git_submodule, false end |
#tmp_home(host) ⇒ Object
61 62 63 64 |
# File 'lib/capistrano/dockerbuild.rb', line 61 def tmp_home(host) @tmp_host ||= {} @tmp_host[host.properties.arch] ||= "/tmp/capistrano-dockerbuild-#{SecureRandom.hex(8)}" end |