<p>Hi,</p>
<p>I am new in golang. I develop web api using golang on mac os. My production environment is ubuntu 14.04 on Digitalocean. How can I deploy golang? what is the bast practice? How can I use docker? </p>
<hr/>**评论:**<br/><br/>silenceofnight: <pre><p>You can pretty much just copy the binary to the server and you are done. You can use Docker if you want, but there isn't any need to.</p></pre>tech_tuna: <pre><p>Just started doing some work (DevOps, CI/CD, etc) for a client building a web app in Go. This was pretty much my initial conversation with him.</p>
<p>Then I asked about needing Nginx and he said "No, no need for that really, you just can just run the Go app, open the ports and you're done."</p>
<p>My response "Wow. I like that."</p></pre>robvdl: <pre><p>The only thing you can run into is needing special permissions to open port 80 because it's a lower port there is some protection around opening lower ports.</p>
<p>Running the app as root will do it but is not desirable, I read that Nginx/apache do some magic to temporarily become root, open the port, then become the www-data user to achieve this. I am not sure if Caddy does this too, I've been meaning to check that out some time.</p></pre>ozbilenersin: <pre><p>Thank you for your response. Can I build for Ubuntu 14.04 on Mac Os.</p></pre>atamiri: <pre><p>Yes, you can:</p>
<p>GOOS=linux GOARCH=amd64 go build</p>
<p>(Other valid architectures are, for example, arm, arm64, mips etc., it depends on what server you have.)</p></pre>8lall0: <pre><p>$ GOOS=linux go build</p></pre>kjk: <pre><p>Recently I moved deploy of my Go software to CoreOS on DigitalOcean. I describe the important pieces here <a href="http://blog.kowalczyk.info/article/5/Blueprint-for-deploying-web-apps-on-CoreOS.html" rel="nofollow">http://blog.kowalczyk.info/article/5/Blueprint-for-deploying-web-apps-on-CoreOS.html</a></p>
<p>Before that I was using fabric (<a href="http://blog.kowalczyk.info/article/ucle/Using-Fabric-for-deploying-server-software.html" rel="nofollow">http://blog.kowalczyk.info/article/ucle/Using-Fabric-for-deploying-server-software.html</a>) and after that ansible. They are all good solutions with plenty of documentation.</p></pre>earthboundkid: <pre><p>Great post. </p></pre>pierrrre: <pre><p>My workflow at work: Git tag => Travis CI build => build binary => upload to AWS S3 => pull binary from all servers</p></pre>cdoxsey: <pre><p>I would switch to ubuntu 16 and systemd. You just need a file:</p>
<pre><code>[Unit]
Description=www
[Service]
ExecStart=/opt/www/www
WorkingDirectory=/opt/www
Restart=always
[Install]
WantedBy=multi-user.target
</code></pre>
<p>And then you just need to build the binary for linux and upload it:</p>
<pre><code>[remote] $ systemctl stop www
[local ] $ rsync -az --delete /tmp/build-www/ {USER}@{MACHINE}:/opt/www
[remote] $ systemctl start www
</code></pre>
<p>These days I use a cloud init script (DO should have something like it): <a href="https://github.com/calebdoxsey/cloud-machine/blob/master/install.bash" rel="nofollow">https://github.com/calebdoxsey/cloud-machine/blob/master/install.bash</a></p>
<p>It also creates a proxy with caddy and updates DNS entries in cloudflare to give me automatic failover if an instance dies. </p>
<p>I just download the code and build it on the box.</p>
<p>Or you can spend the next year attempting to learn modern service orchestration with kubernetes, docker, etc... :)</p></pre>robvdl: <pre><p>I pretty much do the same thing except build it into a .deb that self installs the systemd script, creates a special user for the app, etc. Call me old school but I still prefer deploying with .deb packages.</p></pre>scopeh: <pre><p>You'll need to compile the binary to the correct os/arch. This link should help you with that. <a href="https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5" rel="nofollow">https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5</a></p>
<p>Once you've done that, just upload the binary and run it.</p></pre>mcandre: <pre><p>export GOARCH=amd64
export GOOS=linux
go build</p>
<p>That will compile your Go application for modern Linux environments. You can inspect the resulting binary with the <code>file</code> tool, to confirm that the binary has the right attributes for the target environment.</p>
<p>Then copy the binary to the desired server and run.</p></pre>durthu_smith: <pre><p>just use heroku?</p></pre>ewanvalentine: <pre><p>I use Jenkins to ssh into my digital ocean server, got a git pull, build my go binary, then build it into a docker container, stop the old one and start the new one. That's pretty much it! </p>
<p>Here's an example: <a href="https://gist.github.com/EwanValentine/8441ab15030b100f60bf3423bf9f7c8d" rel="nofollow">https://gist.github.com/EwanValentine/8441ab15030b100f60bf3423bf9f7c8d</a> </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传