cheatsheets/heroku.md

207 lines
3.3 KiB
Markdown
Raw Permalink Normal View History

2013-10-14 02:36:58 +00:00
---
title: Heroku
2015-11-24 05:06:06 +00:00
category: Devops
updated: 2017-10-11
description: |
A one-page reference to common Heroku-CLI commands.
intro: |
[Heroku](https://heroku.com/) is a web hosting platform supporting many languages, and this guide is a reference to Heroku's [command-line interface](https://heroku.com/).
2013-10-14 02:36:58 +00:00
---
2014-07-15 13:35:11 +00:00
### `create` - Create an app
2012-03-16 06:14:31 +00:00
```bash
heroku create sushi
```
```bash
git push heroku master
```
2012-03-16 06:14:31 +00:00
This will create an application named `sushi`. ([docs](https://devcenter.heroku.com/articles/creating-apps))
### `container` - Docker containers
```bash
heroku stack:set container -app <app>
heroku container:push web -app <app>
heroku container:release web -app <app>
```
Containers can be deployed using the Heroku Container Registry. ([docs](https://devcenter.heroku.com/articles/container-registry-and-runtime))
2016-03-28 06:56:43 +00:00
### `access` - Collaboration
2013-08-28 16:04:46 +00:00
#### Manage collaborators
```bash
heroku access # List
heroku access:add me@xy.com
heroku access:remove me@xy.com
```
#### Transfer to another owner
2013-08-28 16:04:46 +00:00
```bash
heroku apps:transfer new@owner.com
```
2013-08-28 16:04:46 +00:00
2014-07-15 13:35:11 +00:00
### `logs` - Show logs
2013-09-17 10:06:00 +00:00
```bash
heroku logs
heroku logs -t # --tail (stream)
heroku logs -s app # --source (only on app logs)
```
2013-09-17 10:06:00 +00:00
2014-07-15 13:35:11 +00:00
### `releases`
2014-02-25 10:32:14 +00:00
```bash
heroku releases
heroku releases:info v25
heroku rollback
```
2014-02-25 10:32:14 +00:00
### `pg` - PostgreSQL
2013-08-28 16:04:46 +00:00
#### Start a database
2013-08-28 16:04:46 +00:00
```bash
heroku addons:add heroku-postgresql
```
2013-08-28 16:04:46 +00:00
#### Enable backups
2013-08-28 16:04:46 +00:00
```bash
heroku addons:add pgbackups:auto-month
```
2013-08-28 16:04:46 +00:00
See: [Heroku PostgreSQL](https://devcenter.heroku.com/articles/heroku-postgresql) _(devcenter.heroku.com)_
2014-07-15 13:35:11 +00:00
### `config` - Environment var configuration
2014-07-15 13:35:11 +00:00
#### Listing
2013-08-28 16:04:46 +00:00
```bash
heroku config # List
heroku config -s # List in shell format
```
2013-08-28 16:04:46 +00:00
#### Getting
2012-03-16 06:14:31 +00:00
```bash
heroku config:get KEY
```
2012-03-16 06:14:31 +00:00
#### Setting
2013-08-28 16:04:46 +00:00
```bash
heroku config:set KEY=val
heroku config:set KEY1=val KEY2=val ...
```
2013-08-28 16:04:46 +00:00
```bash
heroku config:unset KEY1
```
2013-08-28 16:04:46 +00:00
2014-07-15 13:35:11 +00:00
### `apps` - Applications
2013-08-28 16:04:46 +00:00
```bash
heroku apps # list
heroku apps:create [NAME]
heroku apps:destroy --app APP
heroku apps:info
heroku apps:open # open in browser
heroku apps:rename NEWNAME
```
2013-08-28 16:04:46 +00:00
2014-07-15 13:35:11 +00:00
### `maintenance`
```bash
heroku maintenance:on
```
```bash
heroku maintenance:off
```
## Processes
### `ps` - Managing processes
```bash
heroku ps # list
heroku ps:scale web=1 # spawn more dynos
```
### `restart`
```bash
heroku restart
```
### `run` - Running tasks
```bash
heroku run bash
heroku run console # Rails console
heroku run rake assets:precompile
```
## Domains
2014-07-15 13:35:11 +00:00
### `domains` - Custom domains
2013-08-28 16:04:46 +00:00
#### Add both!
```bash
heroku domains:add example.com
heroku domains:add www.example.com
```
#### Removing
2013-08-28 16:04:46 +00:00
```bash
heroku domains:clear
heroku domains:remove example.com
```
See: [Custom domains](https://devcenter.heroku.com/articles/custom-domains) _(devcenter.heroku.com)_
2012-03-16 06:14:31 +00:00
2014-07-15 13:35:11 +00:00
### Wildcard domains
2012-03-16 06:14:31 +00:00
```bash
heroku addons:add wildcard_domains
```
```bash
*.yourdomain.com => heroku.com
```
2012-03-16 06:14:31 +00:00
## Other tricks
2012-11-15 21:57:56 +00:00
2014-07-15 13:35:11 +00:00
### htpasswd (for PHP apps)
2012-11-15 21:57:56 +00:00
2013-08-28 16:04:46 +00:00
Create an `.htaccess` file in the webroot:
2012-11-15 21:57:56 +00:00
```bash
AuthUserFile /app/www/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
```
2012-11-15 21:57:56 +00:00
2013-08-28 16:04:46 +00:00
Create a `.htpasswd` file:
```bash
$ htpasswd -c .htpasswd [username]
```
2013-08-28 16:04:46 +00:00
See: [gist.github.com](https://gist.github.com/3316425)
2012-11-15 21:57:56 +00:00
## References
2012-11-15 21:57:56 +00:00
* <https://addons.heroku.com/>
* <https://devcenter.heroku.com/>