自动化的Go应用部署

huangapple go评论91阅读模式
英文:

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

我推荐使用Travis CI + Heroku

你可以直接使用git push将应用部署到Heroku,但我喜欢在此之前使用Travis来构建和运行测试。

有一些在线指南,但我会直接进入主题:

你需要什么?

  • Github账号
  • Travis账号(与Github关联,如果是开源项目则免费)
  • 空的Heroku应用(免费的dyno非常好用)

设置

在你的Github仓库中,创建以下文件:

之后,进入你的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,因此你只需设置一次,构建和部署只需一次推送即可完成 自动化的Go应用部署

此外,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:

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 自动化的Go应用部署

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

huangapple
  • 本文由 发表于 2014年5月24日 12:00:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/23841193.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定