-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use local docker registry to push and pull app images
Allow applications to be deployed without needing to set up a repository in a remote Docker registry. If the registry server starts with `localhost`, Kamal will start a local docker registry on that port and push the app image to it. Then when pulling the image onto the servers, we use net-ssh to forward the that port from the app server to the deployment server.
- Loading branch information
Showing
19 changed files
with
323 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Kamal::Cli::PortForwarding | ||
attr_reader :hosts, :port | ||
|
||
def initialize(hosts, port) | ||
@hosts = hosts | ||
@port = port | ||
end | ||
|
||
def forward | ||
if KAMAL.config.registry.local? | ||
@done = false | ||
forward_ports | ||
end | ||
|
||
yield | ||
ensure | ||
stop | ||
end | ||
|
||
private | ||
|
||
def stop | ||
@done = true | ||
@threads.to_a.each(&:join) | ||
end | ||
|
||
def forward_ports | ||
@threads = hosts.map do |host| | ||
Thread.new do | ||
Net::SSH.start(host, KAMAL.config.ssh.user) do |ssh| | ||
ssh.forward.remote(port, "localhost", port, "localhost") | ||
ssh.loop(0.1) do | ||
if @done | ||
ssh.forward.cancel_remote(port, "localhost") | ||
break | ||
else | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
class Kamal::Cli::Registry < Kamal::Cli::Base | ||
desc "login", "Log in to registry locally and remotely" | ||
desc "setup", "Setup local registry or log in to remote registry locally and remotely" | ||
option :skip_local, aliases: "-L", type: :boolean, default: false, desc: "Skip local login" | ||
option :skip_remote, aliases: "-R", type: :boolean, default: false, desc: "Skip remote login" | ||
def login | ||
run_locally { execute *KAMAL.registry.login } unless options[:skip_local] | ||
on(KAMAL.hosts) { execute *KAMAL.registry.login } unless options[:skip_remote] | ||
def setup | ||
if KAMAL.registry.local? | ||
run_locally { execute *KAMAL.registry.setup } unless options[:skip_local] | ||
else | ||
run_locally { execute *KAMAL.registry.login } unless options[:skip_local] | ||
on(KAMAL.hosts) { execute *KAMAL.registry.login } unless options[:skip_remote] | ||
end | ||
end | ||
|
||
desc "logout", "Log out of registry locally and remotely" | ||
desc "remove", "Remove local registry or log out of remote registry locally and remotely" | ||
option :skip_local, aliases: "-L", type: :boolean, default: false, desc: "Skip local login" | ||
option :skip_remote, aliases: "-R", type: :boolean, default: false, desc: "Skip remote login" | ||
def logout | ||
run_locally { execute *KAMAL.registry.logout } unless options[:skip_local] | ||
on(KAMAL.hosts) { execute *KAMAL.registry.logout } unless options[:skip_remote] | ||
def remove | ||
if KAMAL.registry.local? | ||
run_locally { execute *KAMAL.registry.remove, raise_on_non_zero_exit: false } unless options[:skip_local] | ||
else | ||
run_locally { execute *KAMAL.registry.logout } unless options[:skip_local] | ||
on(KAMAL.hosts) { execute *KAMAL.registry.logout } unless options[:skip_remote] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.