Skip to content

Feature: Create builds directly instead of restarting old builds#73

Open
aknuds1 wants to merge 4 commits intodrone-plugins:v2from
grafana:chore/use-api
Open

Feature: Create builds directly instead of restarting old builds#73
aknuds1 wants to merge 4 commits intodrone-plugins:v2from
grafana:chore/use-api

Conversation

@aknuds1
Copy link
Copy Markdown

@aknuds1 aknuds1 commented Sep 24, 2020

This PR proposes a rewrite of the plugin to, instead of re-starting old builds, create builds via Client.BuildCreate.

@donny-dont
Copy link
Copy Markdown
Contributor

@aknuds1 can you look at targeting the v2 branch?

@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Sep 25, 2020

@donny-dont Thanks, I wasn't aware.

@aknuds1 aknuds1 changed the base branch from master to v2 September 25, 2020 18:56
@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Sep 25, 2020

Will have to fix it up later.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Sep 28, 2020

@donny-dont I pushed a revision now that's cleanly based on v2, where I retain the blocking functionality. Please have a look.

Also, would you mind explaining the purpose of the v2 branch, and its relation to the master branch?

Copy link
Copy Markdown
Contributor

@donny-dont donny-dont left a comment

Choose a reason for hiding this comment

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

Marking up my nits. This particular plugin is widely used so I'm not approving it without consensus from @bradrydzewski and @tboerger

parts[0],
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see any benefit for moving the else if into this block.

Copy link
Copy Markdown
Author

@aknuds1 aknuds1 Sep 29, 2020

Choose a reason for hiding this comment

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

I think it's far more understandable when reading and verifying the code, since it's a pain to get your head around in which exact cases the else block would originally fire. You also get the idiomatic Go error handling, with early return on an error and no corresponding else.

github.com/drone-plugins/drone-plugin-lib v0.4.0
github.com/drone/drone-go v1.4.0
github.com/joho/godotenv v1.3.0
github.com/stretchr/testify v1.4.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tboerger do you have any preferences on go testing modules? I don't have any strong opinions on it all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No strong opinion on that, but isn't the standard library enough?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can do without it, but it does make error checking in tests far less verbose.

Comment on lines -36 to -48
&cli.BoolFlag{
Name: "wait",
Usage: "Wait for any currently running builds to finish",
EnvVars: []string{"PLUGIN_WAIT"},
Destination: &settings.Wait,
},
&cli.DurationFlag{
Name: "timeout",
Value: time.Duration(60) * time.Second,
Usage: "How long to wait on any currently running builds",
EnvVars: []string{"PLUGIN_WAIT_TIMEOUT"},
Destination: &settings.Timeout,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Believe @bradrydzewski 's initial ask was that wait and timeout would apply to the triggered build so should probably modify that accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

OK, will try.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See @bradrydzewski ''s comments below at #73 (comment)

branch string
)

