-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: clone repository before getting working dir #3867
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ee1c0b0
fix: clone repository before getting working dir
ghaiszaher 89acc3b
unrelated change
ghaiszaher 793aafb
Merge branch 'main' into fix/clone-before-build
ghaiszaher ab78b2b
move TryLock up
ghaiszaher adcb86a
Merge branch 'main' into fix/clone-before-build
jamengual 9f4d3e1
fix workspace and add e2e tests
ghaiszaher 16653a4
Merge remote-tracking branch 'origin/fix/clone-before-build' into fix…
ghaiszaher 25f3e5a
fix description
ghaiszaher 3fb2d7d
Merge branch 'main' into fix/clone-before-build
ghaiszaher 8934637
Merge branch 'main' into fix/clone-before-build
ghaiszaher 2cc64a2
Merge branch 'main' into fix/clone-before-build
ghaiszaher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
server/controllers/events/testdata/test-repos/simple-yaml/exp-output-plan-default.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Ran Plan for dir: `.` workspace: `default` | ||
|
||
<details><summary>Show Output</summary> | ||
|
||
```diff | ||
preinit | ||
|
||
|
||
Terraform used the selected providers to generate the following execution | ||
plan. Resource actions are indicated with the following symbols: | ||
+ create | ||
|
||
Terraform will perform the following actions: | ||
|
||
# null_resource.simple[0] will be created | ||
+ resource "null_resource" "simple" { | ||
+ id = (known after apply) | ||
} | ||
|
||
Plan: 1 to add, 0 to change, 0 to destroy. | ||
|
||
Changes to Outputs: | ||
+ var = "fromconfig" | ||
+ workspace = "default" | ||
|
||
postplan | ||
``` | ||
|
||
* :arrow_forward: To **apply** this plan, comment: | ||
* `atlantis apply -d .` | ||
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url) | ||
* :repeat: To **plan** this project again, comment: | ||
* `atlantis plan -d .` | ||
</details> | ||
Plan: 1 to add, 0 to change, 0 to destroy. | ||
|
||
--- | ||
* :fast_forward: To **apply** all unapplied plans from this pull request, comment: | ||
* `atlantis apply` | ||
* :put_litter_in_its_place: To delete all plans and locks for the PR, comment: | ||
* `atlantis unlock` |
36 changes: 36 additions & 0 deletions
36
server/controllers/events/testdata/test-repos/simple-yaml/exp-output-plan-staging.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Ran Plan for dir: `.` workspace: `staging` | ||
|
||
<details><summary>Show Output</summary> | ||
|
||
```diff | ||
Terraform used the selected providers to generate the following execution | ||
plan. Resource actions are indicated with the following symbols: | ||
+ create | ||
|
||
Terraform will perform the following actions: | ||
|
||
# null_resource.simple[0] will be created | ||
+ resource "null_resource" "simple" { | ||
+ id = (known after apply) | ||
} | ||
|
||
Plan: 1 to add, 0 to change, 0 to destroy. | ||
|
||
Changes to Outputs: | ||
+ var = "fromfile" | ||
+ workspace = "staging" | ||
``` | ||
|
||
* :arrow_forward: To **apply** this plan, comment: | ||
* `atlantis apply -w staging` | ||
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url) | ||
* :repeat: To **plan** this project again, comment: | ||
* `atlantis plan -w staging` | ||
</details> | ||
Plan: 1 to add, 0 to change, 0 to destroy. | ||
|
||
--- | ||
* :fast_forward: To **apply** all unapplied plans from this pull request, comment: | ||
* `atlantis apply` | ||
* :put_litter_in_its_place: To delete all plans and locks for the PR, comment: | ||
* `atlantis unlock` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,6 +509,19 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Cont | |
|
||
var pcc []command.ProjectContext | ||
|
||
ctx.Log.Debug("building plan command") | ||
unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace, DefaultRepoRelDir) | ||
if err != nil { | ||
return pcc, err | ||
} | ||
defer unlockFn() | ||
|
||
ctx.Log.Debug("cloning repository") | ||
_, _, err = p.WorkingDir.Clone(ctx.HeadRepo, ctx.Pull, DefaultWorkspace) | ||
if err != nil { | ||
return pcc, err | ||
} | ||
|
||
// use the default repository workspace because it is the only one guaranteed to have an atlantis.yaml, | ||
// other workspaces will not have the file if they are using pre_workflow_hooks to generate it dynamically | ||
defaultRepoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, DefaultWorkspace) | ||
|
@@ -580,17 +593,12 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Cont | |
} | ||
} | ||
|
||
ctx.Log.Debug("building plan command") | ||
unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace, DefaultRepoRelDir) | ||
if err != nil { | ||
return pcc, err | ||
} | ||
defer unlockFn() | ||
|
||
ctx.Log.Debug("cloning repository") | ||
_, _, err = p.WorkingDir.Clone(ctx.HeadRepo, ctx.Pull, workspace) | ||
if err != nil { | ||
return pcc, err | ||
if DefaultWorkspace != workspace { | ||
ctx.Log.Debug("cloning repository with workspace %s", workspace) | ||
_, _, err = p.WorkingDir.Clone(ctx.HeadRepo, ctx.Pull, workspace) | ||
if err != nil { | ||
return pcc, err | ||
} | ||
Comment on lines
+596
to
+601
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole block is unnecessary because this call happens later anyway, but I kept it just in case it's needed for cases that I didn't notice |
||
} | ||
|
||
repoRelDir := DefaultRepoRelDir | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary to clone
DefaultWorkspace
at this point and notworkspace