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

Schedule Webhook Deploys in Threads #3436

Open
vinayhegde90 opened this issue Jul 5, 2019 · 13 comments
Open

Schedule Webhook Deploys in Threads #3436

vinayhegde90 opened this issue Jul 5, 2019 · 13 comments

Comments

@vinayhegde90
Copy link

Hi Team,

We're using Samson (v2488) for our deployments for about 12 apps with 4-5 stages for each. For automated deploys, we trigger the Generic web-hook via a scheduled bash-script to all the stages every morning. Below is a small snippet of the same:

#!/bin/bash
curl -v http://$webhook_url_1/integrations/generic/$random_hash_1 -d @deploy.json --header "Content-Type: application/json"
sleep 180

curl -v http://$webhook_url_2/integrations/generic/$random_hash_2 -d @deploy.json --header "Content-Type: application/json"
sleep 180

curl -v http://$webhook_url_X/integrations/generic/$random_hash_X -d @deploy.json --header "Content-Type: application/json"

The Issue: While the script just fires a curl call to trigger the deployments and about 50% succeed, the remaining fail with errors like below:

[12:37:21] Your configuration specifies to merge with the ref 'refs/heads/master'
[12:37:21] from the remote, but no such ref was fetched.

Can someone here please help me with enable scheduling via an option in Samson or an alternate logic in the script such as multi-threading so that the triggered webhook finishes deploy to all stages successfully in a phased manner?

Do let me know if any more info is required.

@grosser
Copy link
Contributor

grosser commented Jul 5, 2019

samson has periodic deploys which might help PERIODICAL=...,periodical_deploy:86400,... but it does them all at once

idk what these errors are or where they come from ... sounds like git problems :(

you could try using curl -X POST foo.com/projects/foo/stages/bar/deploys and see if that's better

@vinayhegde90
Copy link
Author

I already had a look at periodic deploys as you said but was confused by its tooltip.

samson-periodic-deploys

Please correct me if I'm wrong but periodic deploys will only happen every 24 hrs from the last deploy that should be successful otherwise there won't be any, thus triggering a failure email.

For e.g: Let's say if a successful deploy happens for 1 stage today at 7 PM, then the periodic one will be triggered at 7 PM on the next day right?

Also, is there a way to schedule this at a particular time?

@grosser
Copy link
Contributor

grosser commented Jul 8, 2019 via email

@grosser
Copy link
Contributor

grosser commented Jul 8, 2019

fyi added a PR to show next execution time in the tooltip

@vinayhegde90
Copy link
Author

I suppose we'll need to update Samson to the latest, i.e: v2845 to avail the fix pushed in #3438

It schedules at the same time for all deploys, I'd think it would run midnight UTC I think it would be easy to add a kind of offset so it runs at the time you want.

How can this be added? Also as we'd want the runs to be in IST, does it depend on what timezone Samson uses?

@vinayhegde90
Copy link
Author

you could try using curl -X POST foo.com/projects/foo/stages/bar/deploys and see if that's better

tried it as you recommended but it didn’t work, sharing the commands & status codes for reference.

user@server:~$ curl -X POST http://endpoint/projects/<project-name>/stages/<qa>/deploys
HTTP/1.1 422 Unprocessable Entity
Content-Type: text/html; charset=UTF-8
X-Request-Id: 78552476-22fc-46bd-9cc5-88121df3ae7c
X-Runtime: 0.112386
Set-Cookie: __profilin=p%3Dt; path=/
Content-Length: 103248

user@server:~$ curl --write-out %{http_code} http://endpoint/projects/<project-name>/stages/<qa>/deploys -d @deploy.json --header "Content-Type: application/json"

while running this as a one-off command is fine but won't this approach be problematic to scale up in a script since there'd be multiple apps across multiple stages?

@grosser
Copy link
Contributor

grosser commented Jul 9, 2019 via email

@grosser
Copy link
Contributor

grosser commented Jul 9, 2019 via email

@vinayhegde90
Copy link
Author

will need to send some data like -d '{"deploy":{"reference":"master"}}' etc idk why this would be problematic ... need lots of deploys -> do lots of api calls :D

doing lots of API calls isn't the issue here, what I was looking for a way to do them in parallel (with or without threads) with a single endpoint thereby avoiding failures to deploy on the same app on multiple stages

@grosser
Copy link
Contributor

grosser commented Jul 10, 2019 via email

@vinayhegde90
Copy link
Author

I meant one app, i.e: (backend-app-1) is deployed to multiple stages (server-1, server-2... server-n) with master branch & similarly, (frontend-app-1) to above stages

@grosser
Copy link
Contributor

grosser commented Jul 11, 2019

So you want to deploy the next stage when the first stage finishes ?
Using the webhook or the /deploys endpoint should return a deploy id, that can be used to check if the deploy is succeeded ... need to implement a loop to wait until it is either succeeded or failed/errored and then continue/stop.

@vinayhegde90
Copy link
Author

vinayhegde90 commented Jul 12, 2019

No, we want to deploy it in parallel in a threaded manner on all stages for a particular app. We do have a loop that sleeps for X seconds post triggering the webhooks, i.e: sequentially but that isn't very effective.

idk what these errors are or where they come from ... sounds like git problems :(

We also figured a probable cause for the Git issues that appear due to Samson doing Git IO like fetch/pull/checkout still ongoing for deploys on 1 stage but fails on any of the others due to Git locking.

A workaround to solve this would be separating and/or cloning the repos in a folder structure based on stage which has the following pros & cons:
Pros:

  • Git locking will be avoided as each app is deployed to all stages without conflicts or waiting for an operation to finish.
  • Removes a single point of failure in case of repo deletion as dependent deploys will fail due to directory being absent until it's recloned

Cons:

  • Keeping multiple copies of same repo segregated in different folders will increase disk usage.
  • Will get tedious to manage for a large number of stages.
  • Increases IO as team scales since there'll be more pull/push

Hoping this helps anyone solving a similar problem, cheers!

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

No branches or pull requests

2 participants