Skip to content

Add --project-name cli flag. Lazily load project name from flags, env, or compose file #599

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

Merged
merged 11 commits into from
Aug 7, 2024

Conversation

jordanstephens
Copy link
Member

@jordanstephens jordanstephens commented Aug 1, 2024

Fixes #586

This pull request aims to add support for running defang compose commands outside of the project's working directory by using the --project-name CLI flag. In order to accomplish this, the compose.Loader has been refactored to accept a projectName and to avoid trying to read the compose.yaml file from disk unless absolutely necessary.

Many commands do not require any project information aside from the name, so will not need to read the compose file if the project name is passed using this new flag.

The compose.Loader will keep a reference to the project name passed by --project-name flag, or by the COMPOSE_PROJECT_NAME env var. If a project name has not been passed through the cli flag or environment, the compose.Loader will read the compose.yaml file from the path passed in with -f or from the current working directory. Once the compose file has been read, the compose.Loader will keep a reference to it in memory to avoid reading it again.

In order to implement this, I have removed some stateful attributes with values derived from the project name. I have replaced references to these attributes with function calls which ask the loader for the project name. This introduces a fair amount of churn into the diff since compose.Loader.GetProjectName can return an error and callers of these derived values may now need to handle these errors.

TODO

  • flesh out further test coverage
  • make sure it is still possible to derive project name from the current working directory
  • update docs to add a "Concept" for "Project" (Describe Projects defang-docs#69)

@jordanstephens jordanstephens marked this pull request as draft August 1, 2024 01:01
@lionello lionello mentioned this pull request Aug 2, 2024
@jordanstephens jordanstephens marked this pull request as ready for review August 7, 2024 21:18
@jordanstephens jordanstephens requested a review from lionello August 7, 2024 21:18
@lionello lionello merged commit fab0ce7 into main Aug 7, 2024
7 checks passed
@lionello lionello deleted the jordan/586 branch August 7, 2024 22:15
jordanstephens added a commit that referenced this pull request Aug 29, 2024
Since #599, we already consider the COMPOSE_PROJECT_NAME env var when
loading the project name, so this fallback is redundant. We also want to
suggest using the --project-name flag instead of the env var.
jordanstephens added a commit that referenced this pull request Aug 29, 2024
Since #599, we already consider the COMPOSE_PROJECT_NAME env var when
loading the project name, so this fallback is redundant. We also want to
suggest using the --project-name flag instead of the env var.
jordanstephens added a commit that referenced this pull request Aug 29, 2024
Since #599, we already consider the COMPOSE_PROJECT_NAME env var when
loading the project name, so this fallback is redundant. We also want to
suggest using the --project-name flag instead of the env var.
lionello pushed a commit that referenced this pull request Aug 30, 2024
Since #599, we already consider the COMPOSE_PROJECT_NAME env var when
loading the project name, so this fallback is redundant. We also want to
suggest using the --project-name flag instead of the env var.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants