如何在Amazon EC2上部署Go程序而不在EC2上编译它?
I am looking for a way to deploy the go binary on amazon ec2. Currently all the tutorials I have found (1, 2) are explaining how to move the go sources on ec2 and to compile them there.
This is not what I am looking for for a couple of reasons. Among them:
- I do not want to copy all the sources
- I do not want to install irrelevant binaries (go compiler and other things)
In my opinion this is unnecessary because go has an ability to cross-compile binaries. I think that is is better to build a binary locally and to upload it on ec2.
Am I missing something here, are there any hidden pitfalls with my approach or is there a better way?
P.S. if this question is better suited for serverfault, please let me know or move it there.
我正在寻找一种在Amazon EC2上部署go二进制文件的方法。 目前,我已经找到了所有教程( 1 , 2 )正在说明如何移动 在ec2上找到源代码并在那里进行编译。 p>
出于某些原因,这不是我想要的。 其中: p>
- 我不想复制所有源文件 li>
- 我不想安装无关的二进制文件(编译器及其他 事物) li>
ul>
在我看来,这是不必要的,因为go可以交叉编译二进制文件。 我认为在本地构建二进制文件并将其上传到ec2更好。 p>
我在这里遗漏了一些东西吗,我的方法是否存在任何隐患?还是有更好的方法? p>
PS 如果此问题更适合于serverfault,请让我知道或将其移到那里。 p> div>
You are right. One of the selling points of Go is cross-compiling into a single binary file. It's better to compile at localhost then copy it to your server.
$ GOOS=linux GOARCH=amd64 go build -o my_app .
$ scp my_app ec2@ip:~