--- name: heroku-cli description: Deploy, manage, and operate apps on Heroku from the command line — dynos, databases, config, logs, and pipelines context: fork --- # Heroku CLI Skill The Heroku CLI manages apps, dynos, databases, config vars, and deployments on the Heroku platform. Use `heroku --help` for full flag details. ## Installation & Authentication ```bash # Install via Homebrew brew install heroku # Login (opens browser for OAuth) heroku login # Login via CLI only (no browser) heroku login -i # Check who you're logged in as heroku whoami # Logout heroku logout ``` ## Configuration & Auth Tokens Heroku CLI uses OAuth by default via `heroku login`. Auth tokens are stored in `~/.netrc`. ```bash # View current auth token heroku auth:token # Create a long-lived authorization (for CI/scripts) heroku authorizations:create --description "CI token" # List authorizations heroku authorizations # Revoke an authorization heroku authorizations:revoke # Set token via environment variable (for CI/CD) export HEROKU_API_KEY="your-token-here" ``` **Environment variables:** | Variable | Purpose | | ---------------------- | --------------------------------- | | `HEROKU_API_KEY` | Auth token (overrides `~/.netrc`) | | `HEROKU_APP` | Default app (skip `-a` flag) | | `HEROKU_TEAM` | Default team | | `HEROKU_DEBUG` | Enable debug output (`1`) | | `HEROKU_DEBUG_HEADERS` | Show HTTP headers (`1`) | **MCP Server** (for AI agent integration): ```bash # Start Heroku MCP server (stdio mode) heroku mcp ``` ## App Management ```bash # List all apps heroku apps heroku apps --json # App info heroku apps:info -a heroku apps:info -a --json # Create a new app heroku apps:create heroku apps:create --region eu # Rename app heroku apps:rename -a # Delete app (destructive!) heroku apps:destroy -a # Open app in browser heroku open -a # App maintenance mode heroku maintenance:on -a heroku maintenance:off -a ``` ## Deployment ```bash # Deploy via Git git push heroku main # Deploy a specific branch git push heroku feature-branch:main # Set Git remote heroku git:remote -a # View releases heroku releases -a # Rollback to previous release heroku rollback -a heroku rollback v42 -a ``` ## Dynos (Process Management) ```bash # List running dynos heroku ps -a # Scale dynos heroku ps:scale web=1 -a heroku ps:scale web=2:standard-1x -a heroku ps:scale worker=1 -a # Restart dynos heroku ps:restart -a heroku ps:restart web -a heroku ps:restart web.1 -a # Stop a dyno heroku ps:stop worker.1 -a # Resize dyno type heroku ps:type web=standard-2x -a # One-off dyno (run a command) heroku run bash -a heroku run python manage.py migrate -a heroku run python manage.py createsuperuser -a heroku run python manage.py shell -a ``` ## Config Vars (Environment Variables) ```bash # List all config vars heroku config -a heroku config -a --json # Get a specific var heroku config:get DATABASE_URL -a # Set config vars heroku config:set SECRET_KEY="my-secret" -a heroku config:set KEY1=val1 KEY2=val2 -a # Remove config var heroku config:unset KEY_NAME -a # Edit interactively heroku config:edit -a ``` ## Logs ```bash # View recent logs heroku logs -a # Tail logs (live stream) heroku logs --tail -a # Filter by process type heroku logs --process-type=web -a heroku logs --process-type=worker -a # Filter by dyno name heroku logs --dyno-name=web-123-456 -a # Limit number of lines heroku logs --num=100 -a # Filter by source heroku logs --source=app -a heroku logs --source=heroku -a ``` ## PostgreSQL Database ```bash # Database info heroku pg -a heroku pg:info -a # Open psql shell heroku pg:psql -a # Create backup heroku pg:backups:capture -a # List backups heroku pg:backups -a # Download latest backup heroku pg:backups:download -a # Restore from backup heroku pg:backups:restore DATABASE_URL -a # Push local DB to Heroku heroku pg:push local_db DATABASE_URL -a # Pull Heroku DB locally heroku pg:pull DATABASE_URL local_db -a # Reset database (destructive!) heroku pg:reset -a # Database credentials heroku pg:credentials:url -a # Run SQL heroku pg:psql -a -c "SELECT count(*) FROM users;" ``` ## Redis ```bash # Redis info heroku redis -a heroku redis:info -a # Open Redis CLI heroku redis:cli -a ``` ## Add-ons ```bash # List add-ons on an app heroku addons -a # List all add-ons across apps heroku addons --all # Provision an add-on heroku addons:create heroku-postgresql:essential-0 -a heroku addons:create heroku-redis:mini -a heroku addons:create papertrail:choklad -a # Add-on info heroku addons:info -a # Open add-on dashboard heroku addons:open -a # Destroy add-on heroku addons:destroy -a # List available add-on plans heroku addons:plans ``` ## Domains & SSL ```bash # List domains heroku domains -a # Add custom domain heroku domains:add www.example.com -a heroku domains:add example.com -a # Remove domain heroku domains:remove www.example.com -a # SSL certificates heroku certs -a heroku certs:auto -a heroku certs:auto:enable -a ``` ## Pipelines (Staging/Production) ```bash # List pipelines heroku pipelines # Create pipeline heroku pipelines:create -a --stage production # Add app to pipeline heroku pipelines:add -a --stage staging # Promote staging to production heroku pipelines:promote -a # Pipeline info heroku pipelines:info ``` ## Buildpacks ```bash # List buildpacks heroku buildpacks -a # Set buildpack heroku buildpacks:set heroku/python -a # Add buildpack (multi-buildpack) heroku buildpacks:add heroku/nodejs -a # Set buildpack order heroku buildpacks:set heroku/nodejs --index 1 -a ``` ## Access & Teams ```bash # List collaborators heroku access -a # Add collaborator heroku access:add user@example.com -a # Remove collaborator heroku access:remove user@example.com -a # List teams heroku teams # List team members heroku members -t ``` ## Container Deployment (Docker) ```bash # Login to container registry heroku container:login # Push image heroku container:push web -a # Release image heroku container:release web -a # Push + release in one step heroku container:push web -a && heroku container:release web -a ``` ## Local Development ```bash # Run app locally using Procfile heroku local # Run specific process heroku local web # Run with specific .env file heroku local --env .env.local ``` ## SSH Keys ```bash # List SSH keys heroku keys # Add SSH key heroku keys:add ~/.ssh/id_ed25519.pub # Remove SSH key heroku keys:remove user@example.com ``` ## Django-Specific Workflows ```bash # Run migrations heroku run python manage.py migrate -a # Create superuser heroku run python manage.py createsuperuser -a # Django shell heroku run python manage.py shell -a # Collect static files heroku run python manage.py collectstatic --noinput -a # Run management command heroku run python manage.py -a # Check Celery worker heroku ps -a | grep worker heroku logs --process-type=worker -a ``` ## Troubleshooting ```bash # Check app status heroku ps -a heroku logs --tail -a # Check Heroku platform status heroku status # Restart everything heroku ps:restart -a # Check buildpacks heroku buildpacks -a # Check releases for recent changes heroku releases -a # Debug: run bash on a dyno heroku run bash -a # Check CLI version heroku --version # Update CLI heroku update ``` ## Common Procfile Examples ``` # Django with Gunicorn web: gunicorn myproject.wsgi --log-file - worker: celery -A myproject worker --loglevel=info beat: celery -A myproject beat --loglevel=info # Django with uv web: uv run gunicorn myproject.wsgi --log-file - release: uv run python manage.py migrate ``` ## Environment Tips - Always use `heroku config:set` instead of hardcoding secrets - Use `heroku pg:credentials:url` to get the current DATABASE_URL - `heroku run` spins up a one-off dyno — it does NOT run on your web dyno - `heroku local` reads from `.env` file (not Heroku config vars) - Add `-a ` to every command, or set `HEROKU_APP` env var, or run from a directory with the Heroku git remote