gerrit code review

45
Main sponsor Gerrit Luca Milanesio

Upload: luca-milanesio

Post on 17-May-2015

17.168 views

Category:

Education


1 download

DESCRIPTION

Overview of Gerrit Code Review with a specific focus on its Jenkins CI integration.See and learn how to improve your Agile application lifecycle management by making your builds more stable and your development more under control.Gerrit Code Review allows developers to share ideas and get collective ownership of the project design and code-style.

TRANSCRIPT

Page 1: Gerrit Code Review

Main sponsor

GerritLuca Milanesio

Page 2: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Who’s that guy ?

Luca MilanesioLMIT Software / GerritForge LLP

• Jenkins contributor and founder

of JenkinsMobi.com

• Git enthusiast since 2009

and innovator in large

enterprises

• Gerrit contributor since

2011

Page 3: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Agenda

• Agile and the broken build dilemma• Can Git solve it ? • “Agile” workflow with Git• Gerrit: the smart way• Just about code-review ?• Let’s play with Gerrit live !

Page 4: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Agile and continuous integration

• Who is using CI ? … raise your hand !!!!

• Good or bad ?

• Why ?

Page 5: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Continuous Integration is GOOD

• Live “weather forecast” of the project• Detect and resolve conflicts earlier• Bring TDD to life• Enforce collective code ownership• … and much more

Page 6: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Breaking the build id BAD !

• All devs gets tests broken• Build stops • Test are NOT executed

… all team goes at “DEFCON1” to fix it ASAP !!

Page 7: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Broken build dilemma: how to avoid it ?

1. Do not PUSH until you’re 100% sure of GREEN bar

2. Create multiple personal CI builds and validate builds before PUSH

3. Install a “Jenkins Build Game” plug-in and get free beers

… DO ANY OF THEM REALLY WORK ?

Page 8: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Git … can you help out ?

Git short story: the anti-Subversion• Apr 2005 – Linus writes PERL scripts for Linux Kernel SCM• Jul 2005 … Git 0.99 is out !

Git principles:• Continuous branching / merging / rebasing /

stashing• Distributed repositories• Distributed patch distribution• Early integration

(before breaking the CI)

Page 9: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Git topic-branches workflow

A1 A2

topic1

topic2

masterA3

B4 B5

C2 C3 C4

Agile workflow – one topic branch per story• Keep on branch whilst RED / AMBER bar• Continuous rebase on master• Merge on GREEN bar

Page 10: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Problem resolved ?

• Let’s use Git then ?“My repo is the master” “Git is all about peer-to-peer dev” “Who has reverted my commits ? … !$@#!$!”

• Git doesn’t enforce any policyPeer-to-peer development allowedDictatorship or anarchy of changes are both

allowed

… is there a “better Git” out there ?

Page 11: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit, brief history

The idea: Guido Van Rossum Code-review for Perforce Porting to SVN and OpenSourced Python-based

2008 - Project fork for AOSP(Shawn Pearce / Joe Onorato)

Name changed to Gerrit Rietveld Based on Git Set of “patches” on original Guido’s

Rietveld project

2009 - Gerrit 2, the Java + GWT rewriting

(Shawn Pearce)

Google Mondrian

Rietveld

Gerrit Rietveld

gerrit

Page 12: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

What is Gerrit today ?

• 100% pure Java SSH and HTTP Git backendPowered by JGit

• GWT Web-view administrationUsers and GroupsProject and branch securityGit repository browsing

• Git repository replication engine• Code collaboration and review• Code validation through Jenkins Triggers

Page 13: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1 master

CI Build: OK

Page 14: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1 master

A1

clone

localmaster

CI Build: OK

Page 15: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1 master

A1

clone

C2local

master

CI Build: OK

Page 16: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2

A1

clone

C2local

master

push

CI Build: OK

Page 17: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2

A1

clone

C2local

master

push

Verified: -1(build failed)

CI Build: OK

Page 18: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2 C2*

A1

clone

C2local

masterC2*

push

Verified: -1(build failed)

push

CI Build: OK

Page 19: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2 C2*

A1

clone

C2local

masterC2*

push

Verified: -1(build failed)

push

Verified: +1(build OK)

CI Build: OK

Page 20: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2 C2*

A1

clone

C2local

masterC2*

push

Verified: -1(build failed)

push

Verified: +1(build OK)

Reviewed: +2

CI Build: OK

Page 21: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: high level workflow

A1

refs/for/master

master

C2 C2*

A1

clone

C2local

masterC2*

push

Verified: -1(build failed)

push

Verified: +1(build OK)

Reviewed: +2

CI Build: OK

C2*

CI Build: OK

Page 22: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Cool, isn’t it ?

