Skip to content
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

Refactor init cmd #432

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

Refactor init cmd #432

wants to merge 16 commits into from

Conversation

terzioglub
Copy link
Collaborator

@terzioglub terzioglub commented Jan 30, 2025

Old Process:
For Every Initialized Template:

A separate .bruin.yml file was created inside the template, even if one already existed elsewhere.

New Process:

task: running bruin init with template X

if current folder is git repo:
if .bruin.yml exist in current folder:
merge .bruin.yml from current folder with the one from template X
else:
create .bruin.yml in current folder from contents of .bruin.yml of template X
create folder X in current folder with pipeline contentx except the .bruin.yml
else (current foder is not git repo):

go up the folder tree structure until we find a git repo or we reach the very root of the file system

if we reach the very root of the filesystem:
    create "bruin" folder
    init git repo in "bruin" folder
    create .bruin.yml based on the template X and place bruin folder
    create folder X inside bruin folder

else (if we reach an existing git repo in the ancestors in folder Y):
    do we also find a .bruin.yml:
        merge .bruin.yml of pipeline X with the one in folder Y
        create folder X with contents of the pipeline except for .bruin.yml (since we mertged)
    else:
        create .bruin.yml in folder Y based on the one from pipeline X
        create folder X with contents of the pipeline except for .bruin.yml 

Copy link
Contributor

@karakanb karakanb left a comment

Choose a reason for hiding this comment

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

two notes:

  • let's add an integration test that covers the changes here.
  • make sure we are not overriding if there are existing connections with the same name.

return nil
}

func mergeEnvironment(centralConfig *config.Config, templateEnvName string, templateEnv config.Environment) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's say the user has two envs, staging and prod, staging being marked as the default. if we have a .bruin.yml in our template and that has an env called default, it seems like we would create it as a new environment, correct? in that case I suggest using the user's default environment and merge into that.

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