swarmpit icon indicating copy to clipboard operation
swarmpit copied to clipboard

Reversing Docker Compose file from running stack

Open umardraz opened this issue 3 years ago • 6 comments

Hello sorry to ask here, but it will be very helpful if I get answer from here. I saw if I tried to edit a stack in swarmpit then it shows the exact docker-compose file's content that I had use while deploying the stack, now I only want to know how swarmpit is doing this, I tried to check all docker commands but haven't find anywhere.

I am doing little development in bash and python, and I need it there so I could see the docoker compose file content for my existing running stack. If you help me that how I can do then it will be great for me.

Thanks

umardraz avatar Jul 07 '21 02:07 umardraz

there is no easy way to do it, we're basically querying the current state of swarm and using this data to rebuild some valid stackfile from it. we also use same approach to convert single service into stack.

best way to start looking into how we do it is here https://github.com/swarmpit/swarmpit/blob/38ffbe08e717d8620bf433c99f2e85a9e5984c32/src/clj/swarmpit/docker/engine/mapper/compose.clj#L138

if you have swarmpit deployed in your swarm, you can use its API to let it generate stackfile for you

api/stacks/{name}/compose

mrq1911 avatar Jul 14 '21 09:07 mrq1911

HI thanks for your response.

Ok I had tried this

https://myswarmpit.local/api/stacks/<stack_name>/compose

but got this "Authentication failed", would you please help me how I can use the api

umardraz avatar Jul 14 '21 11:07 umardraz

@umardraz you need to generate API token first in settings section of Swarmpit.

nohaapav avatar Jul 14 '21 22:07 nohaapav

Yes I did it and it worked.

Now the question is, is there a way that I can launch swarmpit as API only and and define my own api token in swarmpit docker-compose file and deploy?

umardraz avatar Jul 15 '21 07:07 umardraz

@umardraz You can't. To do that new build without FE part will be required.

nohaapav avatar Jul 16 '21 00:07 nohaapav

Hmm, it will be really a great feature if we can launch API only as well

umardraz avatar Jul 25 '21 05:07 umardraz