How to deploy your first Go web app

blov · 2015-04-23 22:23:37 · 1439 次点击    
这是一个分享于 2015-04-23 22:23:37 的资源,其中的信息可能已经有所发展或是发生改变。

http://www.vincepergolizzi.com/How-to-deploy-your-first-Go-web-app

Would appreciate some feedback on this, I'm quite new to Go and a lot of the stuff I wrote about so feel free to correct me or provide some suggestions on how to make the guide better.


评论:

1Gijs:

If you want to keep it simple, why add the nginx webserver ? Add the reason(s) why you think its good to do.

Also, I think by default a Digital Ocean Ubuntu 14.04 distro has no firewall enabled ? In which case at least a link to this would be good to add: https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server

Finally I think some specific link to setting up ssh keys would be recommendable as well.

v89_cs:

Thanks I added why to use nginx, and a small section on using ufw at the end.

Good point about the SSH, I think I will write a paragraph or two about how to setup a deploy script so you can quickly push changes from dev to the server and that will require SSH setup to be explained.

keithy12:

nginx is pretty good to learn, it's good for newbies to learn how to set up subdomains for their projects.

bankslain:

./demo_webapp &

If you're exposing your project to the internet you probably at least want your app to auto-restart when it crashes or when the server reboots. Also, it might be an idea to run it as nobody instead of with your usual user account.

v89cs:

Thanks, I actually don't know how to do this but I will investigate and add to the guide once I know how to do it and how to explain it.

elithrar
:

See here: http://elithrar.github.io/article/running-go-applications-in-the-background/

Supervisord is one way to do it, as it Upstart (someone provided an example) or systemd. I prefer Supervisor as it's cross-platform/portable across OS versions (hey, Debian!).

dwevlo:

You need to create an upstart script. For example: (in /etc/init/demo-webapp.conf)

description "demo-webapp"
start on (started networking)
respawn
chdir /home/apps
exec /home/apps/demo-webapp

Then sudo initctl start demo-webapp.

Also most web apps have extra files, so I would rsync a whole folder over (the binary and any static js, css, images, etc)

v89_cs:

Thanks I will check this out, if you want I can credit you for this in the guide, PM me if you care about that.

Yes Im going to expand on the rsync, and explain how to create a deploy scripts to push changes easily to the server.

v89_cs:

I've added this now after testing it and credited you in the paragraph, thanks!

010a:

Its worth noting that choosing upstart for this part might not be such a good idea. Upstart is being replaced by systemd in ubuntu 15.04 (literally days from being released). It'll still be in 14.04 LTS until 16.04 comes out a year from now, but it might be worthwhile to include instructions for systemd as well.

faendriel:

what exactly is the benefit of nginx? can't I just SNAT to port 3000 from 80?

q1t:

it also handles https for all your apps on the server and deals with caching, and could work as a load balancer. That why I would prefer some kind of proxy server between my web apps and the wild. haproxy is another good alternative.

v89_cs:

I don't know, my intention is to have multiple apps on 1 server so I can hit a subdomain on port 80 and it will route to a specific Go app running on port Y

If I go to the main domain it will go to another app and so on

I then don't have to bog down any of my individual apps with this routing logic and can let nginx handle it all

AnAge_OldProb:

It's also a lot faster at serving static assets if you need to gain some performance there.

warmans:

You really need to package your application rather than manually creating all the scripts on the live server.

There are various projects that make it easier to build all the package types from a single spec. Effing-package-manager is a popular one.

Even if you don't actually package it as a deb or rpm you should still be able to install from source using a makefile or similar. It's pretty easy to do. Here is an example: https://github.com/warmans/fluentd-monitor/blob/master/Makefile#L17


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

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