Git Hosting: Difference between revisions

From CSCWiki
Jump to navigation Jump to search
(Created page with "We have a cgit[https://git.csclub.uwaterloo.ca] instance running off of <nowiki>caffeine</nowiki>. Each club member may have their own directory. Projects used by CSC as a who...")
 
(Document locale issues)
 
(23 intermediate revisions by 3 users not shown)
Line 1: Line 1:
We have a cgit[https://git.csclub.uwaterloo.ca] instance running off of <nowiki>caffeine</nowiki>. Each club member may have their own directory. Projects used by CSC as a whole are hosted in the <code>public</code> directory.
We have a [https://git.csclub.uwaterloo.ca Gitea] instance running on [[Machine List#caffeine|caffeine]]. You can sign in via LDAP to the web interface. Projects used by CSC as a whole are owned by the [https://git.csclub.uwaterloo.ca/public public] organization, except for website-committee related repos, which are owned by the [https://git.csclub.uwaterloo.ca/www www] org.


== Installation Details ==
== Creating a public project ==
<code>/etc/gitea</code> on caffeine contains the configs for Gitea. It's installed as a Debian package, with additional files in <code>/var/lib/gitea/</code>and a systemd service at <code>/lib/systemd/system/gitea.service</code>.

There is a custom locale (used to define CSC-custom strings in some pages) at <code>/var/lib/gitea/custom/options/locale/locale_en-US.ini</code> that may need to be updated when the Gitea APT package is updated. To update this, run the <code>update_custom_locale.sh</code> in that directory (as root).

== Usage ==
"It's basically GitHub"

- raymo

=== SSH keys ===
It is recommended to setup [https://git.csclub.uwaterloo.ca/user/settings/keys SSH keys] so that you do not have to enter your password each time you push to a repo. Once you have uploaded your public key, add the following to your ~/.ssh/config:
<pre>
Host csclub.uwaterloo.ca
HostName csclub.uwaterloo.ca
IdentityFile ~/.ssh/id_rsa
User git
</pre>
(Replace ~/.ssh/id_rsa by the location of your private SSH key.) Now you should be able to clone, push and pull over SSH.

== Continuous Integration ==
We are running a CI server at https://ci.csclub.uwaterloo.ca. It uses OAuth via Gitea for logins, so you need to have logged in to Gitea first. See https://docs.drone.io/ for documentation. All you have to do is create a .drone.yml file in your repo, then enable CI on the repo from the CSC Drone website. There is an example [https://git.csclub.uwaterloo.ca/merenber/drone-test here].

== Pushing and pulling from the filesystem ==
(for syscom only)
<br>
If you need to keep the ability to push/pull from the filesystem, in addition to Gitea, you will need to take the following steps.
In this example, we are migrating a repo called 'public/repo.git', which is a folder under /srv/git on caffeine (which is a symlink to /users/git).
The way we're doing this right now is kind of hacky, but it works:
<ol>
<ol>
<li>Clone the original repo locally: <code>git clone /srv/git/public/repo.git</code></li>
<li>Delete the old repo (from phosphoric-acid, which has no_root_squash): <code>rm -rf /srv/git/public/repo.git</code></li>
<li>Create a new repo with the name 'repo' from the Gitea web UI. This should create a bare repository at <code>/srv/git/public/repo.git</code>. (Make sure you choose the 'public' org from the dropdown.)</li>
<li>
<li>
Push the original repo to the new remote:
Make sure you part of the <code>git</code> group. If not, add yourself to the group via [[ceo]]. Note that it may take a while until the servers synchronize with LDAP. Use the <code>groups</code> command to check if you part of the <code>git</code> group yet.
</li>
<li>
Login to caffeine and run the following:
<pre>
<pre>
cd repo
become_club git
git remote add gitea https://git.csclub.uwaterloo.ca/public/repo.git
cd /srv/git/public
git push gitea master
git init --bare projectname.git
chmod -R g+x projectname.git
</pre>
</pre>
</li>
</li>
<li>
<li>
Remove any git gooks which require gitea:
On any other CSC machine, you can clone the repo by running the following:
<pre>
<pre>
git clone /srv/git/public/projectname.git
rm $(grep -IRl gitea /srv/git/public/repo.git/hooks)
</pre>
</pre>
</li>
</li>
<li>
<li>
Change file permissions:
On a non-CSC machine, you can clone the repo by running the following:
<pre>
<pre>
git clone username@caffeine.csclub.uwaterloo.ca:/srv/git/public/projectname.git
chown -R git:git /srv/git/public/repo.git
chmod -R g+w /srv/git/public/repo.git
</pre>
If you wish to push an existing repo to an empty repo on the server, run the following:
<pre>
git remote add csc username@caffeine.csclub.uwaterloo.ca:/srv/git/public/projectname.git
git push csc branchname
</pre>
</pre>
You will need to do this from phosphoric-acid (due to NFS root squashing).
</li>
</li>
</ol>
</ol>
Note that the repo folder SHOULD be owned by git:git. Anything else will likely break Gitea. (If a user pushes something to the folder and their umask doesn't allow group members to read, for example, then Gitea will be unable to read the repo.)

<br>
== Creating a personal project ==
This means that only trusted users should be in the git group - ideally, only syscom members.
On caffeine, run <code>become_club git</code> and create the directory <code>/srv/git/username</code>.
Login to aspartame and run, as root, <code>chown username /srv/git/username</code>.
As your regular user, you can now create subdirectories under <code>/srv/git/username</code> using
<code>git init --bare projectname.git</code>.

See the previous section for instructions on how to clone/push to your repo.

Latest revision as of 21:04, 14 September 2022

We have a Gitea instance running on caffeine. You can sign in via LDAP to the web interface. Projects used by CSC as a whole are owned by the public organization, except for website-committee related repos, which are owned by the www org.

Installation Details

/etc/gitea on caffeine contains the configs for Gitea. It's installed as a Debian package, with additional files in /var/lib/gitea/and a systemd service at /lib/systemd/system/gitea.service.

There is a custom locale (used to define CSC-custom strings in some pages) at /var/lib/gitea/custom/options/locale/locale_en-US.ini that may need to be updated when the Gitea APT package is updated. To update this, run the update_custom_locale.sh in that directory (as root).

Usage

"It's basically GitHub"

- raymo

SSH keys

It is recommended to setup SSH keys so that you do not have to enter your password each time you push to a repo. Once you have uploaded your public key, add the following to your ~/.ssh/config:

Host csclub.uwaterloo.ca
        HostName csclub.uwaterloo.ca
        IdentityFile ~/.ssh/id_rsa
        User git

(Replace ~/.ssh/id_rsa by the location of your private SSH key.) Now you should be able to clone, push and pull over SSH.

Continuous Integration

We are running a CI server at https://ci.csclub.uwaterloo.ca. It uses OAuth via Gitea for logins, so you need to have logged in to Gitea first. See https://docs.drone.io/ for documentation. All you have to do is create a .drone.yml file in your repo, then enable CI on the repo from the CSC Drone website. There is an example here.

Pushing and pulling from the filesystem

(for syscom only)
If you need to keep the ability to push/pull from the filesystem, in addition to Gitea, you will need to take the following steps. In this example, we are migrating a repo called 'public/repo.git', which is a folder under /srv/git on caffeine (which is a symlink to /users/git). The way we're doing this right now is kind of hacky, but it works:

  1. Clone the original repo locally: git clone /srv/git/public/repo.git
  2. Delete the old repo (from phosphoric-acid, which has no_root_squash): rm -rf /srv/git/public/repo.git
  3. Create a new repo with the name 'repo' from the Gitea web UI. This should create a bare repository at /srv/git/public/repo.git. (Make sure you choose the 'public' org from the dropdown.)
  4. Push the original repo to the new remote:
    cd repo
    git remote add gitea https://git.csclub.uwaterloo.ca/public/repo.git
    git push gitea master
    
  5. Remove any git gooks which require gitea:
    rm $(grep -IRl gitea /srv/git/public/repo.git/hooks)
    
  6. Change file permissions:
    chown -R git:git /srv/git/public/repo.git
    chmod -R g+w /srv/git/public/repo.git
    

    You will need to do this from phosphoric-acid (due to NFS root squashing).

Note that the repo folder SHOULD be owned by git:git. Anything else will likely break Gitea. (If a user pushes something to the folder and their umask doesn't allow group members to read, for example, then Gitea will be unable to read the repo.)
This means that only trusted users should be in the git group - ideally, only syscom members.