Gitea: Difference between revisions
Guest09248 (talk | contribs) No edit summary |
m (Update links) |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
[https://gitea.com Gitea] is a community managed lightweight code hosting solution written in Go. It is a fork of Gogs. | |||
{{Note|This guide is not for installing Gitea in Docker. If you want to install Gitea in a Docker container, follow [https://docs.gitea.com/installation/install-with-docker the official documentation]}} | |||
== Installation == | |||
First, [[Repositories#Managing_repositories| Enable the Community Repository]] | |||
Then install the {{pkg|gitea}} package: | |||
{{cmd|apk add gitea}} | |||
== Setting up the Database == | |||
{{Note|These instructions are for MariaDB. If you would like to set up another database, follow [https://docs.gitea.com/installation/database-prep the official documentation]}} | |||
Install the MariaDB and {{pkg|mariadb-client}} packages: | |||
{{cmd|apk add mariadb mariadb-client}} | |||
Set up the MariaDB installation and secure it: | |||
{{cmd|<nowiki>mysql_install_db --user=mysql --datadir=/var/lib/mysql</nowiki> | |||
service mariadb start | |||
rc-update add mariadb | |||
mysql_secure_installation}} | |||
Create the <code>gitea</code> database and a user with access to it: | |||
{{Note|Everything after the <code>mysql -u root -p</code> should be typed in the MariaDB prompt (looks like <code>MariaDB [(none)]></code>)}} | |||
{{Note|Replace the above username 'giteauser' and password 'giteapassword' with something secure. Remember these settings. You will need them later when setting up Gitea.}} | |||
{{cmd|mysql -u root -p | |||
CREATE DATABASE gitea DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | |||
GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'giteapassword'; | |||
FLUSH PRIVILEGES; | |||
EXIT}} | |||
If you want, you can uninstall the <code>mariadb-client</code> now as it's not needed anymore: | |||
{{cmd|apk del mariadb-client}} | |||
In {{path|/etc/gitea/app.ini}}, replace the contents of the <code>[database]</code> section with the following: | |||
<pre> | |||
DB_TYPE = mysql | |||
HOST = /var/run/mysqld/mysqld.sock | |||
NAME = gitea ; The database name set with 'CREATE DATABASE' | |||
USER = giteauser ; The database user | |||
PASSWD = giteapassword ; The password for the database user | |||
</pre> | |||
== Configurations == | |||
The Gitea service can be configured using {{path|/etc/conf.d/gitea}}: | |||
{| class="wikitable" | |||
|- | |||
! Description !! Configuration Variable !! Default Value | |||
|- | |||
| User to run Gitea under || GITEA_USER || gitea | |||
|- | |||
| Gitea working directory || GITEA_WORK_DIR || /var/lib/gitea/ | |||
|- | |||
| Gitea configuration file || GITEA_CONF || /etc/gitea/app.ini | |||
|} | |||
Some additional settings in {{path|/etc/gitea/app.ini}}: | |||
{| class="wikitable" | |||
|- | |||
! Description !! Configuration Variable !! Default Value | |||
|- | |||
| Gitea customization directory || <code>Cannot be configured</code> || /var/lib/gitea/custom/ | |||
|- | |||
| Web files || STATIC_ROOT_PATH || /usr/share/webapps/gitea/ | |||
|- | |||
| Data files || APP_DATA_PATH || /var/lib/gitea/data/ | |||
|- | |||
| Git repository storage directory || ROOT || /var/lib/gitea/git/ | |||
|- | |||
| Log directory || ROOT_PATH || /var/log/gitea/ | |||
|} | |||
{{Note|Gitea has a built-in web server, so there is no need to configure one. However, you can [https://docs.gitea.com/administration/reverse-proxies set up a reverse proxy].}} | |||
{{Note|To customize the look and feel of Gitea, find the correct path in {{path|/usr/share/webapps/gitea/}} and make the same path in {{path|/var/lib/gitea/custom/}}. For example, to add a new Gitea theme, create the {{path|/var/lib/gitea/custom/public/css/}} directory, then add the css for the theme there.}} | |||
== Controlling and starting gitea == | |||
You should not start Gitea without setting certain environment variables and passing some options, since it won't know where to store data and logs, so it is recommended to start gitea using the init script: | |||
{{cmd|service gitea start}} | |||
To add Gitea to the default runlevel (such that it runs automatically on every boot): | |||
{{cmd|rc-update add gitea}} | |||
To stop the Gitea service: | |||
{{cmd|service gitea stop}} | |||
=== Running Gitea without the init script === | |||
If (for whatever reason), you would like to start Gitea without using the initscript, you should first stop the Gitea service: | |||
{{cmd|service gitea stop}} | |||
Then, run Gitea with this command (as the <code>gitea</code> user): | |||
{{cmd|<nowiki>GITEA_WORK_DIR=/var/lib/gitea gitea web --config /etc/gitea/app.ini</nowiki>}} | |||
This will use the correct configuration file and write to the correct directories. | |||
== Post installation == | |||
{{Expand}} | {{Expand}} | ||
After installing Gitea, go to <nowiki>http://localhost:3000</nowiki> and start the post-installation process. | |||
== Setting up SSH Git access == | |||
'''Do not''' try to be clever and use <code>ssh-copy-id</code>, as it will not have the correct command set. | |||
As an example, if this is the public key: | |||
<pre> | |||
ssh-ed25519 ******************************************************************** **********@gmail.com | |||
</pre> | |||
The line in {{path|.ssh/authorized_keys}} needs to be: | |||
<pre> | |||
command="/usr/bin/gitea --config=/etc/gitea/app.ini serv key-2",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 ******************************************************************** **********@gmail.com | |||
</pre> | |||
In order to do this, [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent generate a SSH key], then go to the Gitea settings panel and click the <code>Add Key</code> button, then paste in your public key. | |||
Now, once you've added your private key to the SSH agent, you can use SSH with Gitea like you normally would with GitHub, GitLab, etc. | |||
[[Category:Server]] | |||
[[Category:Git]] |
Latest revision as of 20:49, 29 November 2023
Gitea is a community managed lightweight code hosting solution written in Go. It is a fork of Gogs.
Installation
First, Enable the Community Repository
Then install the gitea package:
apk add gitea
Setting up the Database
Install the MariaDB and mariadb-client packages:
apk add mariadb mariadb-client
Set up the MariaDB installation and secure it:
mysql_install_db --user=mysql --datadir=/var/lib/mysql service mariadb start rc-update add mariadb mysql_secure_installation
Create the gitea
database and a user with access to it:
mysql -u root -p
should be typed in the MariaDB prompt (looks like MariaDB [(none)]>
)mysql -u root -p CREATE DATABASE gitea DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'giteapassword'; FLUSH PRIVILEGES; EXIT
If you want, you can uninstall the mariadb-client
now as it's not needed anymore:
apk del mariadb-client
In /etc/gitea/app.ini, replace the contents of the [database]
section with the following:
DB_TYPE = mysql HOST = /var/run/mysqld/mysqld.sock NAME = gitea ; The database name set with 'CREATE DATABASE' USER = giteauser ; The database user PASSWD = giteapassword ; The password for the database user
Configurations
The Gitea service can be configured using /etc/conf.d/gitea:
Description | Configuration Variable | Default Value |
---|---|---|
User to run Gitea under | GITEA_USER | gitea |
Gitea working directory | GITEA_WORK_DIR | /var/lib/gitea/ |
Gitea configuration file | GITEA_CONF | /etc/gitea/app.ini |
Some additional settings in /etc/gitea/app.ini:
Description | Configuration Variable | Default Value |
---|---|---|
Gitea customization directory | Cannot be configured |
/var/lib/gitea/custom/ |
Web files | STATIC_ROOT_PATH | /usr/share/webapps/gitea/ |
Data files | APP_DATA_PATH | /var/lib/gitea/data/ |
Git repository storage directory | ROOT | /var/lib/gitea/git/ |
Log directory | ROOT_PATH | /var/log/gitea/ |
Controlling and starting gitea
You should not start Gitea without setting certain environment variables and passing some options, since it won't know where to store data and logs, so it is recommended to start gitea using the init script:
service gitea start
To add Gitea to the default runlevel (such that it runs automatically on every boot):
rc-update add gitea
To stop the Gitea service:
service gitea stop
Running Gitea without the init script
If (for whatever reason), you would like to start Gitea without using the initscript, you should first stop the Gitea service:
service gitea stop
Then, run Gitea with this command (as the gitea
user):
GITEA_WORK_DIR=/var/lib/gitea gitea web --config /etc/gitea/app.ini
This will use the correct configuration file and write to the correct directories.
Post installation
This material needs expanding ... Please feel free to help us complete it. |
After installing Gitea, go to http://localhost:3000 and start the post-installation process.
Setting up SSH Git access
Do not try to be clever and use ssh-copy-id
, as it will not have the correct command set.
As an example, if this is the public key:
ssh-ed25519 ******************************************************************** **********@gmail.com
The line in .ssh/authorized_keys needs to be:
command="/usr/bin/gitea --config=/etc/gitea/app.ini serv key-2",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 ******************************************************************** **********@gmail.com
In order to do this, generate a SSH key, then go to the Gitea settings panel and click the Add Key
button, then paste in your public key.
Now, once you've added your private key to the SSH agent, you can use SSH with Gitea like you normally would with GitHub, GitLab, etc.