Skip to content

Commit

Permalink
Dont build image if it has already been pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Jul 15, 2024
1 parent fa73d72 commit 8ba0879
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/kamal/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BuildError < StandardError; end

desc "deliver", "Build app and push app image to registry then pull image on servers"
def deliver
push
push unless already_built?
pull
end

Expand Down Expand Up @@ -158,4 +158,10 @@ def pull_on_hosts(hosts)
execute *KAMAL.builder.validate_image
end
end

def already_built?
run_locally { execute *KAMAL.docker.manifest(KAMAL.builder.absolute_image) }
rescue SSHKit::Command::Failed
false
end
end
1 change: 1 addition & 0 deletions lib/kamal/commands/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Kamal::Commands::Builder < Kamal::Commands::Base
delegate :create, :remove, :push, :clean, :pull, :info, :context_hosts, :config_context_hosts, :validate_image,
:first_mirror, to: :target
delegate :absolute_image, to: :config

include Clone

Expand Down
4 changes: 4 additions & 0 deletions lib/kamal/commands/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def running?
docker :version
end

def manifest(tag)
docker :manifest, :inspect, tag
end

# Do we have superuser access to install Docker and start system services?
def superuser?
[ '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' ]
Expand Down

0 comments on commit 8ba0879

Please sign in to comment.