xavdid / heroku-config

[Utility] Push and pull heroku environment variables to your local env

Home Page:https://www.npmjs.com/package/heroku-config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to push to pipeline's review app config vars?

ErlanBazarov opened this issue · comments

I'm not sure! If you can link me to some heroku API docs about pipeline config vars, I can sure look.

Got it! Looks like there's a write operation here.

I'm not very familiar with the feature. Are your pipeline_id and pipeline_coupling_stage values that are familiar to you?

How would you imagine the command would look? Seems like heroku pipelines:config:push pipeline1 stage1 and heroku pipelines:config:pull .... Then it would follow the same format as the regular heroku config command?

Yes, I could really use this now too! I think your proposed interface looks reasonable.

Users would have the pipeline_id (or at least a friendly name from which you could get the id) and I believe pipeline_coupling_stage would be one of: review, development, staging or production

A little background on pipelines:

  • A pipeline consists of 1-3 "normal" apps each of which is assigned to one stage: "development", "staging" or "production"
  • There is also a special stage called review
  • Each time a PR is opened Heroku automatically spins up a new app and gives it the configuration from the review stage

So this feature would let us set the config vars for the review stage so each app Heroku spins up for us gets them.

Happy to help on this.

FWIW I was able to implement what I needed in my ruby project but it would still be super useful if heroku-config supported it too. If helpful here is the basic ruby code I used to implement it.

# user provided pipeline name
pipeline_name = "my-pipeline"

# platform-api setup
heroku_token = ''
client ||= PlatformAPI.connect_oauth(heroku_token)
pipeline_client ||= PlatformAPI::Pipeline.new(client)
pipeline_config_client ||= PlatformAPI::PipelineConfigVar.new(client)

# get a pipeline id using it's name
pipeline_id = pipeline_client.info(pipeline_name)["id"]

# get current "review app" config var settings 
config_vars = pipeline_config_client.info_for_app(pipeline_id, "review")

# make changes
updated_config_vars = ...

# update "review app" config var settings
# - overwrites each var we send with a value
# - deletes each var we send with a nil/null value
# - preserves any var we don't send
pipeline_config_client.update(pipeline_id, "review", updated_config_vars)

Got it! That's very helpful.

Just to confirm- It looks like we'd use this API endpoint to get/set the vars. If I'm understanding correctly, the CLI would be something like heroku config:pull --pipeline MY_PIPELINE, where we get the pipeline id from the name and update the values of the "review" app. Does that sound right?

Also, would you ever want to specify other stages? could also add a --pipeline-stage arg (maybe that defaults to review but can take any of "test" or "review" or "development" or "staging" or "production", which seem to be the valid stage types).

How does that sound?

@xavdid That'd be great! I'm a bit torn but I'd probably recommend requiring a stage flag to stay consistent with Heroku's APIs. I could imagine for example Heroku someday supporting config vars on a pipeline itself. If that happens you'll want
heroku config:pull --pipeline MY_PIPELINE to read read the pipeline vars instead of the review app vars.

Also FWIW I think only the stages review and test work for this API.

Excited to see this!

Got it, makes sense! I can likely get that added in the next few days, thank you!

Ok! This is released as part of heroku-config@1.6.0. You can update using heroku plugins:update, or it may happen automatically. See releases for the full changelog.