本文根据 Devhints / Heroku 翻译。代码示例及版本范围沿用原文。原文标注更新日期:2017-10-11。
Heroku 是一个支持多种编程语言的网络托管平台,本指南旨在介绍 Heroku 的 命令行界面.
create - 创建应用
heroku create sushi
git push heroku master
这将创建一个名为……的应用 sushi. (文档)
container - Docker 容器
heroku stack:set container -app <app>
heroku container:push web -app <app>
heroku container:release web -app <app>
可以使用 Heroku 容器镜像仓库(Container Registry)来部署容器。(文档)
access - 协作
管理协作者
heroku access # List
heroku access:add me@xy.com
heroku access:remove me@xy.com
转让给其他所有者
heroku apps:transfer new@owner.com
logs - 查看日志
heroku logs
heroku logs -t # --tail (stream)
heroku logs -s app # --source (only on app logs)
releases
heroku releases
heroku releases:info v25
heroku rollback
pg - PostgreSQL
启动数据库
heroku addons:add heroku-postgresql
启用备份
heroku addons:add pgbackups:auto-month
参见: Heroku PostgreSQL (devcenter.heroku.com)
config - 环境变量配置
列出
heroku config # List
heroku config -s # List in shell format
获取
heroku config:get KEY
设置
heroku config:set KEY=val
heroku config:set KEY1=val KEY2=val ...
heroku config:unset KEY1
apps - 应用程序
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
maintenance
heroku maintenance:on
heroku maintenance:off
进程
ps - 管理进程
heroku ps # list
heroku ps:scale web=1 # spawn more dynos
restart
heroku restart
run - 运行任务
heroku run bash
heroku run console # Rails console
heroku run rake assets:precompile
域名
domains - 自定义域名
两者都添加!
heroku domains:add example.com
heroku domains:add www.example.com
移除
heroku domains:clear
heroku domains:remove example.com
参见: 自定义域名 (devcenter.heroku.com)
通配符域名
heroku addons:add wildcard_domains
*.yourdomain.com => heroku.com
其他技巧
htpasswd(适用于 PHP 应用)
创建一个 .htaccess 文件(置于网站根目录下):
AuthUserFile /app/www/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
创建一个 .htpasswd 文件:
$ htpasswd -c .htpasswd [username]
参见: gist.github.com