OSDN Git Service

Regular updates
[twpd/master.git] / heroku.md
1 ---
2 title: Heroku
3 category: Devops
4 layout: 2017/sheet
5 updated: 2017-10-11
6 description: |
7   A one-page reference to common Heroku-CLI commands.
8 intro: |
9   [Heroku](http://heroku.com/) is a web hosting platform supporting many languages, and this guide is a reference to Heroku's [command-line interface](http://heroku.com/).
10 ---
11
12 ### `create` - Create an app
13
14 ```bash
15 heroku create sushi
16 ```
17
18 ```bash
19 git push heroku master
20 ```
21
22 This will create an application named `sushi`. ([docs](https://devcenter.heroku.com/articles/creating-apps))
23
24 ### `container` - Docker containers
25
26 ```bash
27 heroku stack:set container -app <app>
28 heroku container:push web -app <app>
29 heroku container:release web -app <app>
30 ```
31
32 Containers can be deployed using the Heroku Container Registry. ([docs](https://devcenter.heroku.com/articles/container-registry-and-runtime))
33
34 ### `access` - Collaboration
35
36 #### Manage collaborators
37
38 ```bash
39 heroku access                     # List
40 heroku access:add me@xy.com
41 heroku access:remove me@xy.com
42 ```
43
44 #### Transfer to another owner
45
46 ```bash
47 heroku apps:transfer new@owner.com
48 ```
49
50 ### `logs` - Show logs
51
52 ```bash
53 heroku logs
54 heroku logs -t      # --tail (stream)
55 heroku logs -s app  # --source (only on app logs)
56 ```
57
58 ### `releases`
59
60 ```bash
61 heroku releases
62 heroku releases:info v25
63 heroku rollback
64 ```
65
66 ### `pg` - PostgreSQL
67
68 #### Start a database
69
70 ```bash
71 heroku addons:add heroku-postgresql
72 ```
73
74 #### Enable backups
75
76 ```bash
77 heroku addons:add pgbackups:auto-month
78 ```
79
80 See: [Heroku PostgreSQL](https://devcenter.heroku.com/articles/heroku-postgresql) _(devcenter.heroku.com)_
81
82 ### `config` - Environment var configuration
83
84 #### Listing
85
86 ```bash
87 heroku config        # List
88 heroku config -s     # List in shell format
89 ```
90
91 #### Getting
92
93 ```bash
94 heroku config:get KEY
95 ```
96
97 #### Setting
98
99 ```bash
100 heroku config:set KEY=val
101 heroku config:set KEY1=val KEY2=val ...
102 ```
103
104 ```bash
105 heroku config:unset KEY1
106 ```
107
108 ### `apps` - Applications
109
110 ```bash
111 heroku apps                  # list
112 heroku apps:create [NAME]
113 heroku apps:destroy --app APP
114 heroku apps:info
115 heroku apps:open             # open in browser
116 heroku apps:rename NEWNAME
117 ```
118
119 ### `maintenance`
120
121 ```bash
122 heroku maintenance:on
123 ```
124
125 ```bash
126 heroku maintenance:off
127 ```
128
129 ## Processes
130
131
132 ### `ps` - Managing processes
133
134 ```bash
135 heroku ps              # list
136 heroku ps:scale web=1  # spawn more dynos
137 ```
138
139 ### `restart`
140
141 ```bash
142 heroku restart
143 ```
144
145 ### `run` - Running tasks
146
147 ```bash
148 heroku run bash
149 heroku run console                  # Rails console
150 heroku run rake assets:precompile
151 ```
152
153 ## Domains
154
155 ### `domains` - Custom domains
156
157 #### Add both!
158
159 ```bash
160 heroku domains:add example.com
161 heroku domains:add www.example.com
162 ```
163
164 #### Removing
165
166 ```bash
167 heroku domains:clear
168 heroku domains:remove example.com
169 ```
170
171 See: [Custom domains](https://devcenter.heroku.com/articles/custom-domains) _(devcenter.heroku.com)_
172
173 ### Wildcard domains
174
175 ```bash
176 heroku addons:add wildcard_domains
177 ```
178
179 ```bash
180 *.yourdomain.com => heroku.com
181 ```
182
183 ## Other tricks
184
185 ### htpasswd (for PHP apps)
186
187 Create an `.htaccess` file in the webroot:
188
189 ```bash
190 AuthUserFile /app/www/.htpasswd
191 AuthType Basic
192 AuthName "Restricted Access"
193 Require valid-user
194 ```
195
196 Create a `.htpasswd` file:
197
198 ```bash
199 $ htpasswd -c .htpasswd [username]
200 ```
201
202 See: [gist.github.com](https://gist.github.com/3316425)
203
204 ## References
205
206  * <https://addons.heroku.com/>
207  * <https://devcenter.heroku.com/>