3.4 使用 Buildpacks
Deis 支持通过 Heroku Buildpacks 部署应用程序。如果你对 遵循 Heroku 构建应用程序的最佳实践有兴趣或是你正在部署一个已经运行在 Heroku 上的应用程序,那么 Buildpacks 是非常有用的。
预先准备应用程序
如果你没有一个已经存在的应用程序,你可以 clone 一个示例应用程序,证明 Heroku Buildpack 工作流。
$ git clone https://github.com/deis/example-ruby-sinatra.git
$ cd example-ruby-sinatra
创建一个应用程序
使用 deis create
在 Controller 创建一个应用程序。
$ deis create
Creating application... done, created unisex-huntress
Git remote deis added
使用 push 来部署
使用 git push deis master
来部署你的应用程序:
$ git push deis master
Counting objects: 95, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (52/52), done.
Writing objects: 100% (95/95), 20.24 KiB | 0 bytes/s, done.
Total 95 (delta 41), reused 85 (delta 37)
-----> Ruby app detected
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-1.9.3
-----> Installing dependencies using 1.5.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Fetching gem metadata from http://rubygems.org/..........
Fetching additional metadata from http://rubygems.org/..
Using bundler (1.5.2)
Installing tilt (1.3.6)
Installing rack (1.5.2)
Installing rack-protection (1.5.0)
Installing sinatra (1.4.2)
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into ./vendor/bundle
Bundle completed (8.81s)
Cleaning up the bundler cache.
-----> Discovering process types
Procfile declares types -> web
Default process types for Ruby -> rake, console, web
-----> Compiled slug size is 12M
-----> Building Docker image
Uploading context 11.81 MB
Uploading context
Step 0 : FROM deis/slugrunner
---> 5567a808891d
Step 1 : RUN mkdir -p /app
---> Running in a4f8e66a79c1
---> 5c07e1778b9e
Removing intermediate container a4f8e66a79c1
Step 2 : ADD slug.tgz /app
---> 52d48b1692e5
Removing intermediate container e9dfce920e26
Step 3 : ENTRYPOINT ["/runner/init"]
---> Running in 7a8416bce1f2
---> 4a18f93f1779
Removing intermediate container 7a8416bce1f2
Successfully built 4a18f93f1779
-----> Pushing image to private registry
Launching... done, v2
-----> unisex-huntress deployed to Deis
http://unisex-huntress.local.deisapp.com
To learn more, use `deis help` or visit http://deis.io
To ssh://git@local.deisapp.com:2222/unisex-huntress.git
* [new branch] master -> master
$ curl -s http://unisex-huntress.local.deisapp.com
Powered by Deis!
因为一个 Heroku 风格的应用程序被检测到了,web 进程类型第一次部署自动被扩展到 1。
已经包含的 Buildpacks
为了方便起见,许多 buildpacks 与 Deis 捆绑在一起:
- Ruby Buildpack
- Nodejs Buildpack
- Java Buildpack
- Gradle Buildpack
- Grails Buildpack
- Play Buildpack
- Python Buildpack
- PHP Buildpack
- Clojure Buildpack
- Scala Buildpack
- Go Buildpack
- Multi Buildpack
Deis 将重复循环每个 buildpack 的 bin/detect
脚本来匹配你正在发布的代码。
使用定制的 Buildpack
为了使用一个定制的 buildpack,设置 BUILDPACK_URL
环境变量。
$ deis config:set BUILDPACK_URL=https://github.com/dpiddy/heroku-buildpack-ruby-minimal
Creating config... done, v2
=== humble-autoharp
BUILDPACK_URL: https://github.com/dpiddy/heroku-buildpack-ruby-minimal
在你下一步的 git push
,定制的 buildpack 将被使用。