BigW Consortium Gitlab

architecture.md 8.82 KB
Newer Older
1
# GitLab Architecture Overview
2

3
## Software delivery
4

5
There are two editions of GitLab: [Enterprise Edition](https://about.gitlab.com/gitlab-ee/) (EE) and [Community Edition](https://about.gitlab.com/gitlab-ce/) (CE). GitLab CE is delivered via git from the [gitlabhq repository](https://gitlab.com/gitlab-org/gitlab-ce/tree/master). New versions of GitLab are released in stable branches and the master branch is for bleeding edge development.
6

7
EE releases are available not long after CE releases. To obtain the GitLab EE there is a [repository at gitlab.com](https://gitlab.com/subscribers/gitlab-ee). For more information about the release process see the section 'New versions and upgrading' in the readme.
8

9
Both EE and CE require an add-on component called gitlab-shell. It is obtained from the [gitlab-shell repository](https://gitlab.com/gitlab-org/gitlab-shell/tree/master). New versions are usually tags but staying on the master branch will give you the latest stable version. New releases are generally around the same time as GitLab CE releases with exception for informal security updates deemed critical.
10

11 12 13 14 15 16 17 18
## Physical office analogy

You can imagine GitLab as a physical office.

**The repositories** are the goods GitLab handling.
They can be stored in a warehouse.
This can be either a hard disk, or something more complex, such as a NFS filesystem;

19 20
**Nginx** acts like the front-desk.
Users come to Nginx and request actions to be done by workers in the office;
21 22 23 24 25

**The database** is a series of metal file cabinets with information on:
 - The goods in the warehouse (metadata, issues, merge requests etc);
 - The users coming to the front desk (permissions)

26
**Redis** is a communication board with “cubby holes” that can contain tasks for office workers;
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

**Sidekiq** is a worker that primarily handles sending out emails.
It takes tasks from the Redis communication board;

**A Unicorn worker** is a worker that handles quick/mundane tasks.
They work with the communication board (Redis).
Their job description:
 - check permissions by checking the user session stored in a Redis “cubby hole”;
 - make tasks for Sidekiq;
 - fetch stuff from the warehouse or move things around in there;

**Gitlab-shell** is a third kind of worker that takes orders from a fax machine (SSH) instead of the front desk (HTTP).
Gitlab-shell communicates with Sidekiq via the “communication board” (Redis), and asks quick questions of the Unicorn workers either directly or via the front desk.

**GitLab Enterprise Edition (the application)** is the collection of processes and business practices that the office is run by.

43
## System Layout
44

45
When referring to `~git` in the pictures it means the home directory of the git user which is typically /home/git.
46

47 48 49 50
GitLab is primarily installed within the `/home/git` user home directory as `git` user. Within the home directory is where the gitlabhq server software resides as well as the repositories (though the repository location is configurable).

The bare repositories are located in `/home/git/repositories`. GitLab is a ruby on rails application so the particulars of the inner workings can be learned by studying how a ruby on rails application works.

51
To serve repositories over SSH there's an add-on application called gitlab-shell which is installed in `/home/git/gitlab-shell`.
52

53
### Components
54

55
![GitLab Diagram Overview](gitlab_architecture_diagram.png)
56
 
57
_[edit diagram (for GitLab team members only)](https://docs.google.com/drawings/d/1fBzAyklyveF-i-2q-OHUIqDkYfjjxC4mq5shwKSZHLs/edit)_
58

59
A typical install of GitLab will be on GNU/Linux. It uses Nginx or Apache as a web front end to proxypass the Unicorn web server. By default, communication between Unicorn and the front end is via a Unix domain socket but forwarding requests via TCP is also supported. The web front end accesses `/home/git/gitlab/public` bypassing the Unicorn server to serve static pages, uploads (e.g. avatar images or attachments), and precompiled assets. GitLab serves web pages and a [GitLab API](https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/api) using the Unicorn web server. It uses Sidekiq as a job queue which, in turn, uses redis as a non-persistent database backend for job information, meta data, and incoming jobs.
60

61
The GitLab web app uses MySQL or PostgreSQL for persistent database information (e.g. users, permissions, issues, other meta data). GitLab stores the bare git repositories it serves in `/home/git/repositories` by default. It also keeps default branch and hook information with the bare repository.
62

63
When serving repositories over HTTP/HTTPS GitLab utilizes the GitLab API to resolve authorization and access as well as serving git objects.
64

65 66 67 68 69
The add-on component gitlab-shell serves repositories over SSH. It manages the SSH keys within `/home/git/.ssh/authorized_keys` which should not be manually edited. gitlab-shell accesses the bare repositories directly to serve git objects and communicates with redis to submit jobs to Sidekiq for GitLab to process. gitlab-shell queries the GitLab API to determine authorization and access.

### Installation Folder Summary

To summarize here's the [directory structure of the `git` user home directory](../install/structure.md).
70

71
### Processes
72 73 74

    ps aux | grep '^git'

75
GitLab has several components to operate. As a system user (i.e. any user that is not the `git` user) it requires a persistent database (MySQL/PostreSQL) and redis database. It also uses Apache httpd or Nginx to proxypass Unicorn. As the `git` user it starts Sidekiq and Unicorn (a simple ruby HTTP server running on port `8080` by default). Under the GitLab user there are normally 4 processes: `unicorn_rails master` (1 process), `unicorn_rails worker` (2 processes), `sidekiq` (1 process).
76

77
### Repository access
78

79
Repositories get accessed via HTTP or SSH. HTTP cloning/push/pull utilizes the GitLab API and SSH cloning is handled by gitlab-shell (previously explained).
80

81
## Troubleshooting
82

83
See the README for more information.
84

85
### Init scripts of the services
86

87
The GitLab init script starts and stops Unicorn and Sidekiq.
88 89

```
90
/etc/init.d/gitlab
91
Usage: service gitlab {start|stop|restart|reload|status}
92
```
93

94 95 96
Redis (key-value store/non-persistent database)

```
97
/etc/init.d/redis
98
Usage: /etc/init.d/redis {start|stop|status|restart|condrestart|try-restart}
99 100 101
```

SSH daemon
102

103
```
104
/etc/init.d/sshd
105 106 107
Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}
```

108
Web server (one of the following)
109 110

```
111
/etc/init.d/httpd
112 113 114 115 116 117 118 119 120
Usage: httpd {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}

$ /etc/init.d/nginx
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest}
```

Persistent database (one of the following)

```
121
/etc/init.d/mysqld
122 123 124 125 126 127
Usage: /etc/init.d/mysqld {start|stop|status|restart|condrestart|try-restart|reload|force-reload}

$ /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ..]
```

128
### Log locations of the services
129

130
Note: `/home/git/` is shorthand for `/home/git`.
131 132 133

gitlabhq (includes Unicorn and Sidekiq logs)

134
- `/home/git/gitlab/log/` contains `application.log`, `production.log`, `sidekiq.log`, `unicorn.stdout.log`, `githost.log` and `unicorn.stderr.log` normally.
135 136 137

gitlab-shell

138
- `/home/git/gitlab-shell/gitlab-shell.log`
139 140 141

ssh

142 143
- `/var/log/auth.log` auth log (on Ubuntu).
- `/var/log/secure` auth log (on RHEL).
144 145 146

nginx

147
- `/var/log/nginx/` contains error and access logs.
148 149 150

Apache httpd

151
- [Explanation of Apache logs](https://httpd.apache.org/docs/2.2/logs.html).
152 153
- `/var/log/apache2/` contains error and output logs (on Ubuntu).
- `/var/log/httpd/` contains error and output logs (on RHEL).
154 155 156

redis

157
- `/var/log/redis/redis.log` there are also log-rotated logs there.
158 159 160

PostgreSQL

161
- `/var/log/postgresql/*`
162 163 164

MySQL

165 166
- `/var/log/mysql/*`
- `/var/log/mysql.*`
167

168
### GitLab specific config files
169

170
GitLab has configuration files located in `/home/git/gitlab/config/*`. Commonly referenced config files include:
171

172 173 174
- `gitlab.yml` - GitLab configuration.
- `unicorn.rb` - Unicorn web server settings.
- `database.yml` - Database connection settings.
175

176
gitlab-shell has a configuration file at `/home/git/gitlab-shell/config.yml`.
177

178
### Maintenance Tasks
179

180
[GitLab](https://gitlab.com/gitlab-org/gitlab-ce/tree/master) provides rake tasks with which you see version information and run a quick check on your configuration to ensure it is configured properly within the application. See [maintenance rake tasks](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/maintenance.md).
181
In a nutshell, do the following:
182 183 184 185 186 187 188 189

```
sudo -i -u git
cd gitlab
bundle exec rake gitlab:env:info RAILS_ENV=production
bundle exec rake gitlab:check RAILS_ENV=production
```

190
Note: It is recommended to log into the `git` user using `sudo -i -u git` or `sudo su - git`. While the sudo commands provided by gitlabhq work in Ubuntu they do not always work in RHEL.