英文:
Automated go app deployment
问题
我想知道是否有任何方便的方法可以自动化将代码部署到GO的实时服务器上,无论是使用标准内置方法还是其他方法。
我希望有类似于Google App Engine的方式,只需运行命令即可将代码上传到服务器并触发重启。
(最终,我希望通过git提交来触发重新构建和重新部署,但这是未来的计划。)
英文:
I'm wondering if there are any convenient ways to automate deployment of code to a live server in GO, either standard built-in methods, or otherwise.
I want something google app engine like, I just run the command and it uploads to the server and triggers a restart.
(Ultimately I want a git commit to trigger a rebuild and redeploy, but thats for down the track in the future)
答案1
得分: 5
你可以直接使用git push将应用部署到Heroku,但我喜欢在此之前使用Travis来构建和运行测试。
有一些在线指南,但我会直接进入主题:
你需要什么?
- Github账号
- Travis账号(与Github关联,如果是开源项目则免费)
- 空的Heroku应用(免费的dyno非常好用)
设置
在你的Github仓库中,创建以下文件:
- .travis.yml(更多信息请参考Travis CI文档)
- Procfile
- .go-dir
之后,进入你的Travis账号,添加你的仓库并启用构建。
这是一个示例最小化的配置文件内容(基于我部署到Heroku的应用):
.travis.yml
language: go
go:
- tip
deploy:
provider: heroku
buildpack: https://github.com/kr/heroku-buildpack-go.git
api_key:
secure: <your heroku api key encripted with travis encrypt>
on: master
Procfile
worker: your-app-binary
.go-dir
your-app-binary
Procfile和.go-dir是Heroku的配置文件,如果你部署的是Web应用,可能会有所不同,你可以在Heroku文档中了解更多信息。
一个重要且容易被忽视的点是构建包,没有它,部署将无法工作。
阅读Travis文档以了解如何加密Heroku密钥。
工作原理
基本上,每次推送到你的仓库都会触发Travis CI构建,如果构建通过,它将部署应用到Heroku,因此你只需设置一次,构建和部署只需一次推送即可完成
此外,Travis会自动构建并更新到你的仓库中的所有Pull Request的状态。
要查看我的配置和构建,请查看我的Travis构建和我的仓库中的工作配置
英文:
I recommend Travis CI + Heroku.
You can deploy to heroku directly with just a git push, but I like to use Travis to build and run the tests before that.
There are some guides online but I'll try to go directly to the point:
What you will need?
- Github account
- Travis account (linked with github, free if open source)
- Empty Heroku app (Free dyno works great)
Setup
In your github repo, create the following files:
- .travis.yml (more info on the Travis CI documentation)
- Procfile
- .go-dir
After that go to your Travis account, add your repository and enabled the build for it.
Here is a sample minimal config file content (based on my app that I deploy to heroku):
.travis.yml
language: go
go:
- tip
deploy:
provider: heroku
buildpack: https://github.com/kr/heroku-buildpack-go.git
api_key:
secure: <your heroku api key encripted with travis encrypt>
on: master
Procfile
worker: your-app-binary
.go-dir
your-app-binary
Procfile and .go-dir are heroku configs so it can vary if you are deploying a web app, you can read more at the heroku documentation
One important and easily missed point is the build pack, without it the deploy will not work.
Read the Travis docs to see how to encrypt the heroku key
How it works?
Basically, every push to your repository will trigger the Travis CI build, if it passes it will deploy the app to heroku, so you set this up once and build + deploy is just a push away
Also Travis will build and updated the status of all Pull Requests to your repository automagically.
To see my config and build, please take a look at my Travis build and my repository with my working configs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论