Use local docker registry to push and pull app images#1355
Use local docker registry to push and pull app images#1355djmb merged 38 commits intobasecamp:mainfrom
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.
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.
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.
Oh awesome! This will be great 🎉
There was a problem hiding this comment.
Looks like this is now released: https://docs.docker.com/engine/release-notes/28/
f3dc9f3 to
3c21394
Compare
ShPakvel
left a comment
There was a problem hiding this comment.
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.
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 purposePortForwardingto 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
...
endThere was a problem hiding this comment.
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.
ace00d7 to
a106b81
Compare
3c5dc0b to
48f56b3
Compare
|
I'm a solodeveloper and I was using Cloudflare tunnels to connect to a local registry but this is much better. Thank you @npezza93 I wonder if can use the same configuration for local and remote registry to avoid "works on machine". Changes here: https://github.com/driveton/kamal/tree/local-registry-branch
|
|
Can we make this work when running Kamal inside the devcontainer? |
I have no need for such a feature but you are more than welcome to open a pr against this and I can include it |
|
Sure, it's kind of tricky though. I'm not sure how to solve it. My understanding is that Kamal, at least for Rails, is "best used" inside the devcontainer
Docker expects https so for any of those scenarios to work, we need to "hack" to accept http or to install certificates which is cumbersome. |
|
It would be great to merge this. Currently I use ghcr.io and it is randomly totally unusable due to |
|
This would be a great feature to have. what is blocking this MR to be merged? is any help needed? |
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: