aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/self-hosting_git
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 /docs/posts/self-hosting_git
parent897df34e5e55448ae89fbf1a77533e792e7a5c4e (diff)
update intro, new post: Self-hosting Git!
Diffstat (limited to 'docs/posts/self-hosting_git')
-rw-r--r--docs/posts/self-hosting_git/index.html189
1 files changed, 189 insertions, 0 deletions
diff --git a/docs/posts/self-hosting_git/index.html b/docs/posts/self-hosting_git/index.html
new file mode 100644
index 0000000..67ef514
--- /dev/null
+++ b/docs/posts/self-hosting_git/index.html
@@ -0,0 +1,189 @@
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <link rel="stylesheet" href="/style.css">
5 <link rel="stylesheet" href="/syntax.css">
6 <meta charset="UTF-8">
7 <meta name="viewport" content="initial-scale=1">
8 <meta content="#ffffff" name="theme-color">
9 <meta name="HandheldFriendly" content="true">
10 <meta property="og:title" content="Self-hosting Git">
11 <meta property="og:type" content="website">
12 <meta property="og:description" content="a static site {for, by, about} me ">
13 <meta property="og:url" content="https://peppe.rs">
14 <link rel="icon" type="image/x-icon" href="/favicon.png">
15 <title>Self-hosting Git · peppe.rs</title>
16 <body>
17 <div class="posts">
18 <div class="post">
19 <a href="/" class="post-end-link">⟵ Back</a>
20 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/self-hosting_git.md
21">View Raw</a>
22 <div class="separator"></div>
23 <div class="date">
24 17/10 — 2020
25 <div class="stats">
26 <span class="stats-number">
27 87.90
28 </span>
29 <span class="stats-unit">cm</span>
30 &nbsp
31 <span class="stats-number">
32 5.4
33 </span>
34 <span class="stats-unit">min</span>
35 </div>
36 </div>
37 <h1>
38 Self-hosting Git
39 </h1>
40 <div class="post-text">
41 <p>Earlier this week, I began migrating my repositories from Github to <a href="https://git.zx2c4.com/">cgit</a>. If you care at all about big corporates turning open-source into a T-shirt farming service, this is the way to go.</p>
42<h3 id="offerings">Offerings</h3>
43<p>cgit is <em>very</em> bare bones. It is <a href="https://tools.ietf.org/html/rfc3875">cgi</a> web interface interface to git, and nothing more. You may browse repositories, view diffs, commit logs and even clone via http. If you are looking to replace Github with cgit, keep in mind that cgit does not handle issues or pull/merge requests. If people wish to contribute to your work, they would have to send you a patch via email.</p>
44<h3 id="setup">Setup</h3>
45<p>Installing cgit is fairly straightforward, if you would like to compile it from source:</p>
46<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="co"># fetch</span></span>
47<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a><span class="fu">git</span> clone https://git.zx2c4.com <span class="kw">&amp;&amp;</span> <span class="bu">cd</span> cgit</span>
48<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a><span class="fu">git</span> submodule init</span>
49<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="fu">git</span> submodule update</span>
50<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a></span>
51<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a><span class="co"># install</span></span>
52<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="fu">make</span> NO_LUA=1</span>
53<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="fu">sudo</span> make install</span></code></pre></div>
54<p>This would drop the cgit cgi script (and the default css) into <code>/var/www/htdocs/cgit</code>. You may configure cgit by editing <code>/etc/cgitrc</code>. I specify the <code>NO_LUA</code> flag to compile without lua support, exclude that flag if you would like to extend cgit via lua scripts.</p>
55<h3 id="going-live">Going live</h3>
56<p>You might want to use, <a href="https://github.com/gnosek/fcgiwrap">fcgiwrap</a>, a <a href="http://www.nongnu.org/fastcgi">fastcgi</a> wrapper for <code>cgi</code> scripts,</p>
57<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="fu">sudo</span> apt install fcgiwrap</span>
58<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="fu">sudo</span> systemctl start fcgiwrap.socket</span></code></pre></div>
59<p>Expose the cgit cgi script to the web via <code>nginx</code>:</p>
60<pre><code># nginx.conf
61server {
62 listen 80;
63 server_name git.example.com;
64
65 # serve static files
66 location ~* ^.+\.(css|png|ico)$ {
67 root /var/www/htdocs/cgit;
68 }
69
70 location / {
71 fastcgi_pass unix:/run/fcgiwrap.socket;
72 fastcgi_param SCRIPT_FILENAME /var/www/htdocs/cgit/cgit.cgi; # the default location of the cgit cgi script
73 fastcgi_param PATH_INFO $uri;
74 fastcgi_param QUERY_STRING $args;
75 }
76}</code></pre>
77<p>Point cgit to your git repositories:</p>
78<pre><code># /etc/cgitrc
79scan-path=/path/to/git/repos</code></pre>
80<p><strong><em>Note</em></strong>: <em><code>scan-path</code> works best if you stick it at the end of your <code>cgitrc</code></em>.</p>
81<p>You may now create remote repositories at <code>/path/to/git/repos</code>, via:</p>
82<pre><code>git init --bare</code></pre>
83<p>Add the remote to your local repository:</p>
84<pre><code>git remote set-url origin user@remote:/above/path
85git push origin master</code></pre>
86<h3 id="configuration">Configuration</h3>
87<p>cgit is fairly easy to configure, all configuration options can be found <a href="https://git.zx2c4.com/cgit/tree/cgitrc.5.txt">in the manual</a>, here are a couple of cool ones though:</p>
88<p><strong>enable-commit-graph</strong>: Generates a text based graphical representation of the commit history, similar to <code>git log --graph --oneline</code>.</p>
89<pre><code>| * | Add support for configuration file
90* | | simplify command parsing logic
91* | | Refactor parsers
92* | | Add basic tests
93* | | Merge remote-tracking branch &#39;origin/master&#39; in...
94|\| |
95| * | add installation instructions for nix
96| * | switch to pancurses backendv0.2.2
97| * | bump to v0.2.2
98* | | Merge branch &#39;master&#39; into feature/larger-names...
99|\| |
100| * | enable feature based compilation to support win...
101| * | remove dependency on rustc v1.45, bump to v0.2....
102| * | Merge branch &#39;feature/windows&#39; of https://git...
103| |\ \
104| | * | add windows to github actions
105| | * | switch to crossterm backend
106| | * | Merge branch &#39;fix/duplicate-habits&#39;
107| | |\ \
108| | | * | move duplicate check to command parsing blo...</code></pre>
109<p><strong>section-from-path</strong>: This option paired with <code>scan-path</code> will automatically generate sections in your cgit index page, from the path to each repo. For example, the directory structure used to generate sections on <a href="https://git.peppe.rs">my cgit instance</a> looks like this:</p>
110<pre><code>├── cli
111│ ├── dijo
112│ ├── eva
113│ ├── pista
114│ ├── taizen
115│ └── xcursorlocate
116├── config
117│ ├── dotfiles
118│ └── nixos
119├── fonts
120│ ├── curie
121│ └── scientifica
122├── languages
123│ └── lisk
124├── libs
125│ ├── cutlass
126│ └── fondant
127├── terminfo
128├── university
129│ └── furby
130└── web
131 └── isostatic</code></pre>
132<h3 id="ease-of-use">Ease of use</h3>
133<p>As I mentioned before, <code>cgit</code> is simply a view into your git repositories, you will have to manually create new repositories by entering your remote and using <code>git init --bare</code>. Here are a couple of scripts I wrote to perform actions on remotes, think of it as a smaller version of Github’s <code>gh</code> program.</p>
134<p>You may save these scripts as <code>git-script-name</code> and drop them in your <code>$PATH</code>, and git will automatically add an alias called <code>script-name</code>, callable via:</p>
135<pre><code>git script-name</code></pre>
136<h4 id="git-new-repo">git-new-repo</h4>
137<p>Creates a new repository on your remote, the first arg may be a path (section/repo-name) or just the repo name:</p>
138<pre><code>#! /usr/bin/env bash
139#
140# usage:
141# git new-repo section/repo-name
142#
143# example:
144# git new-repo fonts/scientifica
145# creates: user@remote:fonts/scientifica
146
147if [ $# -eq 0 ]; then
148 echo &quot;requires an arg&quot;
149 exit 1
150fi
151
152ssh user@remote git init --bare &quot;$1&quot;;</code></pre>
153<h4 id="git-set-desc">git-set-desc</h4>
154<p>To set a one line repository description. It simply copies the local <code>.git/description</code>, into <code>remote/description</code>. <code>cgit</code> displays the contents of this file on the index page:</p>
155<pre><code>#! /usr/bin/env bash
156#
157# usage:
158# enter repo description into .git/description and run:
159# git set-desc
160
161remote=$(git remote get-url --push origin)
162scp .git/description &quot;$remote/description&quot;</code></pre>
163
164 </div>
165
166 <div class=intro>
167 Hi.
168 <div class=hot-links>
169 <a href=https://peppe.rs/index.xml class=feed-button>Subscribe</a>
170 <a href=https://liberapay.com/nerdypepper/donate class=donate-button>Donate</a>
171 </div>
172 <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p>
173 <p>
174 I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
175 I write <a href=https://git.peppe.rs>open-source stuff</a> to pass time.
176 I also design fonts:
177 <a href=https://git.peppe.rs/fonts/scientifica>scientifica</a>,
178 <a href=https://git.peppe.rs/fonts/curie>curie</a>.
179 </p>
180 <p>Send me a mail at [email protected] or a message at [email protected].</p>
181 </div>
182
183 <a href="/" class="post-end-link">⟵ Back</a>
184 <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/self-hosting_git.md
185">View Raw</a>
186 </div>
187 </div>
188 </body>
189</html>