glue scripts in Go, how to package and distribute

blov · 2017-11-22 01:00:07 · 731 次点击    
这是一个分享于 2017-11-22 01:00:07 的资源,其中的信息可能已经有所发展或是发生改变。

Lets say for example, you have a github repo that handles your infrastructure for an application. We'll call this repo infrastructure. It has some Terraform scripts, some Ansible scripts, etc. Now lets say you want to glue it all together with a Go binary that you build.

If this were Ruby or Python, I would write a simple script with various commands to interface with the above tools, and I would include it with the above repo.

For Go, what is the intended way to accomplish this? Do I:

  1. create a separate repo in my Go workspace called infrastructure_builder (for example), then create a binary, and store that in the infrastructure repo with my above project?

  2. have the Go source files co-exist in the same repo as my infrastructure project, and build a binary perhaps on deployment of that project. If I did this, how does that work as far as the Go workspaces?

  3. or because I plan to glue this together with Go, simply put all the above infrastructure project, in the Go workspace and have the Go source code live alongside it.

Or is there another way of handling this?


评论:

Zikes:

I like to use make, since it's fairly standard. One of the great things about this is make can assume that Go is installed on the builder machine, so you can go get other Go tools and run project "scripts" with go run somescript.go.

mcandre:

To begin with, version control the scripts into some git repositories. Bundle into a Docker container, RPM, DEB, TGZ, or such. Gradually replace each script with a pure Go equivalent.

antiphase
:

Why, in the name of all that is good and holy, would you put a script into a Docker container?

mcandre:

Not for transport, for installation. Glue code is a vague term. If the script is meant to function as part of a machine, then install it so. If, on the other hand the script is meant to manage machines, and be invoked by humans, then just keep it in a git repository.

sacrehubert:

To avoid the usual "it works on my machine..." issues.

dtirer:

To clarify what I mean by glue scripts. Before running any terraform commands, we have to make sure that:

  • terraform init has been run in the correct environment .

  • that any terraform modules have been downloaded .

  • we need to grab a couple secrets from AWS Parameter Store that serve as input to Terraform .

  • etc...

So I'm looking write a script that encapsulates some of these things in single commands like: builder init staging, and so forth


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

731 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传