func parseRepoBranch(repo string) (string, string, string, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't have any strong feelings on the modification to this function but maybe others do @tboerger ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think it's way better to return errors from this function at least, instead of leaving to the caller to surmise an error happened, without having the reason leading up to it.

@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Sep 28, 2020

@donny-dont Thanks! Will look into your feedback.

@donny-dont
Copy link
Copy Markdown
Contributor

@aknuds1 with regards to the v2 branch we had this PR #70 which added a block option. Per #68 the ideal behavior was for that block that was added to be the wait option. The PR adding the params for the BuildCreate method in drone-go wasn't present yet so we merged things over into a v2 branch.

Also remember that drone-downstream is a very popular plugin so we'd need to have a proper migration path for users hence the v2.

@tboerger
Copy link
Copy Markdown
Contributor

The wait, block and deploy features are important as they are actively used as far as I know.

@donny-dont
Copy link
Copy Markdown
Contributor

The block was added by @dschmidt and has yet to ship in anything. My understanding from @bradrydzewski 's bug is that what is currently block is what he thinks wait should be.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@dschmidt
Copy link
Copy Markdown
Contributor

The wait, block and deploy features are important as they are actively used as far as I know.

At least by me/ownCloud block is used :trollface:

The block was added by @dschmidt and has yet to ship in anything.

Agreed, probably not many people except for me are already using it, but I think it's an important feature and other people will follow once it's released.

My understanding from @bradrydzewski 's bug is that what is currently block is what he thinks wait should be.

Yeah, I tried to make the change non-breaking... which led to having two hard to distinguish options ... but I still like it better than reusing an existing option for a different function :-\

@donny-dont
Copy link
Copy Markdown
Contributor

Its my understanding that wait was originally there because of a limitation of the API. Remember that drone-downstream is one of the first plugins way back in the pre-1.0 days. With the new build API its not needed so we can just use wait as wait for the triggered build to end.

@bradrydzewski
Copy link
Copy Markdown
Member

the wait feature is only used because it was previously impossible to restart a build while it was running, which is why polling was implemented. This limitation no longer exists. Also we are moving from build restart to build create endpoint. So the wait command should no longer be relevant for this plugin.

@bradrydzewski
Copy link
Copy Markdown
Member

if there are concerns about this being a breaking change ...

the wait field should be repurposed to wait for the build to complete and, if the build fails, return a non-zero exit code.

my recommendation would be that we deprecate and ignore wait going forward since it should no longer be needed. We can use block to ensure that it does not break existing configurations that define wait. Since wait is deprecated and ignored, I recommend we change from block_timeout to just timeout since there will only be a single timeout going forward.

@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Oct 2, 2020

Having a look at the feedback.

@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Oct 2, 2020

my recommendation would be that we deprecate and ignore wait going forward since it should no longer be needed. We can use block to ensure that it does not break existing configurations that define wait. Since wait is deprecated and ignored, I recommend we change from block_timeout to just timeout since there will only be a single timeout going forward.

@bradrydzewski For the sake of clarity, do you want for wait to be ignored or for it to enable block if set?

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
return fmt.Errorf("unable to get last successful build for %s", entry)
}
}
fmt.Printf("deploying Drone build #%d of repo %s/%s\n", build.Number, owner, name)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@bradrydzewski Question: The old code, if the wait setting is enabled, will delay deploying/promoting a build until it has finished running. Considering you think the wait option is legacy, what should the new behaviour be?

@aknuds1 aknuds1 requested review from donny-dont and tboerger October 2, 2020 07:45
@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Oct 2, 2020

I've re-implemented deploy logic, but not sure what to do wrt. builds that are currently running. Please see my comment.

@dschmidt
Copy link
Copy Markdown
Contributor

dschmidt commented Dec 4, 2020

Is there any way forward with this?

@aknuds1
Copy link
Copy Markdown
Author

aknuds1 commented Dec 5, 2020

I also hope we can progress on this :)

@andrewhowdencom
Copy link
Copy Markdown
Contributor

Thanks for your work @aknuds1 ♥ I will be using this from now also.

@andrewhowdencom
Copy link
Copy Markdown
Contributor

In testing this I found a condition in which if, for whatever reason, a new build is not created (such as if the build does not match a given set of triggers — in my case custom was missing from match events) — the plugin appeared to succeed, but then failed immediately thereafter when it was in the "block" step.

Notably, the returned build ID was 0 — like the request itself worked, but that while the event was successfully triggered, there were no builds generated.

Logs were:

2 | starting Drone build for __REPO__successfully started Drone build for __REPO__: #0
3 | with params:
4 | - DRONE_UPSTREAM_BUILD_NUMBER: 580
5 |  
6 | blocking until build is finished
7 | time="2021-02-17T20:50:53Z" level=error msg="execution failed: client error 404: {\"message\":\"sql: no rows in result set\"}\n"
8

This server is a little mutant though — theres a couple patches on there that aren't in main (yet) — but it might be worth digging into.

@leandrolerena
Copy link
Copy Markdown

Any news on this? There is a bug associated with this to my knowledge (parameter passing, old parameters get reused instead of new ones), which can lead to timeconsuming problems.

Is there a workaround for this? Will this PR be merged?

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.

7 participants