diff options
Diffstat (limited to 'posts')
-rw-r--r-- | posts/self-hosting_git.md | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/posts/self-hosting_git.md b/posts/self-hosting_git.md new file mode 100644 index 0000000..6d0e1a4 --- /dev/null +++ b/posts/self-hosting_git.md | |||
@@ -0,0 +1,220 @@ | |||
1 | Earlier this week, I began migrating my repositories from | ||
2 | Github to [cgit](https://git.zx2c4.com/). If you care at | ||
3 | all about big corporates turning open-source into a T-shirt | ||
4 | farming service, this is the way to go. | ||
5 | |||
6 | ### Offerings | ||
7 | |||
8 | cgit is *very* bare bones. It is | ||
9 | [cgi](https://tools.ietf.org/html/rfc3875) web interface | ||
10 | interface to git, and nothing more. You may browse | ||
11 | repositories, view diffs, commit logs and even clone via | ||
12 | http. If you are looking to replace Github with cgit, keep | ||
13 | in mind that cgit does not handle issues or pull/merge | ||
14 | requests. If people wish to contribute to your work, they | ||
15 | would have to send you a patch via email. | ||
16 | |||
17 | ### Setup | ||
18 | |||
19 | Installing cgit is fairly straightforward, if you would | ||
20 | like to compile it from source: | ||
21 | |||
22 | ```sh | ||
23 | # fetch | ||
24 | git clone https://git.zx2c4.com && cd cgit | ||
25 | git submodule init | ||
26 | git submodule update | ||
27 | |||
28 | # install | ||
29 | make NO_LUA=1 | ||
30 | sudo make install | ||
31 | ``` | ||
32 | |||
33 | This would drop the cgit cgi script (and the default css) | ||
34 | into `/var/www/htdocs/cgit`. You may configure cgit by | ||
35 | editing `/etc/cgitrc`. I specify the `NO_LUA` flag to | ||
36 | compile without lua support, exclude that flag if you would | ||
37 | like to extend cgit via lua scripts. | ||
38 | |||
39 | ### Going live | ||
40 | |||
41 | You might want to use, | ||
42 | [fcgiwrap](https://github.com/gnosek/fcgiwrap), a | ||
43 | [fastcgi](http://www.nongnu.org/fastcgi) wrapper for `cgi` | ||
44 | scripts, | ||
45 | |||
46 | ```sh | ||
47 | sudo apt install fcgiwrap | ||
48 | sudo systemctl start fcgiwrap.socket | ||
49 | ``` | ||
50 | |||
51 | Expose the cgit cgi script to the web via `nginx`: | ||
52 | |||
53 | ``` | ||
54 | # nginx.conf | ||
55 | server { | ||
56 | listen 80; | ||
57 | server_name git.example.com; | ||
58 | |||
59 | # serve static files | ||
60 | location ~* ^.+\.(css|png|ico)$ { | ||
61 | root /var/www/htdocs/cgit; | ||
62 | } | ||
63 | |||
64 | location / { | ||
65 | fastcgi_pass unix:/run/fcgiwrap.socket; | ||
66 | fastcgi_param SCRIPT_FILENAME /var/www/htdocs/cgit/cgit.cgi; # the default location of the cgit cgi script | ||
67 | fastcgi_param PATH_INFO $uri; | ||
68 | fastcgi_param QUERY_STRING $args; | ||
69 | } | ||
70 | } | ||
71 | ``` | ||
72 | |||
73 | Point cgit to your git repositories: | ||
74 | |||
75 | ``` | ||
76 | # /etc/cgitrc | ||
77 | scan-path=/path/to/git/repos | ||
78 | ``` | ||
79 | |||
80 | ***Note***: *`scan-path` works best if you stick it at the end of your | ||
81 | `cgitrc`*. | ||
82 | |||
83 | You may now create remote repositories at | ||
84 | `/path/to/git/repos`, via: | ||
85 | |||
86 | ``` | ||
87 | git init --bare | ||
88 | ``` | ||
89 | |||
90 | Add the remote to your local repository: | ||
91 | |||
92 | ``` | ||
93 | git remote set-url origin user@remote:/above/path | ||
94 | git push origin master | ||
95 | ``` | ||
96 | |||
97 | ### Configuration | ||
98 | |||
99 | cgit is fairly easy to configure, all configuration | ||
100 | options can be found [in the | ||
101 | manual](https://git.zx2c4.com/cgit/tree/cgitrc.5.txt), here | ||
102 | are a couple of cool ones though: | ||
103 | |||
104 | **enable-commit-graph**: Generates a text based graphical | ||
105 | representation of the commit history, similar to `git log | ||
106 | --graph --oneline`. | ||
107 | |||
108 | ``` | ||
109 | | * | Add support for configuration file | ||
110 | * | | simplify command parsing logic | ||
111 | * | | Refactor parsers | ||
112 | * | | Add basic tests | ||
113 | * | | Merge remote-tracking branch 'origin/master' in... | ||
114 | |\| | | ||
115 | | * | add installation instructions for nix | ||
116 | | * | switch to pancurses backendv0.2.2 | ||
117 | | * | bump to v0.2.2 | ||
118 | * | | Merge branch 'master' into feature/larger-names... | ||
119 | |\| | | ||
120 | | * | enable feature based compilation to support win... | ||
121 | | * | remove dependency on rustc v1.45, bump to v0.2.... | ||
122 | | * | Merge branch 'feature/windows' of https://git... | ||
123 | | |\ \ | ||
124 | | | * | add windows to github actions | ||
125 | | | * | switch to crossterm backend | ||
126 | | | * | Merge branch 'fix/duplicate-habits' | ||
127 | | | |\ \ | ||
128 | | | | * | move duplicate check to command parsing blo... | ||
129 | ``` | ||
130 | |||
131 | **section-from-path**: This option paired with `scan-path` | ||
132 | will automatically generate sections in your cgit index | ||
133 | page, from the path to each repo. For example, the directory | ||
134 | structure used to generate sections on [my cgit | ||
135 | instance](https://git.peppe.rs) looks like this: | ||
136 | |||
137 | ``` | ||
138 | ├── cli | ||
139 | │ ├── dijo | ||
140 | │ ├── eva | ||
141 | │ ├── pista | ||
142 | │ ├── taizen | ||
143 | │ └── xcursorlocate | ||
144 | ├── config | ||
145 | │ ├── dotfiles | ||
146 | │ └── nixos | ||
147 | ├── fonts | ||
148 | │ ├── curie | ||
149 | │ └── scientifica | ||
150 | ├── languages | ||
151 | │ └── lisk | ||
152 | ├── libs | ||
153 | │ ├── cutlass | ||
154 | │ └── fondant | ||
155 | ├── terminfo | ||
156 | ├── university | ||
157 | │ └── furby | ||
158 | └── web | ||
159 | └── isostatic | ||
160 | ``` | ||
161 | |||
162 | ### Ease of use | ||
163 | |||
164 | As I mentioned before, `cgit` is simply a view into your git | ||
165 | repositories, you will have to manually create new | ||
166 | repositories by entering your remote and using `git init | ||
167 | --bare`. Here are a couple of scripts I wrote to perform | ||
168 | actions on remotes, think of it as a smaller version of | ||
169 | Github's `gh` program. | ||
170 | |||
171 | You may save these scripts as `git-script-name` and drop | ||
172 | them in your `$PATH`, and git will automatically add an | ||
173 | alias called `script-name`, callable via: | ||
174 | |||
175 | ``` | ||
176 | git script-name | ||
177 | ``` | ||
178 | |||
179 | #### git-new-repo | ||
180 | |||
181 | Creates a new repository on your remote, | ||
182 | the first arg may be a path (section/repo-name) or just the | ||
183 | repo name: | ||
184 | |||
185 | ``` | ||
186 | #! /usr/bin/env bash | ||
187 | # | ||
188 | # usage: | ||
189 | # git new-repo section/repo-name | ||
190 | # | ||
191 | # example: | ||
192 | # git new-repo fonts/scientifica | ||
193 | # creates: user@remote:fonts/scientifica | ||
194 | |||
195 | if [ $# -eq 0 ]; then | ||
196 | echo "requires an arg" | ||
197 | exit 1 | ||
198 | fi | ||
199 | |||
200 | ssh user@remote git init --bare "$1"; | ||
201 | ``` | ||
202 | |||
203 | |||
204 | #### git-set-desc | ||
205 | |||
206 | To set a one line repository | ||
207 | description. It simply copies the local `.git/description`, | ||
208 | into `remote/description`. `cgit` displays the contents of | ||
209 | this file on the index page: | ||
210 | |||
211 | ``` | ||
212 | #! /usr/bin/env bash | ||
213 | # | ||
214 | # usage: | ||
215 | # enter repo description into .git/description and run: | ||
216 | # git set-desc | ||
217 | |||
218 | remote=$(git remote get-url --push origin) | ||
219 | scp .git/description "$remote/description" | ||
220 | ``` | ||