-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use local docker registry to push and pull app images #1355
Open
npezza93
wants to merge
11
commits into
basecamp:main
Choose a base branch
from
npezza93:local-docker-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f7283c3
Use local docker registry to push and pull app images
djmb cf5d7be
Use v3
npezza93 561a164
Fix cop
npezza93 17f396d
fix tests
npezza93 96cf78f
coerce nil
npezza93 3c21394
Set default server to localhost in deploy template
npezza93 bdf4efa
Comment registry password
npezza93 9573b97
Move around condition to make port forwarding usable elsewhere
npezza93 35c90d6
Test accessory with different registry
npezza93 4107764
Tweak tests
npezza93 6f6e7e4
Pass block
npezza93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,19 +1,27 @@ | ||
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 | ||
def setup | ||
ensure_docker_installed | ||
|
||
run_locally { execute *KAMAL.registry.login } unless options[:skip_local] | ||
on(KAMAL.hosts) { execute *KAMAL.registry.login } unless options[:skip_remote] | ||
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
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you guys for working on this feature! 🙏🏼 I was thinking to try it myself 😄
Minor 2 cents suggestion:
if KAMAL.config.registry.local?
is the only part that coupled to registry port. Extracting that condition will make class more general purposePortForwarding
to use for any other service port forwarding.So how about, instead of this line here (and condition in the class), to do something like following with direct condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ShPakvel, I like the suggestion around making the PortForwarding class usable elsewhere and not tying it to if the registry is local. Didnt really follow the code suggestion but made some edits to make the class usable elsewhere. Let me know what you think