Skip to content

Instantly share code, notes, and snippets.

@mwarkentin
Created January 4, 2018 20:00
Show Gist options
  • Save mwarkentin/b782694d879e41ba91db6fc101d74e47 to your computer and use it in GitHub Desktop.
Save mwarkentin/b782694d879e41ba91db6fc101d74e47 to your computer and use it in GitHub Desktop.
convox util makefile
APPS=$(shell convox api get /apps --rack="${rack}" | jq --raw-output ".[].name")
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
infoall: ## View application info for all apps on a rack | args: rack
$(foreach app,$(APPS),echo ""; convox apps info --rack="${rack}" --app="${app}";)
envall: ## View environment variables for all apps on a rack | args: rack
$(foreach app,$(APPS),echo ""; echo "### ${app}"; convox env --rack="${rack}" --app="${app}";)
certall: ## Update certs for all apps on a rack | args: rack, cert
$(foreach app,$(APPS),echo "\nSetting ${cert} on ${app}..."; convox ssl update web:443 ${cert} --rack="${rack}" --app="${app}";)
sgall: ## Update custom SG for all apps on a rack | args: rack, sg
$(foreach app,$(APPS),echo "\nSetting param SecurityGroup=${sg} on ${app}..."; convox apps params set SecurityGroup="${sg}" --app "${app}" --rack "${rack}";)
copyenv: ## Copy a full set of environment variables from one app to another | args: rack_source, app_source, rack_target, app_target
@echo "Copying environment variables from ${rack_source} ${app_source} to ${rack_target} ${app_target}..."
convox env --rack="${rack_source}" --app="${app_source}" | convox env set --rack="${rack_target}" --app="${app_target}"
unsetenvs: ## Unset a list of environment variables | args: rack, app, envs (space separated list)
@echo "Unsetting ${envs} for ${rack} ${app}..."
$(foreach envvar,${envs},convox env unset $(envvar) --rack="${rack}" --app="${app}";)
unsetenvsall: ## Unset a full set of environment variables | args: rack, app
@echo "Unsetting all environment variables for ${rack} ${app}..."
$(foreach envvar,$(shell convox env --rack="${rack}" --app="${app}" | cut -d '=' -f 1),convox env unset $(envvar) --rack="${rack}" --app="${app}";)
paramsall: ## View application params for all apps on a rack | args: rack
$(foreach app,$(APPS),echo ""; convox apps params --rack="${rack}" --app="${app}";)
formationsall: ## View application formation params for all apps on a rack | args: rack
@$(foreach app,$(APPS),echo "\n\n${app}"; convox api get --rack="${rack}" /apps/${app}/parameters | jq -j 'to_entries[] | select(.key | contains("Formation")) | "\(.key)=\(.value) "';)
copyformation: ## Copy a full set of formation parameters for an app from one rack to another | args: rack_source, rack_target, app
convox apps params set --rack="${rack_target}" --app="${app}" $(shell convox api get --rack="${rack_source}" /apps/${app}/parameters | jq -j 'to_entries[] | select(.key | contains("Formation")) | "\(.key)=\(.value) "')
copyformationsall: ## Copy a full set of formation parameters for one rack to another | args: rack_source, rack_target
@$(foreach app,$(APPS),echo "\n\n${app}"; convox apps params set --rack="${rack_target}" --app="${app}" $(shell convox api get --rack="${rack_source}" /apps/${app}/parameters | jq -j 'to_entries[] | select(.key | contains("Formation")) | "\(.key)=\(.value) "');)
.PHONY: copyenv envall help infoall unsetenvs unsetenvsall paramsall formationsall copyformation copyformationsall
.DEFAULT_GOAL := help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment