Skip to content
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

Deploy an already built configuration #230

Open
JustAlternate opened this issue Nov 14, 2024 · 8 comments
Open

Deploy an already built configuration #230

JustAlternate opened this issue Nov 14, 2024 · 8 comments
Milestone

Comments

@JustAlternate
Copy link

Hi, love the project

I currently have a CI/CD for testing and deploying nix related stuff to different hosts

In my CI I'm building the configuration and then if everything works well I want to be able to deploy this already built configuration to the remote host in my CD

It looks like morph don't allow deploying an already built configuration

Would this be possible ?

@adamtulinius
Copy link
Contributor

Hi

I have actually been thinking about this lately.

As it is, metadata (such as deployment order and health checks) are only available to morph when evaluating the deployment, so for such a feature to be meaningful that metadata would have to be part of the build output (and this might actually make total sense).

Can you describe more about how you would expect such a feature to work? And in what scenarios it's useful in? I imagine it being a situation where you want to be able to deploy a system without having the deployment sources available.

If you want this feature now, maybe it's easier for now to nix copy the built system onto the remote host, and trigger the switch-to-configuration machinery that is available somewhere in the system. Sadly this will be without health checks, and have to be done on each host individually.

@johanot
Copy link
Contributor

johanot commented Nov 15, 2024

@adamtulinius AFAIK, eval of metadata is waaaay faster than eval of a nixos config? It's sorta directly visible on morph in that the host-lists, including tags etc. shows up after just a couple of seconds, even though you have a long list of hosts. :)

So... One could imagine adding a feature to morph that would allow morph to jump to the target host and try to substitute the desired system, as a first step, and then (and only then) - if the wanted system is not present or cannot be substituted - will the system be build locally.

Of course all of this would be much more fun if morph did things in parallel :) And also, I don't wanna highjack this issue. The above is just a suggestion/thought.

EDIT: And of course you need a way to specify the desired system if you don't wanna waste time eval'ing it. :)

@adamtulinius
Copy link
Contributor

So... One could imagine adding a feature to morph that would allow morph to jump to the target host and try to substitute the desired system, as a first step, and then (and only then) - if the wanted system is not present or cannot be substituted - will the system be build locally.

👋

Yeah that's a valid point. But that's also why I'm curious about the usecase, and what is being optimized for (because my own thoughts have been a different kind of decoupling, where deployment without sources could be interesting).

Of course all of this would be much more fun if morph did things in parallel :)

Something might be in the works here 😅

@adamtulinius
Copy link
Contributor

AFAIK, eval of metadata is waaaay faster than eval of a nixos config? It's sorta directly visible on morph in that the host-lists, including tags etc. shows up after just a couple of seconds, even though you have a long list of hosts. :)

That is true. I think we've used some unfortunate terminology in morph. When I said "eval the deployment" I meant the eval-machines.nix bit, which is in fact very quick (as opposed to morphs implicit "eval all the hosts step" that comes next).

@johanot
Copy link
Contributor

johanot commented Nov 15, 2024

With my edit above, I realized that there's probably also a variant where you:

  1. Still eval the NixOS systems locally
  2. But you don't wanna build or substitute to your local store, before copy'ing to remote

Right now you are forced to getting the system on your local machine, one way or another, which ... is not really necessary. (if your target host already has the desired system or can substitute it directly)

^^ This "variant" might be easier to fix (than trying to eliminate system eval)

@adamtulinius
Copy link
Contributor

With my edit above, I realized that there's probably also a variant [.. snip]

Maybe the best way forward is to create separate issues for the different variations? And then in this issue we can focus on @JustAlternate's problem. Does that sound ok?

@JustAlternate
Copy link
Author

JustAlternate commented Nov 16, 2024

Yes the root of my problem is to be able to build the configuration in a job of my CI, verify that the build succeeded, do other checks...

And after that, launch a CD job to deploy the configuration by reusing the built artifact that was made previously by the CI.

So I was wondering if it was possible for morph to deploy an already built configuration to one or multiple host

I imagine something like

morph deploy machine_to_deploy.nix switch --use-already-built-configuration=./result/

So that morph can still check what machine it needs to deploy using the machine_to_deploy.nix file and then skip the build process and directly scp the result on every host machine and then switch to it.

@adamtulinius
Copy link
Contributor

And after that, launch a CD job to deploy the configuration by reusing the built artifact that was made previously by the CI.

If that job still had access to the sources, and you invoked morph again, you would only incur the overhead of evaluating the deployment again, and morph (really, nix) would end up using the already built artifacts in the nix store already.

It's currently not possible to do what you want with morph, but I'll add this to a future 2.0 milestone, since it's a good idea, but a rather big thing to implement properly.

Sorry about the bad news on this front :(

@adamtulinius adamtulinius added this to the 2.0 milestone Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants