How to deploy golang?

agolangf · · 492 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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&#39;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 &#34;No, no need for that really, you just can just run the Go app, open the ports and you&#39;re done.&#34;</p> <p>My response &#34;Wow. I like that.&#34;</p></pre>robvdl: <pre><p>The only thing you can run into is needing special permissions to open port 80 because it&#39;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&#39;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 =&gt; Travis CI build =&gt; build binary =&gt; upload to AWS S3 =&gt; 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&#39;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&#39;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&#39;s pretty much it! </p> <p>Here&#39;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

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