Handle corrupt git clones

When cloning the git repo:
1. Try to clone
2. If there's already a build directory reset it
3. Check the clone is valid

If anything goes wrong during that process:
1. Delete the clone directory
2. Clone it again
3. Check the clone is valid

Raise any errors after that
This commit is contained in:
Donal McBreen
2024-05-27 11:11:51 +01:00
parent 10b8c826d8
commit 2c2053558a
6 changed files with 184 additions and 59 deletions

View File

@@ -2,7 +2,8 @@ require "active_support/core_ext/string/filters"
class Kamal::Commands::Builder < Kamal::Commands::Base
delegate :create, :remove, :push, :clean, :pull, :info, :validate_image, to: :target
delegate :clone_directory, :build_directory, to: :"config.builder"
include Clone
def name
target.class.to_s.remove("Kamal::Commands::Builder::").underscore.inquiry
@@ -54,23 +55,6 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
end
end
def create_clone_directory
make_directory clone_directory
end
def clone
git :clone, Kamal::Git.root, path: clone_directory
end
def clone_reset_steps
[
git(:remote, "set-url", :origin, Kamal::Git.root, path: build_directory),
git(:fetch, :origin, path: build_directory),
git(:reset, "--hard", Kamal::Git.revision, path: build_directory),
git(:clean, "-fdx", path: build_directory)
]
end
private
def ensure_local_docker_installed
docker "--version"