-
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
base: main
Are you sure you want to change the base?
Conversation
c217a8b
to
f24e74c
Compare
lib/kamal/commands/registry.rb
Outdated
def setup | ||
combine \ | ||
docker(:start, "kamal-docker-registry"), | ||
docker(:run, "--detach", "-p", "127.0.0.1:#{local_port}:5000", "--name", "kamal-docker-registry", "registry:2"), |
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.
Publishing the port on your local machine will make it available in the same network segment (see moby/moby#45610). That's why I didn't go any further with this at the time.
I think we can mitigate this though by generating a password for the registry when we boot it.
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.
Hmm looks like a pr was merged a few days ago to resolve that. Perhaps in the next release of buildkit it'll be fixed for us?
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.
Oh awesome! This will be great 🎉
1bfc975
to
9685117
Compare
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.
f3dc9f3
to
3c21394
Compare
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.
Thanks again for working on it ❤️ 🚀
lib/kamal/cli/build.rb
Outdated
pull_on_hosts(KAMAL.hosts - first_hosts) | ||
else | ||
pull_on_hosts(KAMAL.hosts) | ||
Kamal::Cli::PortForwarding.new(KAMAL.hosts, KAMAL.config.registry.local_port).forward do |
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:
- This line read like forward ports always. While there is condition inside of class implementation. Even with local registry by default it kind of confusing in case of remote registry usage.
- And the condition in the class
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?
def pull_on_hosts(hosts, forward_registry_port: KAMAL.config.registry.local?)
if forward_registry_port
return Kamal::Cli::PortForwarding.new(hosts, KAMAL.config.registry.local_port).forward do
pull_on_hosts(hosts, forward_registry_port: false)
end
end
...
end
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
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.
This is branched off @djmb 's initial work. I have this working on a simple app but curious to open this up to try out to find issues and possibly optimize. Saw an overall speed up of around 10-15 seconds.
To get this to work update your deploy.yml files registry section to look something like: