Last active
September 3, 2019 19:25
Run a heroku one off dyno with curl and listen to rendezvous
This file contains hidden or 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
#!/bin/bash | |
# args: $1 is the app name, $2 is the command you want to run. | |
heroku_run() { | |
curl -H "Authorization: Bearer ${HEROKU_OAUTH_TOKEN}" \ | |
-H "Accept: application/vnd.heroku+json; version=3" \ | |
-H "Content-Type: application/json" \ | |
-d "{\"attach\": true, \"command\" : \"$2\", \"type\" : \"run\"}" \ | |
"https://api.heroku.com/apps/$1/dynos" | |
} | |
parse_secret() { | |
echo $1 | grep -oe '/heroku\.com\:5000\/([a-z0-9]+)/' | |
} | |
rendez_vous() { | |
(echo "$1"; sleep 2) | openssl s_client -connect rendezvous.runtime.heroku.com:5000 | |
} | |
echo "$1> Running $2" | |
output=$(heroku_run $1 $2) | |
echo "$1> $output" | |
secret=$(parse_secret "$output") | |
echo "$1> Rendez vous... $secret" | |
rendez_vous $secret |
parse_secret() {
echo $1 | cut -d / -f4
}
@kennethreitz I haven't used that in a while, what error do you get, it's possible that Heroku changed their response format.
I just tested it, it still works well for me, on an old app though :-?
just to be sure, you do need to set your heroku api key as HEROKU_OAUTH_TOKEN env. variable.
i think it's a gnu vs bsd awk thing, possibly.
Then you can try replacing the awk command by a grep one:
parse_secret() {
echo $1 | grep -oe '/heroku\.com\:5000\/([a-z0-9]+)/'
}
That should work to retrieve the rendez vous attached url secret from the json response.
I just edited it to use -e
option for the pattern rather than the -P
which may not be available on bsd.
I edited the gist to use grep rather than awk, hope it helps.
thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get an awk error