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

feat(1259): sort projects based on dependencies #2146

Conversation

juliusdanielherreraglomm
Copy link

@juliusdanielherreraglomm juliusdanielherreraglomm commented Mar 16, 2022

This implements:
#1259

feat(1259): atlantis destroy order

While creating the directed acyclic graph, it checks if the
terragrunt.hcl file of the stacks contains our destroy flag:
# ATLANTIS_PLEASE_DESTROY_STACK

If this flag is found, the corresponding edge will be reverted, i.e.
instead of u -> v, we will get v -> u.

feat(1259): topological sort: fix and debugging

  • this will output the dependency graph in *.dot format
  • it will make the plan fail if the TopSort() fails for whatever reason
  • sorting is not necessary when there is just one project
  • dynamic folder/file generation
  • remove some unnecessary else branches
  • add a test for FindProjectNo()
  • and most important: fix FindProjectNo() so that the sorting is correct

New dependency

@juliusdanielherreraglomm juliusdanielherreraglomm requested a review from a team as a code owner March 16, 2022 15:32
@jamengual
Copy link
Contributor

@juliusdanielherreraglomm if you can fix the conflicts and add an example of the problem is trying to solve that will be very helpful, thanks.

@jamengual jamengual added the feature New functionality/enhancement label Mar 16, 2022
@juliusdanielherreraglomm
Copy link
Author

juliusdanielherreraglomm commented Mar 16, 2022

@jamengual Sure thing, conflict is fixed.

Example

If you have an atlantis.yaml like this:

version: 3
projects:
- autoplan:
    enabled: true
    when_modified:
    - '*.hcl'
    - '*.tf*'
    - ../4/terragrunt.hcl
  dir: dependency-test/1
- autoplan:
    enabled: true
    when_modified:
    - '*.hcl'
    - '*.tf*'
    - ../3/terragrunt.hcl
  dir: dependency-test/2
- autoplan:
    enabled: true
    when_modified:
    - '*.hcl'
    - '*.tf*'
    - ../1/terragrunt.hcl
  dir: dependency-test/3
- autoplan:
    enabled: true
    when_modified:
    - '*.hcl'
    - '*.tf*'
  dir: dependency-test/4

this patch will plan/apply the changes in this order:

  1. dependency-test/4
  2. dependency-test/1
  3. dependency-test/3
  4. dependency-test/2

(Copied from test)

@jamengual
Copy link
Contributor

this is somewhat related #2055 maybe you guys need to talk

Julius Daniel Herrera Glomm added 2 commits March 17, 2022 08:26
This implements:
runatlantis#1259

feat(1259): atlantis destroy order

While creating the directed acyclic graph, it checks if the
terragrunt.hcl file of the stacks contains our destroy flag:
`# ATLANTIS_PLEASE_DESTROY_STACK`

If this flag is found, the corresponding edge will be reverted, i.e.
instead of u -> v, we will get v -> u.

feat(1259): topological sort: fix and debugging

* this will output the dependency graph in *.dot format
* it will make the plan fail if the TopSort() fails for whatever reason
* sorting is not necessary when there is just one project
* dynamic folder/file generation
* remove some unnecessary else branches
* add a test for FindProjectNo()
* and most important: fix FindProjectNo() so that the sorting is correct
@austinsherron
Copy link
Contributor

Any word on this? It would solve a lot of problems for my team's use of this awesome tool.

Thanks for all the work on it!

continue
}
// Ignore .terragrunt-cache dirs (#487)
if strings.Contains(file, ".terragrunt-cache/") {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of ignoring this directory, can we list only the files, not directories, so we can do less filtering in lsOut

@jamengual jamengual added the waiting-on-response Waiting for a response from the user label Oct 27, 2022
@jamengual
Copy link
Contributor

@juliusdanielherreraglomm we will like to merge this soon and create a prerelease do you think you can address the comments and add a doc with an example of how to use it?

Thanks.

@nitrocode
Copy link
Member

Test is failing

server/events/project_finder_test.go:599:31: not enough arguments in call to r.ParseRepoCfg

@@ -60,6 +59,7 @@ require (
github.com/leodido/go-urn v1.2.1 // indirect
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869
Copy link
Member

Choose a reason for hiding this comment

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

This is a 5 year old dependency. Is there a way to avoid using this?

https://github.com/yourbasic/graph

@nitrocode nitrocode marked this pull request as draft December 23, 2022 19:04
@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement waiting-on-response Waiting for a response from the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants