Skip to content

feat: Accept all docker compose filenames on default (#138) #141

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yarjor
Copy link

@yarjor yarjor commented Apr 4, 2025

  • Change getComposeFiles behavior to not throw an error if a compose file was not found (and only filter it out), and throw an error only if all give files were not found.
  • Change the compose-file default to be all 4 docker compose filenames specified by Docker's official documentation . Because of the previous change, this will now cause the action to behave on default similarily to the docker compose command (in order to minimize confusion when using default parameters) - try to found files with all 4 possible names.
    • One difference between this implementation and docker compose's behavior that should be noted is that if multiple files exists (e.g compose.yaml and docker-compose.yml), the action will use both of them while docker compose will choose one file and has an order of preference.
  • Updated tests accordingly

Issue: #138

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for creating your PR, we will check it out very soon

@yarjor yarjor changed the title Accept all docker compose filenames on default (#138) feat: Accept all docker compose filenames on default (#138) Apr 4, 2025
@yarjor yarjor marked this pull request as ready for review April 4, 2025 19:35
Copy link
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your PR.
IMO, this is good to match with docker compose specs.

But it is not good to had a breaking change for this (do not check if file exist anymore).

Maybe we can leave the input empty, if so we apply the defaults files and ignore exists check. If input is provided keep the original behavior

@yarjor yarjor marked this pull request as draft April 5, 2025 20:04
@yarjor yarjor marked this pull request as ready for review April 5, 2025 20:21
@yarjor yarjor requested a review from neilime April 5, 2025 20:21
@yarjor
Copy link
Author

yarjor commented Apr 5, 2025

Hi, thanks for your PR. IMO, this is good to match with docker compose specs.

But it is not good to had a breaking change for this (do not check if file exist anymore).

Maybe we can leave the input empty, if so we apply the defaults files and ignore exists check. If input is provided keep the original behavior

Got you, I changed it back to throw an error if a file was not found, and added a separate flow to search for the default compose filenames if the input was empty. This time I also implementing choosing based on the order of preference specified in the official docs (compose > docker-compose, yaml > yml).

BTW, do note that the CI action has permission issues because this pull request is coming from a fork, so the actual action currently isn't tested - I made sure the TS tests pass of course. 😊

README.md Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme file is auto generated from action.yml, you don't have to edit it.
However, can you update compose-file input description in action.yml

@@ -12,7 +12,7 @@ inputs:
compose-file:
description: "Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd)."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update description to explain the new behavior

Comment on lines +67 to +79
// If no compose files are provided, check for all possible compose files by order of preference specified
// in official docker compose specs
composeFiles = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"].filter((composeFile: string) => {
const possiblePaths = [join(cwd, composeFile), composeFile];

for (const path of possiblePaths) {
if (existsSync(path)) {
return true;
}
}
}

throw new Error(`Compose file not found in "${possiblePaths.join('", "')}"`);
});
return false;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can you move it in a new dedicated private method like getExistingDefaultComposeFile.
  • Return the first existing file instead of checking the whole list
  • Throws an error if none found


- name: "Assert: docker-compose.yaml is used"
run: |
docker compose -f ./test/docker-compose.yml ps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it possible it works as the file /test/docker-compose.yml has been renamed?

@neilime neilime force-pushed the all-default-names branch 2 times, most recently from ce6dd82 to f6fda06 Compare May 2, 2025 05:48
@neilime neilime force-pushed the all-default-names branch from f6fda06 to 38a654f Compare May 11, 2025 18:55
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

Successfully merging this pull request may close these issues.

2 participants