aboutsummaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-17 08:04:30 +0100
committerAkshay <[email protected]>2020-10-17 08:04:30 +0100
commit3414053d7cd17b43dd929e4e5fc468d98145e0d5 (patch)
tree7b6ec8cfe18e217343cdd54986d5c179fc9e8098 /posts
parent897df34e5e55448ae89fbf1a77533e792e7a5c4e (diff)
update intro, new post: Self-hosting Git!
Diffstat (limited to 'posts')
-rw-r--r--posts/self-hosting_git.md220
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 @@
1Earlier this week, I began migrating my repositories from
2Github to [cgit](https://git.zx2c4.com/). If you care at
3all about big corporates turning open-source into a T-shirt
4farming service, this is the way to go.
5
6### Offerings
7
8cgit is *very* bare bones. It is
9[cgi](https://tools.ietf.org/html/rfc3875) web interface
10interface to git, and nothing more. You may browse
11repositories, view diffs, commit logs and even clone via
12http. If you are looking to replace Github with cgit, keep
13in mind that cgit does not handle issues or pull/merge
14requests. If people wish to contribute to your work, they
15would have to send you a patch via email.
16
17### Setup
18
19Installing cgit is fairly straightforward, if you would
20like to compile it from source:
21
22```sh
23# fetch
24git clone https://git.zx2c4.com && cd cgit
25git submodule init
26git submodule update
27
28# install
29make NO_LUA=1
30sudo make install
31```
32
33This would drop the cgit cgi script (and the default css)
34into `/var/www/htdocs/cgit`. You may configure cgit by
35editing `/etc/cgitrc`. I specify the `NO_LUA` flag to
36compile without lua support, exclude that flag if you would
37like to extend cgit via lua scripts.
38
39### Going live
40
41You might want to use,
42[fcgiwrap](https://github.com/gnosek/fcgiwrap), a
43[fastcgi](http://www.nongnu.org/fastcgi) wrapper for `cgi`
44scripts,
45
46```sh
47sudo apt install fcgiwrap
48sudo systemctl start fcgiwrap.socket
49```
50
51Expose the cgit cgi script to the web via `nginx`:
52
53```
54# nginx.conf
55server {
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
73Point cgit to your git repositories:
74
75```
76# /etc/cgitrc
77scan-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
83You may now create remote repositories at
84`/path/to/git/repos`, via:
85
86```
87git init --bare
88```
89
90Add the remote to your local repository:
91
92```
93git remote set-url origin user@remote:/above/path
94git push origin master
95```
96
97### Configuration
98
99cgit is fairly easy to configure, all configuration
100options can be found [in the
101manual](https://git.zx2c4.com/cgit/tree/cgitrc.5.txt), here
102are a couple of cool ones though:
103
104**enable-commit-graph**: Generates a text based graphical
105representation 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`
132will automatically generate sections in your cgit index
133page, from the path to each repo. For example, the directory
134structure used to generate sections on [my cgit
135instance](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
164As I mentioned before, `cgit` is simply a view into your git
165repositories, you will have to manually create new
166repositories by entering your remote and using `git init
167--bare`. Here are a couple of scripts I wrote to perform
168actions on remotes, think of it as a smaller version of
169Github's `gh` program.
170
171You may save these scripts as `git-script-name` and drop
172them in your `$PATH`, and git will automatically add an
173alias called `script-name`, callable via:
174
175```
176git script-name
177```
178
179#### git-new-repo
180
181Creates a new repository on your remote,
182the first arg may be a path (section/repo-name) or just the
183repo 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
195if [ $# -eq 0 ]; then
196 echo "requires an arg"
197 exit 1
198fi
199
200ssh user@remote git init --bare "$1";
201```
202
203
204#### git-set-desc
205
206To set a one line repository
207description. It simply copies the local `.git/description`,
208into `remote/description`. `cgit` displays the contents of
209this 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
218remote=$(git remote get-url --push origin)
219scp .git/description "$remote/description"
220```