-
-
Notifications
You must be signed in to change notification settings - Fork 465
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
Support for nested stacks directory #687
base: master
Are you sure you want to change the base?
Conversation
33de00a
to
1f594d5
Compare
67d710b
to
e17ede3
Compare
Merge PR louislam#687: Support for nested stacks directory
I've played around a bit with this PR and it seems to work great. |
How could I help test this? I have a particular Docker stack that is probably profiting from this feature:
Reason I have this stack:
I believe the feature here is exactly what I need and would like to help testing it if possible :) |
@smileBeda It's a normal node/JS application without anything unusual. You need to have an appropriate version of NodeJS and npm || pnpm || yarn installed, then you should be able to |
https://github.com/louislam/dockge/blob/master/CONTRIBUTING.md
Tick the checkbox if you understand [x]:
Description
This PR accompanies the discussion in #214.
Currently, dockge assumes all stacks are exactly one level deep in the stacks directory, and the "name" of a project equals the name of the folder containing it. This assumption is not quite right, and leads to weird behavior where dockge can be "tricked" into thinking a random folder is a docker compose project, or will simply not distinguish between two separate projects.
Some examples of where this assumption breaks:
$stacksDir/project/compose-dev.yml
and$stacksDir/project/compose-prod.yml
). If there is also acompose.yml
dockge will assign both projects the name "project" and not distinguish between them.$stacksDir/application1/authentik
and$stacksDir/application2/authentik
). Dockge will assign both projects the nameauthentik
and will not distinguish them.$notStacksDir/application3/authentik
will produce yet another naming conflict).compose-dev.yml
is not in theacceptedComposeFileNames
) dockge will simply not work with this project. This behavior is undocumented.In these cases the user will tell
docker compose
to tag the project with different names. Sodocker compose
will be aware of the difference but dockge will behave strangely. Plus, people with many (say, 20+) projects running on one machine will most certainly want to use some nesting to organize their stacks directory. For these reasons, I think lettingdocker compose
should be the main source of truth.A real example I had while testing this is I had a
server
directory I want to use as mystacksDir
that contains a folder calledauthentik
. This folder is actually a volume mount for my authentik project, and does not contain a config file. The actual authentik stack is running from a different location on my machine. Even thoughdockge
tries to skip folders that don't contain anacceptedComposeFilename
, the name of the folder matches the name of a project that appears in the output ofdocker compose ls
, so dockge thinks it is a project managed by dockge and then says it cannot find the configuration file:This PR treats
docker compose ls
as the main source of truth, and puts the folder scan afterwards as a "nice to have" for discovering unknown projects. And it fixes the issue described above!There are two commits in this PR that cover the two pieces of functionality changed. They can be reviewed separately, and the first half can be merged independently if you don't like the second. This changes some existing functionality, but everything that used to work should work the same as before, if not slightly better.
The first part focuses on the
stacks.ts
logic that assumes a stack "managed by dockge" means it lives in the folder$stacksDir + $projectName
. It asks docker compose for a list of projects and treats all the projects where the config file starts withstacksDir
as being managed by dockge (currentmaster
does a folder search then asksdocker compose
for services not managed by dockge, but they all go into the string map which can cause conflicts).The second part restores dockge's ability to "discover" projects that had never been run through the CLI, by adding the folder search after the call to docker compose. But it makes that search recursive using node FS. In case of a naming conflict between a "known" project and a "discovered" project, it keeps the "known" project but adds some extra logging and makes dockge's behavior extra transparent. Naming conflicts between projects "known" to docker compose will still happen if the user makes an error using docker compose (e.g.. not tagging projects with names), but at least dockge's behavior will match
docker compose
's.Fixes #(issue)
#214
Type of change
Please delete any options that are not relevant.
Checklist
(including JSDoc for methods)
Screenshots (if any)
Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.