Issue
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.
Solution
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:~
Answered By - Nguyen Dang Minh Answer Checked By - Willingham (WPSolving Volunteer)