用tsuru部署Go应用
概述
在tsuru中创建应用
使用命令创建应用:
对于Go来说,应用平台是Go
!让我们脑洞大开,开发一个’hello world‘教学应用,让我们叫它helloworld
:
$ tsuru app-create helloworld go
使用platform-list
命令列出所有的可用的平台。使用app-list
查看你所有的应用。
$ tsuru app-list
+-------------+-------------------------+--------------------------------+
| Application | Units State Summary | Address |
+-------------+-------------------------+--------------------------------+
| helloworld | 0 of 0 units in-service | helloworld.192.168.50.4.nip.io |
+-------------+-------------------------+--------------------------------+
应用的代码
用Go实现的一个简单web应用main.go
:
通过Git部署
$ tsuru app-info --app helloworld
Application: helloworld
Repository: git@192.168.50.4.nip.io:helloworld.git
Platform: go
Teams: admin
Address: helloworld.192.168.50.4.nip.io
Owner: admin@example.com
Team owner: admin
Pool: theonepool
App Plan:
+---------------+--------+------+-----------+--------+---------+
| Name | Memory | Swap | Cpu Share | Router | Default |
+---------------+--------+------+-----------+--------+---------+
| autogenerated | 0 MB | 0 MB | 100 | | false |
+---------------+--------+------+-----------+--------+---------+
Git远程分支被用来通过Git部署应用。当修改被推送到tsuru远程分支时,项目同时也被部署:
$ git push git@192.168.50.4.nip.io:helloworld.git master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 430 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: tar: Removing leading `/' from member names
remote: /
remote:
remote: ---- Building application image ----
remote: ---> Sending image to repository (5.57MB)
remote: ---> Cleaning up
remote:
remote: ---> Started unit b21298a64e...
remote:
remote: ---- Binding and checking 1 new units ----
remote:
remote: ---- Adding routes to 1 new units ----
remote: ---> Added route to unit b21298a64e
remote:
remote: OK
To git@192.168.50.4.nip.io:helloworld.git
* [new branch] master -> master
如果遇到"Permission denied (publickey)."的错误,请确保你是团队一员并把公钥加到tsuru中。用key-add
命令添加公钥:
使用git remote add
命令来避免每次push代码时都要输入整个远程仓库的链接:
$ git remote add tsuru git@192.168.50.4.nip.io:helloworld.git
然后运行:
$ git push tsuru master
Everything up-to-date
运行应用
tsuru会自动编译和运行应用,但是也可以定制tsuru编译和运行应用的方式。更多内容,请查看Go平台的README:.
应用部署成功,可以通过app-list
命令获得IP或者主机名,然后用浏览器去访问。比如,在下面的列表中:
$ tsuru app-list
+-------------+-------------------------+--------------------------------+
| Application | Units State Summary | Address |
+-------------+-------------------------+--------------------------------+
| helloworld | 1 of 1 units in-service | helloworld.192.168.50.4.nip.io |
+-------------+-------------------------+--------------------------------+
顺利完成!现在我们有了一个部署在tsuru上的简单go项目,现在我们可以访问app-list
返回的blog app
的URL了。(本例中的URL是"helloworld.192.168.50.4.nip.io").
进一步探索
更多信息,可以查看,或者阅读tsuru命令完全使用指南。