News for hackers. Stuff that matters.
Re:Time to hand over the reins before Capistrano costs me my... by patio11 on Sunday October 06, 2013 @03:47PM (#6505193)
Thanks for creating software which has been an immense service to the community, and which I rely on quite a bit.

Tangent mode on:

Somebody really, really needs to write the How To Deploy Rails Without Losing Your Sanity handbook. I will buy a copy. It will sell thousands of them.

A lot of the problems with people's interactions with Capistrano are environment/ops problems which have known solutions that work, but which rely on people having a great understanding of arcane trivia which is spread across conference presentations, blog posts, commit messages, and the practical experience of the best Rails teams. Unless you're prepared for an archaeological expedition every time you start a new Rails project, you're going to do something wrong. You should see the bubblegum and duct tape which I came up with, and it mostly works, but I know it is bubblegum and duct tape.

Example:

Non-deterministic deploys of code from (usually) un-tagged source control

I feel lucky in that I was mentored by an engineer who decided to teach me, one day, Why We Tag Shit. But for the Why We Tag Shit discussion, I would be like almost every other intermediate Rails engineer, and be totally ignorant of why that was a best practice until lack of it bit me in the keister, at which point the server is down and one has to rearchitect major parts of the deployment workflow to do things the right way. Why We Tag Shit is only about a 500 word discussion, but it's one piece of organic knowledge of the hundreds you need to do things right, and it is (to the best of my knowledge) not covered in docs/QuickStarts/etc because that seems to be out of the purview of the framework proper (I guess?).

I'm sure that I'm ignorant of several of the hundreds of pieces of things one needs to do to do deployment right, as evidenced by my fear every time I execute my deploy scripts. I, and I must assume many other companies, am willing to pay for an option which gets me to a non-bubblegum and duct tape outcome.

Seriously, folks: there is a product here.

Re:Time to hand over the reins before Capistrano costs me my... by raverbashing on Sunday October 06, 2013 @03:55PM (#6505207)
I'll be downvoted by the "newer generation" but here's a pet peeve of mine

The same reason "why we tag shit" is the reason downloading packages from gem/pip is not enough

Who guarantees that when you do your deploy, the library you need is there? How many times did your build break because it had a glitch downloading the package?

Keep a way of rebuilding and deploying your software. All of it

Re:Time to hand over the reins before Capistrano costs me my... by lamby on Sunday October 06, 2013 @04:59PM (#6505421)
Mmm. I inherited a rather hardcore strain of liking entirely deterministic builds from being a Debian Developer and would never give up the dependability of it now. In fact, the thought of a build process connecting to the internet to download code just seems so utterly broken in my world view I actually find it difficult to explain it properly to others.

I'd love to be able to do it without embedding code copies, or at least have a smarter system than that.

Re:Time to hand over the reins before Capistrano costs me my... by heavenlyhash on Sunday October 06, 2013 @07:09PM (#6505822)
Sounds like you might like https://github.com/heavenlyhash/mdm ... yummy hashes for determinism, good for binary blobs, embeds semantic links in git, and uses git transports so you can swap out network or local filesystem trivially.
Re:Time to hand over the reins before Capistrano costs me my... by Volpe on Monday October 07, 2013 @04:08AM (#6507012)
But for the most part these build processes are for web apps... If your build can't connect to the internet, your web app isn't going to work (even if it can build).
Re:Time to hand over the reins before Capistrano costs me my... by nirvdrum on Monday October 07, 2013 @08:31AM (#6507730)
Sure, but it's not like the entire Internet is up at once. If rubygems.org goes off-line, it shouldn't mean you can't deploy your Rails app.
Re:Time to hand over the reins before Capistrano costs me my... by awj on Monday October 07, 2013 @12:46PM (#6509461)
Actually, your web server being able to make requests out on the open internet is considered a security liability.

If it lives behind a proxy, a web server being able to talk to anything but the proxy server and database is a matter of developer convenience.

Re:Time to hand over the reins before Capistrano costs me my... by forgottenpass on Monday October 07, 2013 @11:32AM (#6508857)
Why does my personal (or intranet) webapp needs an internet connection to work?
Re:Time to hand over the reins before Capistrano costs me my... by bennyg on Sunday October 06, 2013 @07:07PM (#6505815)
> I'd love to be able to do it without embedding code copies, or at least have a smarter system than that.

Maybe a section on the Server where gems lie, and a section on the hard-drive of your dev computer where gems lie - and then in a build process, it finds the gems with a certain checksum or tag or something similar. That's an interesting idea you have.

Re:Time to hand over the reins before Capistrano costs me my... by regularfry on Monday October 07, 2013 @03:38AM (#6506923)
This. People seem terrified of running their own gem or apt repositories to mirror their dependencies - or even to host their own code.

The dirty little secret is that these things are trivial to set up. Anyone whose build or deploy has been broken by github, rubygems.org, ruby-lang.org or even rvm.io falling over is Doing It Wrong. While I empathise, I have very little sympathy for people panicking when github gets DDoSed again.

Re:Time to hand over the reins before Capistrano costs me my... by mpvh on Monday October 07, 2013 @04:01AM (#6506993)
related - I've used this for running my own Gem server for years - It really is trivial: https://github.com/geminabox/geminabox
Re:Time to hand over the reins before Capistrano costs me my... by regularfry on Monday October 07, 2013 @07:16AM (#6507480)
It can be even simpler. I use Apache serving static files out of /var/www/gems, and a cron job to rebuild the index every 5 minutes if anything's changed. Caching gems is just `rsync -avz $GEM_HOME/cache <server>:/var/www/gems/`. Publishing internal gems I've built is just scp.
Re:Time to hand over the reins before Capistrano costs me my... by angelbob on Thursday October 10, 2013 @01:08PM (#6528816)
Geminabox is simple until you want to run with a lot (500+) of gems. And then index-building is horrible - it basically never finishes.

The complexity comes in mirroring the right set of other people's gems, which match the exact combined set of all versions used in all your various projects.

There is not a good "pass-through" gem server that just automatically mirrors what it is asked for from RubyGems. There really, really should be.

Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @03:58PM (#6505215)
> How many times did your build break because it had a glitch downloading the package?

This happens very infrequently in my experience, but it's simple on most CI servers to restart a build.

Re:Time to hand over the reins before Capistrano costs me my... by kaffeinecoma on Sunday October 06, 2013 @05:05PM (#6505443)
I also wouldn't normally expect a problem here, but this actually happened to me yesterday. Some 3rd-order transitive dependency resulted in trying to download a file from https://rubygems.org, rather than http. Apparently my SSL certs were out of date (on both dev and prod) and so I had to spend a few hours Googling how to make RVM + Ruby Gems update my certs.

It's really easy to write these kinds of things off as rare occurrences, but this is exactly the kind of thing that causes us to talk about "fear" when deploying.

Edit: solution was to run 'rvm osx-ssl-certs update all' on OSX, which is unsettling, as it installs certs all over the disk. Then on Ubuntu it was "yum update openssl", I believe.

Re:Time to hand over the reins before Capistrano costs me my... by darklajid on Monday October 07, 2013 @06:51AM (#6507404)
Nitpicking: Yum on ubuntu us highly unlikely (it's using .deb packages, apt-get). That's what you'd use on a rpm based distribution (Fedora, CentOS).
Re:Time to hand over the reins before Capistrano costs me my... by kaffeinecoma on Monday October 07, 2013 @07:41AM (#6507544)
You're correct, it was apt-get. I also have a Centos image around, so I have yum on the brain.
Re:Time to hand over the reins before Capistrano costs me my... by ollysb on Sunday October 06, 2013 @05:18PM (#6505478)
I've got this problem on a machine at the moment, what was the solution?
[deleted]
Re:Time to hand over the reins before Capistrano costs me my... by davidp on Sunday October 06, 2013 @05:51PM (#6505593)
-- Edit: parent was deleted; the suggestion was about a solution to use http instead of https. --

Security nerd mode activated; solutions like this make me a little twitchy, even when I have to employ them myself.

At the risk of stating something you already know, for the sake of pedantry the security implications of this fix are (at least) as follows:

- If you're checking the signatures of the packages you're downloading, this is probably OK, since even if an attacker spoofed your DNS to route to her own package archive, she would still have to compromise the package signing key to run her code on your system. On top of that, if you're using a hosting/PAAS provider, she'd have to compromise their DNS infrastructure first as well. - If you're not checking package signatures, then hopefully your system doesn't have any "interesting" information (including username/password combinations that might be useful on your or other sites). The hosting/PAAS provider DNS system is still a barrier, but now you're down _two_ of the protections on the chain of code executing in your name.

As always, there are multiple-order-of-magnitude differences in the amount of effort any given element of security is worth; the above fix might be just fine for 99% of applications, while for the remaining 1% some extra thought would be worthwhile. TBH I have no idea how common such "code hijacking" attacks are in practice -- if any "real" security professionals have that info, I'd be curious to hear your thoughts.

Offered in the spirit of helping folks with managers asking "why can't we just turn off SSL?"

Re:Time to hand over the reins before Capistrano costs me my... by kaffeinecoma on Sunday October 06, 2013 @06:10PM (#6505660)
Wish grandparent had not deleted his reply; makes it look like I'm the one suggesting turning off ssl. :-(
Re:Time to hand over the reins before Capistrano costs me my... by numbsafari on Sunday October 06, 2013 @08:21PM (#6506004)
If it happens even one time while you are in the middle of trying to resolve some "emergency", then it has happened one time too many. Customers don't care that you weren't thoughtful enough to keep a mirror of everything you were using.

I remember my first brush with this when Maven first started getting popular. Apache had to move their servers to a new datacenter and the server that had the drives for the main maven repo was lost in transit. It took five days to bring everything back up. During that whole time, nobody could build anything unless they had local copies.

Ever since then, I'm pathological about ensuring that I have a local mirror of all my dependencies.

Re:Time to hand over the reins before Capistrano costs me my... by lamby on Sunday October 06, 2013 @05:04PM (#6505434)
I'm pretty sure that wasn't the point - however infrequently it occurs, it violates the principle that only changes introduced since the previous build could have made it fail.

In practical terms, this means that you never know whether change X is faulty or simply the world is temporarily faulty.

(Of course, this may or may not be not useful to you to know.)

Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @05:11PM (#6505461)
True, but a build could fail arbitrarily fail for any unexpected reason. Pragmatism is important, I'd avoid adding an inconvenient step to my build/deploy process just to mitigate an infrequent edge case.
Re:Time to hand over the reins before Capistrano costs me my... by regularfry on Monday October 07, 2013 @03:42AM (#6506933)
> a build could fail arbitrarily fail for any unexpected reason.

Good engineering is the attempt to prove that statement wrong.

Re:Time to hand over the reins before Capistrano costs me my... by byroot on Sunday October 06, 2013 @05:38PM (#6505555)
Infrequent (I don't remeber that it happened to me during the hundred or thousand deploy I made with capistrano) and mostly harmless.

If the deploy fail for any reason, it's aborted, you just have to run it again.

Re:Time to hand over the reins before Capistrano costs me my... by pyre on Sunday October 06, 2013 @11:34PM (#6506404)
What do you do if the package servers go down for a couple of days? "Oops! Guess I can't deploy. Oh well!"
Re:Time to hand over the reins before Capistrano costs me my... by lamby on Sunday October 06, 2013 @06:02PM (#6505632)
Maybe my brain is wired differently, but having to tell a new hire "Oh yeah sometimes the build randomly fails and we just press retry until it works" would just feel kinda embarrasing to me.
Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @06:16PM (#6505674)
That's not what I said. The point is one might as well say it never happens for how often it happens in practise. I have only had it happen once in recent memory, and even then it was because the hosted CI we use was experiencing issues.
Re:Time to hand over the reins before Capistrano costs me my... by awj on Monday October 07, 2013 @12:43PM (#6509444)
Yeah, I'm right there with you.

Rubygems is a wonderful and powerful tool for getting libraries set up and adding new code. It's not really suited for putting things into production, especially when people think pulling old versions (for whatever reason) is acceptable behavior.

At work we install and set up libraries on development machines using bundler/rubygems, then go in and version lock everything after we know we'll be using it. Building a release-worthy version involves repackaging all of the gems as rpms so they can be installed along with all of our other software when building the new (virtual) server.

It's a pain in the ass, yes, but we have never had library issues crop up in production. I know exactly what is on the system, and fixing anything is an obvious and straightforward process.

You don't have to make things this formal/official, but it's pretty easy to achieve library version updates and know that what's on your server will work correctly at the same time.

Re:Time to hand over the reins before Capistrano costs me my... by DrJ on Sunday October 06, 2013 @05:46PM (#6505578)
for High Availability you would be a fool not to either run your own mirror, or package everything you need into a single bundle.
Re:Time to hand over the reins before Capistrano costs me my... by talkingquickly on Sunday October 06, 2013 @04:18PM (#6505275)
I'm about a third of the way through writing exactly that, covering deployment (capistrano) and basic server provisioning (chef), specifically for Rails apps. If you (or anyone) is interested my email/ twitters in my profile. Aiming to have it out end of 2013/ start of 2014 but would be happy to release it to a few people early for feedback.
Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @04:07PM (#6505237)
Capistrano, what a Byzantine way to deploy software; I haven't typed cap deploy in about 3 years. Heroku's model of Git-based deployment and 12-factor apps has never given me a problem. Also Heroku deploys are de facto tagged as Releases (https://devcenter.heroku.com/articles/releases). I can't wait for Flynn (http://flynn.io/) to be released, it provides a Heroku-esque Git-based deployment strategy on any host.

P.S. I enjoy reading your comments as do many others, but I feel you hand-wave over important points sometimes, e.g. Why you feel tagging is important. If it truly is a 500 word discussion it shouldn't be hard to synopsise.

Re:Time to hand over the reins before Capistrano costs me my... by patio11 on Sunday October 06, 2013 @04:52PM (#6505395)
It is tangential to the point of the comment, since this only gets you to 0.001% of a Rails deployment which works, but if you're interested:

Tags, plus sufficiently advanced dependency management and database migrations (n.b. not trivial!), allow you to track and reproduce past states of the deployed software.

For example: A customer reports a problem. You verify the problem exists. The customer reports that the system didn't have the problem last week Tuesday. If you want to know why, tagged releases (and a record of them -- incidentally, another one of the 643 things to know is "All deploys should be recorded somewhere") let you travel in time back to the software in use last Tuesday, verify if the customer's recollection is accurate (well, sorta), and then compare just what has changed rather than trying to run down the bug without any historical context.

Naming things also lets you talk about them, which is helpful, because you'll want to talk about individual releases of the software. (I mean, sure, you could use random hexadecimal numbers, but for whatever reason people find production_release_20131007_3 a bit more informative than 066630de00d242137efab6bf21b8ea04aeee7a1d. One glance at the first one tells you that it's the 3rd deploy from October 7th, assuming you've used the company's naming convention for more than a minute. The second one tells you nothing and is difficult to pull useful information out of without having to manually cross-tabulate it with you git repository, which would be unfortunate if it were e.g. attached to a log file, customer support request, or Wiki article about known-good releases for interacting with external systems.)

Re:Time to hand over the reins before Capistrano costs me my... by drags on Sunday October 06, 2013 @07:45PM (#6505924)
This is where triggering deploys through Jenkins is really helpful. Now you have a record of which SHA was deployed, when it was deployed and a copy of the console log for the deploy. Can't do much better than that.
Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @05:07PM (#6505447)
Thanks it's not for my benefit, it's for the engineers that might not know better and blindly follow something you say because of your standing in this community. Cargo-culting is not a good habit to encourage in software engineering.

FWIW dates in tags are redundant because the tag itself has a time stamp. Re: environment names in tags, IMO they don't belong in the repo.

Thanks for replying.

Re:Time to hand over the reins before Capistrano costs me my... by Sujan on Sunday October 06, 2013 @05:27PM (#6505514)
> FWIW dates in tags are redundant because the tag itself has a time stamp.

Having them in the tagname makes it much easier and more visible.

Re:Time to hand over the reins before Capistrano costs me my... by sjtgraham on Sunday October 06, 2013 @05:32PM (#6505535)
Times are in the git log. Same as the commit message/tag name/etc.
Re:Time to hand over the reins before Capistrano costs me my... by mynameisvlad on Sunday October 06, 2013 @06:22PM (#6505686)
It's still much easier to scroll down a list of tags and find the right one by date than to look through the git log and look at both a tag name and timestamp.
Re:Time to hand over the reins before Capistrano costs me my... by Dylan16807 on Monday October 07, 2013 @02:01PM (#6509989)
Personally I find git log easier to handle than an enormous list of tags.
Re:Time to hand over the reins before Capistrano costs me my... by Poiesis on Sunday October 06, 2013 @05:42PM (#6505567)
"Good judgement comes from experience; experience comes from bad judgement."
Re:Time to hand over the reins before Capistrano costs me my... by enko on Sunday October 06, 2013 @10:57PM (#6506331)

  after "deploy:restart", "deploy:tag_release"

  desc 'Tag release'
  task :tag_release do
    `git checkout #{rails_env}`
    `git tag #{rails_env}_#{DateTime.now.strftime "%Y_%m_%d-%H_%M"}`
    `git push --tags`
    `git checkout master`
  end
Boom!
Re:Time to hand over the reins before Capistrano costs me my... by dnr on Monday October 07, 2013 @02:42AM (#6506798)
That's not going to match the release name that capistrano chose, right? Seems like you'd want to use latest_release or something.
Re:Time to hand over the reins before Capistrano costs me my... by bradleyland on Monday October 07, 2013 @02:33PM (#6510234)
We do the inverse. We tag first, then instruct Capistrano to grab the latest release (with a prompt). We have a release plan though, where software goes through QA before it's tagged. Only software ready for production gets a tag. Everything up to that point is done on a release branch.

    set :branch do
      default_tag = `git tag`.split("\n").last

      tag = Capistrano::CLI.ui.ask "Tag to deploy (make sure to push the tag first): [#{default_tag}] "
      tag = default_tag if tag.empty?
      tag
    end
Re:Time to hand over the reins before Capistrano costs me my... by enko on Monday October 07, 2013 @03:18AM (#6506879)
Yeah, modify to taste. I only wanted to post some example code to show how easy it is to automate tagging.

My code won't be appropriate if you don't use master/staging/production branches, either.

Re:Time to hand over the reins before Capistrano costs me my... by berto77 on Monday October 07, 2013 @09:03PM (#6512347)
Just use git flow for releases. For non-trivial deploys, you may want to check out teamcity.
Re:Time to hand over the reins before Capistrano costs me my... by bradleyland on Sunday October 06, 2013 @08:42PM (#6506039)
> Capistrano, what a Byzantine way to deploy software...

Why would you come here to say that? Capistrano is one way to deploy software. Heroku's method is another. Neither is wrong.

This kind of thing is why author's of open source tools like Capistrano get burnt out and just want to run for the hills. Because people with no skin in the game have to come along and shoot their mouth off.

You're probably a really nice person, but when you do things like this, you hurt other people and you make yourself look like an asshole.

Re:Time to hand over the reins before Capistrano costs me my... by FooBarWidget on Monday October 07, 2013 @05:25AM (#6507207)
Well-said. Heroku-style deploys are not a replacement for Capistrano-style deploys, merely an alternative. Capistrano is a much lower-level tool. I use Capistrano also for general sysadmin tasks that comprise multiple servers.
Re:Time to hand over the reins before Capistrano costs me my... by conatus on Monday October 07, 2013 @06:51AM (#6507402)
Is it really Byzantine? Never ever had this thought. Once its setup, you just cap deploy - how is this much different from git push heroku? To do anything complex with PaaS stuff you still have to write code to setup the environment - likely no more than for cap.
Re:Time to hand over the reins before Capistrano costs me my... by timdorr on Monday October 07, 2013 @01:39AM (#6506653)
There definitely is a product here, and it's already being built. Docker is the underlying framework for which we'll see significant improvement for deploys in the near future.

In the meantime, and if you're on AWS, check out OpsWorks. It's the cat's pajamas. It both makes much of the hassle of deploying a thing of the past, is extremely flexible, and makes it possible to have Heroku-like "git push" deploys without giving up control (or being forced into Beanstalk's opinionated ways). Amazon made a very smart purchase when they bought Scalarium.

Re:Time to hand over the reins before Capistrano costs me my... by jessepollak on Sunday October 06, 2013 @05:04PM (#6505435)
you don't happen to have a good online reference on Why We Tag Shit, do you?
Re:Time to hand over the reins before Capistrano costs me my... by robmclarty on Monday October 07, 2013 @11:50AM (#6509007)
Not exactly a product, nor wholly Capistrano-centric, but I recently put together an article on how I deploy Rails on a new VM from scratch: http://robmclarty.com/blog/how-to-deploy-a-rails-4-app-with-...
Re:Time to hand over the reins before Capistrano costs me my... by davedx on Monday October 07, 2013 @03:12AM (#6506862)
This is one of the biggest gotchas of (some of) the high productivity full stack frameworks that are out there, in my experience. I've also had issues getting Meteor deployed, and while it's in many ways a smaller, simpler beast than Rails, it has the same kind of black magic and hitting-a-wall-at-100mph deployment experience.

Both Rails and Meteor will let you develop apps at breakneck speed, with their powerful, magic cores and their excellent module ecosystems, but when you get to deploying them you'll sometimes wish you'd stayed on LAMP or (god forbid) ASP.NET. Yes, I really said that.

Re:Time to hand over the reins before Capistrano costs me my... by gesman on Monday October 07, 2013 @01:50PM (#6509914)
I glad you said that. I'm seriously considering moving from RoR to ASP.NET/C# platform.

We're spending $50k-$100k/yr on Linux system administration of all the small and big moving parts that always fall apart and requires constant babysitting.

I want to give MSFT all this money and use MSVS, C#, ASP.NET and Azure for everything. I love MSVS and always loves MSVC (back in the days). I love performance of C{++|#}.

I don't feel inspired to build great SaaS solutions with shitty interpreted languages, forcing to use made-in-the-basement plugins (or gems) and all that trailing crap of sluggishness, upgrades, fixes and weird behaviors that follows.

Now you all may downvote me!