• Gerrit allow “automatic” topic-branches• Triggers with Jenkins branch validation• Enforce collective code-ownership

People “interacts” with the code changesDiscussion on style and architectureDemocratic voting (+1 / -1)

• Project historyReason behind changes is recorded in code-

review

Page 23: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

See Gerrit “live” in action

Page 24: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

1. Set-up

• Option-A: download and install1. Download from

http://code.google.com/p/gerrit/downloads/list2. Gerrit install wizard:

java –jar gerrit-2.2.2.1.war init -d ~/gerrit

3. Run Gerrit:~/gerrit/bin/gerrit.sh start

• Option-B: Gerrit as hosted serviceAssembla.com (free for OpenSorce projects)GitEnterprise.com (free up to 10 users)

Page 25: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

2. Create user and add SSH keys

• Option-A: not easy Gerrit doesn’t support a “local user registry”Options: LDAP or OpenID

• Option-B: use the provider user registrationAssembla:

https://www.assembla.com/signupGitEnterprise:

https://gitent-scm.com/signup

Page 26: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

3. Talk to Gerrit via SSH

• Gerrit SSH console Listen at 29418 port Not a real SSH server (just Gerrit listening)

Page 27: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

4. Create a Gerrit project

• Gerrit Project is: Git repository (use “path notation” to organise projects) Access permissions Code-review and change-sets

• Option-A: use Gerrit SSH command$ ssh -p 29418 lmilanesio@localhost gerrit create-project lmit/33degree

• Option-B: user the provider-specific page Assembla: N/A (only 1 project associated to your “space”) GitEnterprise:

https://gitent-scm.com/newrepo

Page 28: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

5. Clone repo from Gerrit• Git SSH repository URL is:

ssh://<user>@<host>:29418/<Gerrit project>.git

• Gerrit supports HTTP or HTTP/S repository URL:http://<Gerrit URL>/p/<Gerrit project>.git

NOTE: For HTTP authentication, put your credentials on ~/.netrc filemachine <hostname> login <username> password <password>

Page 29: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

6. Gerrit Change-Id

• SHA-1 GUID of a change-set under review• MUST be last line of commit msg

Hint: install Gerrit post-commit hook for auto-generating Change-Id after each Git commit

Now all Git commit will auto-generate a Change-Id !

Page 30: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

7. Submit a change for review

• Change for review committed locally• Push to refs/for/<branch> for submitting local

Git changes for review on <branch>

Page 31: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

8. Verify change against CI

Page 32: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

9. Additional patch-set to Change-Id

• Fix the problem locally• Amend the commit (same Change-Id)• Push again to refs/for/<branch> for adding one

extra change-set

Page 33: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

10. Change-Id is validated against CI

• Request code-review

Page 34: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

11. Review and comment changes

Page 35: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

12. Review merge and submit change

• One or more reviewers can “vote” for the change

• Authorised users can then “Submit” the change.

• Change is automatically merged to master

Page 36: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

13. Master build is triggered … SUCCESS !!

Page 37: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

… is just about code-review then ?

GitHub BitBucket Gitorious GerritSSH / HTTPS

Free public repo

Free private repo

Repo security

Branch security

Code review

Hooks / API

Replication

CI Integration

OpenSource / extensible

Issue-tracker integration

Page 38: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Credits and resources

• Many thanks toShawn Pearce, father of GerritIts contributors and Google Inc.

• Google Gerrit code-reviewhttp://code.google.com/p/gerrit/

• Assembla Gerrithttp://review.assembla.com

• GitEnterprisehttp://review.gitent-scm.com@gitenterprise

Slides available at http://www.slideshare.net/lucamilanesioFollow me: @lucamilanesio

Page 39: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

BACKUP

Page 40: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Gerrit: just code-review then ?

• Git Security – GroupsDefine different “roles” in the projectSystem groups

• Anonymous users: use for public projects• Registered Users: all users• Administrators: to administer Gerrit• Project Owners: to administer projects• Non-interactive Users: for CI or batch

operationsGroups can be hierarchical (groups of

groups)

Page 41: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Define groups and members

Admin > Groups

Page 42: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Putting all together with projects

• Git Security: rights to projectsDefine access rights to Git operationsControl the Gerrit identity vs Git author /

committerDelegate project administrationAssign code-review voting range rightsDefine who can submit and merge

changesOrganise project rights hirarchically

Page 43: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Define project access rights per refspec

Admin > Projects > 33degree > Access

Page 44: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

Assign access rights to Groups

Page 45: Gerrit Code Review

Copyright © 2012 – LMIT Softwarereview.GerritForge™.com

… and Gerrit replication

Master gerrit

Remotegerrit or git

Remotegerrit or git

Git

pro

toco

l

Git

pro

toco

l