mbecker20 / komodo

🦎 a tool to build and deploy software on many servers 🦎
https://komo.do
GNU General Public License v3.0
1.87k stars 36 forks source link

[Feature] Specify stack clone path #100

Closed lighterless closed 1 month ago

lighterless commented 1 month ago

I have multiple stacks that pull from the same repo and so currently it's cloning the same repo multiple times under /etc/komodo/stacks/{repo}/..

It would be nice if we could specify the stack clone path for each stack the same way we can for a repo.

image
lighterless commented 1 month ago

I can workaround this by setting up a repo and then pointing the stacks to files on the server. That works but then I lose out on the git webhooks.

mbecker20 commented 1 month ago

If you use a shared Repo for compose files, you can still setup webhook by using Procedure. The Procedure can PullRepo in the first stage, and deploy the relevant Stacks in the second stage: https://komo.do/docs/webhooks#procedure-webhooks.

It is an common situation though, and maybe something else can help here.

Malopieds commented 1 month ago

The Procedure can PullRepo in the first stage, and deploy the relevant Stacks in the second stage

I'm using a shared repo with subfolder for each service. I have a procedure webhook that works but how do you only deploy the relevant stacks? Would you have an example of doing so? My services are redeployed no matter what file is changed. Am I missing something here? Should I do something in the repos part? Thank you for your help!

lighterless commented 1 month ago

If you use a shared Repo for compose files, you can still setup webhook by using Procedure. The Procedure can PullRepo in the first stage, and deploy the relevant Stacks in the second stage: https://komo.do/docs/webhooks#procedure-webhooks.

It is an common situation though, and maybe something else can help here.

I tried that too but as @Malopieds mentions, it redeploys every stack regardless of which stack in the repo is updated. For example I have a repo with a structure like this:

- services
  - actual
    - compose.yaml
  - adguardhome
    - compose.yaml
  - authelia
    - compose.yaml
  ...

Ideally only the stack that is updated is redeployed.

mbecker20 commented 1 month ago

I have heard this use case a lot, when multiple stacks point to the same repo. I think the main solution here, like you mentioned, is to diff the "Deployed" files vs the "New" files, and if there aren't changes, you can skip the redeploy.

Already every Stack deploy reads the file contents it is deploying, and caches them to the database at Stack.info.deployed_contents. With this in place, doing the diff is straightforward at this point.

A new Core execution API for Stacks will help for this, called DeployStackIfChanged. I think providing this functionality can solve the problem internally for the webhook deploy case, and also gives to users the same logic to hook into inside Procedures (can just change DeployStack executions to DeployStackIfChanged executions).

lighterless commented 1 month ago

We are able to achieve this using a procedure and the DeployStackIfChanged action thanks to https://github.com/mbecker20/komodo/pull/117