== Dev Week -- Pair Programming and Code Review in the Cloud! -- kirkland -- Thu, 3rd Feb, 2012 == {{{#!irc [18:31] welcome all! [18:31] okay, this will be a totally live/interactive session [18:31] please ssh guest@classroom.gazzang.net [18:31] password is 'guest' [18:31] you'll have read only access there [18:31] where I'm going to demo some neat practices for pair programming and code review in the cloud! [18:32] for the best experience, you may want to maximize your window [18:32] or expand it to at least 180x45 characters [18:32] you may want to use ctrl - to decrease font size (in gnome-terminal anyway) [18:32] there's a clicker at the bottom, counting the number people in the session [18:32] i see "14#" at the bottom [18:33] I've used byobu many, many times for these sessions [18:33] but this is the *first* time I've used byobu + tmux ;-) [18:33] we'll see how it goes! [18:33] okay, now that we've got a good count of people in here, let's get started [18:34] in that shared screen session, I'm running IRSSI, a command line irc client [18:34] you can stay connected there (here?) and see what I'm typing [18:34] no need to go back and forth between the terminal session and your chat client [18:34] these are a handful of best practices me and my colleagues around Canonical, Ubuntu, and Gazzang have used over the last few years [18:34] that have really made working with people around the world a lot easier [18:34] chief among these (for me) has been shared GNU screen and now Tmux sessions, in EC2 [18:35] we're able to avoid firewalls and networking/routing issues by "meeting in the middle" [18:35] one or more of us can easily ssh into an EC2 machine [18:35] and these instances can cost as little as $0.02/hour [18:35] now, this one, is a big one ;-) [18:35] 32 cpus and 60GB of memory [18:35] for a "whopping" $2.40/hour :-) [18:36] anyway, this system is running Ubuntu 11.10, plus an updated version of byobu and tmux from ppa:byobu/ppa [18:36] you all who are logged in as the 'guest' user [18:36] are attached to a readonly GNU screen session [18:36] which is wrapped around a tmux session [18:36] which is being driven by my 'ubuntu' user [18:37] for which I'm the only person with access [18:37] that's just for display here [18:37] but if you want to see how to set that up, see the Juju charm 'byobu-classroom' [18:37] in most cases, when I'm doing this with my trusted colleagues [18:37] we just share the same ubuntu account [18:37] and both of us have read/write access [18:38] I'm sure you can appreciate all the things that might go wrong if I gave 27 of you simultaneous read/write access ;-) [18:38] mayhem :-D [18:38] okay, so let's first feel our way around this session [18:38] first, I'll press shift-F1 to display the help/keybindings [18:38] here, i can see that byobu binds a bunch of actions to the F keys [18:39] I'll quickly work my way through a couple of them [18:39] F2 creates new windows, and F3/F4 will move right and left between them [18:39] you won't be able to do that here in our shared session [18:39] but you can do that on your local ubuntu computer by running 'byobu-tmux' on your command line [18:39] so now i hit F2 3 times [18:39] and have windows 0, 1, 2, 3 [18:40] and i can press F3 and F4 to move right and left among them [18:40] i'm going to run the 'top' command in window 3 [18:40] and now i'm going to rename window 3 to say "top" by pressing F8 [18:40] and i'll rename window 0 to "irc" with F8 as well [18:41] okay, so windows are one way of multi tasking [18:41] but spliting the screen is far more interesting! [18:41] ctrl-F2 will split the screen vertically [18:41] and shift-F2 will split the screen horizontall [18:41] and I can keep doing that pretty much ad nauseum! [18:41] note that splits are per-window [18:41] so if I go over to window 3 [18:42] i won't see any splits there, until I create them [18:42] so much space over on the left of window 3 [18:42] i'll create another split there :-) [18:42] moving between windows is F3/F4 [18:42] moving between splits is Shift-Up/Down/Left/Right [18:43] and you should see the split highlighted in purple [18:43] that's your active split [18:43] as well as some numbers that pop up and identify them [18:43] you can jump directly to a number split if you want [18:43] so let's start doing some work in one of these splits [18:43] i have downloaded the source code of libreoffice [18:43] as well as its build dependencies [18:43] let's see it build on a 32 processor system :-) [18:44] and we'll pretend that we're pair programmers working on some big build [18:44] i really like colorized logs [18:44] so I'm going to pipe the output of debuild through ccze [18:44] and that'll take a while :-) [18:45] lets say that I want to break that split out to a window of its own [18:45] as I really don't need to see that build right now [18:45] pressing Shift-F1, I'll get the menu again [18:45] and I can see that Alt-F11 will expand a split to a full window [18:46] so now we have the libreoffice build happening in window 4 [18:46] now, let's look at some source code [18:46] i'm going to install a web application [18:46] we're going to debug a problem [18:46] tail some logs [18:46] and debug it in real time [18:47] I'm going to install pictor [18:47] a web application for browsing pictures over a web interface [18:47] something like picasa, I suppose [18:47] you can point a browser at http://classroom.gazzang.net/pictor [18:47] and you'll see that we need to seed it with some images [18:48] i'm going to grab some packages [18:48] from ubuntu that serve wall papers [18:48] now let's install some symlinks [18:48] to our pictures [18:49] and pretend that's what we want pictor to serve [18:49] now let's tail our apache logs [18:49] in another split [18:50] I can see a few of you browsing that site now :-) [18:50] let's tail the error log now [18:50] I'm going to resize my splits now [18:50] using Ctrl-Up/Down/Left/Right [18:51] busy busy busy :-) [18:51] now [18:51] perhaps you've noticed our bug [18:51] http://classroom.gazzang.net/pictor/?album=%2Fbackdrops&thumbs=1 [18:51] the "backdrops" album is empty [18:51] I wonder why .... [18:52] hmm, so the files in the backdrops directory are png's [18:52] meanwhile, the "working" ones are .jpgs [18:53] let's hack it into the code, then [18:53] this is the point at which [18:53] you and your team [18:53] perhaps pair programming [18:53] might dig through the code and find the bug [18:54] i'm going to search this code for hardcoded "jpg" references [18:54] aha! [18:54] there's an is_image() function [18:54] that looks for files ending in "jpg" and "jpeg" [18:54] let's try adding ".png" [18:54] now refresh [18:54] lovely! [18:54] of course, I just made that change directly on the /usr/share source code [18:54] if we wanted to do this right, we should branch bzr and submit the change [18:54] let's do that very quickly [18:55] there's our 1-line change [18:55] in our bzr cdiff [18:56] and there we have it! [18:56] I'll make sure to credit all of #ubuntu-classroom when I commit this fix later today ;-) [18:56] let's go back and check our office build, out of curiosity [18:57] still chugging along [18:57] are you getting a feel for how this works? [18:57] we use it often for education (like this!) [18:57] where one person is trying to teach one or more how to do something [18:58] but it's also phenomenally useful for debugging complex problems [18:58] johnny-e> QUESTION: is your byobu is using tmux instead of screen? [18:58] johnny-e: well, it's a bit of both [18:58] what you're SEEING is byobu + tmux [18:58] the one line across the bottom [18:58] and the elegant splits [18:58] yes, that's tmux [18:59] but the thing that's keep all of you with readonly access is a wrapper of GNU screen [18:59] though that's entirely transparent to you [18:59] QUESTION: ​ so the double layer of tmux + screen is only because of the need for read-only in this session? [18:59] ssweeny-lernid: yes, exactly [18:59] ssweeny-lernid: when you do this with your friends/colleagues, it'll be trivial to setup [18:59] (this configuration took me a few minutes) [18:59] here's what you'll do ... [18:59] get an Ubuntu system running somewhere [19:00] the "cloud" is nice, because it removes the need for VPNs or fancy routing [19:00] but you could certainly use a physical local system or a VM [19:00] next, you could very conveniently use the ssh-import-id command [19:00] this is also a very useful tool to have in your toolbelt when doing pair programming and code review in the cloud [19:01] you can 'ssh-import-id SOME_LAUNCHPAD_USERNAME' [19:01] and it will securely (over https) connect to Launchpad [19:01] and retrieve that user's public SSH keys and insert them into the local authorized_keys file [19:01] in this way, you can avoid needing to share passwords [19:01] i would have done that today for this session [19:02] but I'm not sure how long it would have taken to import all 29 of you ;-) [19:02] actually, just before we sign off, I'll import your keys [19:02] and let you trash this system for a few seconds before I terminate it :-P [19:03] QUESTION: do you have any problems nesting byobu? like running byobu on my desktop and on my server? [19:03] well, yeah, kinda sorta [19:03] nesting byobu can get complex [19:03] when doing so, you'll need to know the tmux and/or screen key bindings [19:03] and I'd recommend using two different escape sequences [19:03] i use ctrl-a for mour outter session [19:03] and ctrl-b for my inner session [19:04] otherwise, byobu doesn't know which session you're talking to :-) [19:04] QUESTION: I was reading the gnu screen man pages, do you need to set up screen in a specific way to do this? I read something about giving the program root permission or something... [19:04] sinisterstuf: yeah, here's the magic ... [19:04] sinisterstuf: follow me over in the shared session [19:04] you can grab the bzr branch from http://bazaar.launchpad.net/~charmers/charms/oneiric/byobu-classroom/trunk/ [19:05] see hooks/install [19:05] [ -f /usr/share/byobu/profiles/classroom ] || echo " [19:05] aclumask guest+r guest-w guest-x [19:05] aclchg guest +r-w-x '#?' [19:05] aclchg guest +x 'detach' [19:05] multiuser on [19:05] escape "^Bb" [19:05] " > /usr/share/byobu/profiles/classroom [19:05] chmod 644 /usr/share/byobu/profiles/classroom [19:05] that's most of it [19:05] that changes the acls of the guest user to read only [19:05] also, I tweaked the ssh config [19:06] so that the *only* command that the guest user can run on ssh in is to attach to the byobu session [19:06] echo " [19:06] PasswordAuthentication yes [19:06] AllowTcpForwarding no [19:06] Match User guest [19:06] ForceCommand exec screen -x ubuntu/byobu-classroom [19:06] " >> /etc/ssh/sshd_config [19:06] QUESTION: so do you typically nest byobu or just run it in the server? [19:06] jsnapp: I almost never nest byobu [19:06] but that's a good question [19:06] around what I find as best practices for this... [19:06] so I run gnome-terminal (or terminator) [19:06] at full screen [19:06] I use multiple tabs [19:07] but each tab is an ssh session to another server [19:07] in each tab, I run byobu [19:07] which is nice because I can always attach and detach [19:07] actually ... that's a good exercise [19:07] I invite you to detach from the shared session [19:07] using F6 [19:07] and then reattach [19:07] by ssh'ing back in [19:07] ssh guest@classroom.gazzang.net [19:08] you'll see that everything is *exactly* as you left it [19:08] I've just done the same thing [19:08] detached [19:08] and then reattached [19:08] this is your lifeline savior when you have a crappy uplink connection :-) [19:08] it would stink to have this office build die [19:08] just because your ssh session had a hiccup [19:09] now [19:09] each time I need a new shell [19:09] I can either create a new window (F2) [19:09] or a new split (Ctrl-F2/Shift-F2) [19:09] I tend to group similar shells with splits [19:09] so if I'm working on libreoffice in one window [19:09] i might have a handful of related splits [19:09] maybe one building [19:09] maybe one with code [19:09] maybe two with code, side by side [19:10] one for testing, etc. [19:10] one tailing log files [19:10] much like what we're looking at in window 0 [19:10] with 2 logs [19:10] and one code [19:10] oh, let's rearrange the windows [19:10] let's say I want to move the access log left or right one split [19:10] I use Ctrl-F3/F4 [19:11] I can do that with any of the splits [19:11] also, there's a handful of predefined, useful arrange ments [19:11] you can Shift-F8 will toggle through them [19:11] here's equal vertical windows [19:12] or equal horizontal windows [19:12] here's one big one across the top [19:12] and a bunch of verticals across the bottom [19:12] or (probably my favorite) [19:12] one vertical (where I look at my source code) [19:12] and 3 more, where I tail my logs [19:12] I'm going to move my source code over to the left split with Ctrl-F3 [19:13] ah, that's nice [19:13] I can save a particular split arrangement [19:13] Ctrl-Shift-F8 Save the current split-pane layout [19:13] and then restore it later [19:13] Ctrl-F8 Restore a split-pane layout [19:14] there's a menu of the predefined ones, and my saved one, 'favorite' [19:14] oh, let's see tiled as well [19:14] also nice [19:14] it's lovely that *all* of this is happening over ONE single ssh connection [19:14] we have over a dozen shells open [19:14] doing some very busy things [19:14] but just 1 ssh session to the server [19:15] and it's all preserved across attaches and detaches [19:15] QUESTION: ​ Is it possible to do something similar using "ssh -X" to share a desktop in readonly mode when you're working in an IDE? [19:15] kermit666: not that I know of, sorry :-( [19:15] QUESTION: so you're runing byobu on each server you connect to [19:15] yes, always [19:15] johnny-e: you can set that easily on a per-user basis with 'byobu-enable' [19:16] johnny-e: or, you can set that on a system wide basis with 'dpkg-reconfigure byobu' [19:16] HOWEVER [19:16] the best way to do it, I believe [19:16] is by adding a one-liner to your LOCAL ~/.bashrc file [19:16] export LC_TERMTYPE=byobu [19:16] put that in your local ~/.bashrc [19:17] and any time you ssh to a system with a (recent) version of byobu [19:17] this script, /etc/profile.d/Z97-byobu.sh [19:17] will see that you've selected your TERMTYPE to byobu and it will try to launch it by default at startup! [19:17] QUESTION: what if i had an extra view which i would like to toggle on or off ? [19:17] caotic: I don't understand your question, can you clarify please? [19:18] QUESTION: how are you keeping other users screen size from affecting your byobu session? is it the read only access? [19:18] jsnapp: oh, that's a great question [19:18] a *very* hard one as well [19:18] jsnapp: I have overriden the default byobu setting [19:19] jsnapp: normally, byobu sets the tmux option aggressive-resize 'on' [19:19] jsnapp: however, what that means is that everyone is limited by the smallest attached screen [19:19] jsnapp: with 29 of you, one of you could have set your screen to 80x25 and limited all of us [19:19] jsnapp: in some case (most?) that might be the right answer [19:19] jsnapp: but for this demo, it wasn't, sorry [19:19] jsnapp: so I set that to 'off' for this session [19:19] QUESTION: can you assign names to your custom split-pane layouts? [19:20] johnny-e: yes, absolutely, just press ctrl-shift-F8 [19:20] johnny-e: and it'll prompt you to name it [19:20] There are 10 minutes remaining in the current session. [19:20] johnny-e: in your ~/.byobu directory, you'll see a layouts dir [19:20] johnny-e: I named my "favorite" [19:20] johnny-e: and the contents of that file is a tmux split window layout: [19:20] b57b,180x44,0,0{80x44,0,0,99x44,81,0[99x14,81,0,99x14,81,15,99x14,81,30]} [19:21] (have fun interpreting that ;-) [19:21] johnny-e: sorry, I did it earlier; I encourage you to try it on your own byobu system later [19:21] oh, one more important topic! [19:22] now, tmux and screen differ here significantly on a few major points [19:22] i want to cover one of them here [19:22] in tmux, all users will be connected to the same exact session by default [19:22] and all users will see the exact same thing [19:22] which is very much what "pair programming" is all about [19:22] but sometimes, you might want to split off from your colleague [19:22] and work on something else [19:22] on a different view [19:23] here, you would create a new "session" [19:23] which you can do using ctrl-shift-F2 [19:23] so to review: [19:23] F2 Create a new window [19:23] Shift-F2 Create a horizontal split [19:23] Ctrl-F2 Create a vertical split [19:23] Ctrl-Shift-F2 Create a new session [19:23] and then to move between sessions [19:23] Alt-Up/Down Move focus among sessions [19:24] unfortunately, I won't be able to demo that here [19:24] as your screen is attached to my tmux session [19:24] and you won't follow me to the other one [19:24] but try it yourself! it works [19:24] I think we covered all of these, but to review: [19:24] Shift-F1 Display this help [19:24] and creating new things ... [19:25] F2 Create a new window [19:25] Shift-F2 Create a horizontal split [19:25] Ctrl-F2 Create a vertical split [19:25] Ctrl-Shift-F2 Create a new session [19:25] all movement is under F3 and F4 [19:25] There are 5 minutes remaining in the current session. [19:25] F3/F4 Move focus among windows [19:25] Shift-F3/F4 Move focus among splits [19:25] Ctrl-F3/F4 Move a split [19:25] Ctrl-Shift-F3/F4 Move a window [19:25] Alt-Up/Down Move focus among sessions [19:25] Shift-Left/Right/Up/Down Move focus among splits [19:25] Ctrl-Shift-Left/Right Move focus among windows [19:25] Ctrl-Left/Right/Up/Down Resize a split [19:25] so F2/F3/F4 sort of form your "home keys" for byobu [19:25] we can briefly look at the refresh commands [19:25] F5 Reload profile, refresh status [19:25] Shift-F5 Toggle through status lines [19:25] Ctrl-F5 Reconnect ssh/gpg/dbus sockets [19:25] Ctrl-Shift-F5 Change status bar's color randomly [19:26] you should see a few status items in the bottom right, periodically refreshing [19:26] by default, those refresh every 1 second [19:26] i backed that off to 5 seconds, since there are so many of us here [19:26] I just presed Shift-F5 [19:26] and now I can see a different set of status [19:27] including my cost, hostname, ip address [19:27] ctrl-shift-f5 can give your system some personality [19:27] if you have a lot of byobu sessions, seeing them under a different color helps some times [19:27] F6 Detach session and then logout [19:27] Shift-F6 Detach session and do not logout [19:27] Ctrl-F6 Kill split in focus [19:28] perhaps you tried the F6 detach [19:28] shift-F6 will detach from the session, but NOT log you out of the server [19:28] and ctrl-f6 will kill a split [19:28] (perhaps a runaway process) [19:28] OH [19:28] scrollback! [19:28] let's play with scrollback [19:28] which is under F7 [19:28] and alt-pageup/pagedown [19:29] so now I'm scrolling back through one particular split [19:29] anyway, my time is up [19:29] I'll gladly answer questions over in #ubuntu-classroom-chat [19:30] hopefully you see how you can use shared screen and tmux sessions and byobu in the cloud to do code review and pair programming ;-) }}}