Gitea: Difference between revisions

From Alpine Linux
No edit summary
m (Update links)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Expand}}
[https://gitea.com Gitea] is a community managed lightweight code hosting solution written in Go. It is a fork of Gogs.


== Clarifications ==
{{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]}}


1. Gitea was created by a group of users and contributors of the self-hosted Git service Gogs, It is a fork of Gogs and is written in Go.
== Installation ==
 
2. This guide is for real deploy not for docker deploys.. dockers does not need to setup packages and filesystems configs, for that you must use always docker related configurations.


3. If even though docker always uses Alpine linux as images, and the software is alpine packages, it still has nothing to do with using alpine specific commands.
First, [[Repositories#Managing_repositories| Enable the Community Repository]]


4. Git is the version control system (VCS) software behind gitea perse, so must be installed first. But '''repositories on server are not same as in clients.. server repositories are bare repositories'''.
Then install the {{pkg|gitea}} package:
{{cmd|apk add gitea}}


== Pre Requirements ==
== Setting up the Database ==


This document will guide noob users,  
{{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]}}


* CVS command line
Install the MariaDB and {{pkg|mariadb-client}} packages:
** git
{{cmd|apk add mariadb mariadb-client}}
** git-lfs
* Database:
** mysql
** postgresql
** sqlite
** tidb


For database professional setup please refers to the [[Production_DataBases_:_mysql]] page or [[Production_DataBases_:_postgresql]] page
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}}


A hostname is a unique name created to identify a machine on a network, configured in /etc/hostname.
Create the <code>gitea</code> database and a user with access to it:
To change the computer's hostname edit the <code>/etc/hostname</code> file or execute the following command
{{Note|Everything after the <code>mysql -u root -p</code> should be typed in the MariaDB prompt (looks like <code>MariaDB [(none)]></code>)}}
(make sure to replace <code>myhostname</code> with your desired hostname):
{{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


<pre># echo "myhostname" > /etc/hostname</pre>
CREATE DATABASE gitea DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'giteapassword';
FLUSH PRIVILEGES;
EXIT}}


You should also add the hostname to your hosts file (<code>/etc/hosts</code>):
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>
<pre>
127.0.0.1  localhost.localdomain localhost
DB_TYPE = mysql
127.0.1.1  myhostname.mydomain myhostname
HOST = /var/run/mysqld/mysqld.sock
::1        localhost.localdomain localhost
NAME = gitea ; The database name set with 'CREATE DATABASE'
USER = giteauser ; The database user
PASSWD = giteapassword ; The password for the database user
</pre>
</pre>
== Installation ==
This guide does work either if are or not in main or edge the gitea package:, '''take note, do not install any more from edge.. so in fact all gitea dependencies must be listed and installed before gitea and edge brand are activated''', so the following process will guide and show you how to do that; first  gain root privileges or access ssh to your alpine server and then:
# added and update normal repositories
# install direct dependences: git, gnupg, make, bash, coreutils and from normal stable repositories
# install indirect dependences: manpages, grep, lsof, less, curl, binutils, attr, dialog
# alternate edge repositories
# install gitea from edge repository
# restore normal repository
<pre><nowiki>
cat > /etc/apk/repositories << EOF; $(echo)
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community
EOF
apk update
apk add git git-lfs git-doc gnupg gnupg1 make bash bash-doc coreutils
apk add man man-pages grep grep-doc lsof lsof-doc less less-doc curl curl-doc binutils dialog dialog-doc attr
export PAGER=less
cat >> /etc/apk/repositories << EOF; $(echo)
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community
http://dl-cdn.alpinelinux.org/alpine/edge/main
http://dl-cdn.alpinelinux.org/alpine/edge/community
EOF
apk update
apk add gitea
cat > /etc/apk/repositories << EOF; $(echo)
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community
EOF
apk update
</nowiki></pre>
{{warning|Take in consideration that the user <code>gitea</code> or "a gitea" system user must be in the system. Check if the <code>gitea</code> package already crated the user, if not, just created but set home to <code>/var/lib/gitea</code>}}


== Configurations ==
== Configurations ==


Gitea configurations are defined by the gitea service at <code>/etc/init.d/gitea</code> script:
The Gitea service can be configured using {{path|/etc/conf.d/gitea}}:


{| class="wikitable"
{| class="wikitable"
|-
|-
! Artifac !! Name !! Path related
! Description !! Configuration Variable !! Default Value
|-
|-
| Daemon script || gitea || /etc/init.d/gitea
| User to run Gitea under || GITEA_USER || gitea
|-
|-
| Daemon user || gitea || /var/lib/gitea/
| Gitea working directory || GITEA_WORK_DIR || /var/lib/gitea/
|-
|-
| Group user || www-data || /var/www/
| Gitea configuration file || GITEA_CONF || /etc/gitea/app.ini
|-
| Binary program || gitea || /usr/bin/gitea
|-
| Working dir || GITEA_WORK_DIR || /var/lib/gitea/
|-
| Customizing || GITEA_CUSTOM || /var/lib/gitea/custom/
|-
| Config global || gitea.ini || /etc/gitea/app.ini
|-
| Web files || STATIC_ROOT_PATH  || /usr/share/webapps/gitea/
|-
| Data files || APP_DATA_PATH  || /var/lib/gitea/data/
|}
|}


Gitea '''runs as <code>gitea</code> user, and <code>www-data</code> group''', so are ''compatible with any web deploy in system webservers packages of alpine repositories'', but not with any other external installation if does not are same as.
Some additional settings in {{path|/etc/gitea/app.ini}}:
 
Gitea has two configuration files, the '''system defaults at <code>/var/lib/gitea/conf/app.ini</code>''' and modifiable '''package defaults, at <code>/etc/gitea/app.ini</code>'''. Original files are in <code>/usr/share/webapps/gitea</code> and are defaults non-modifiable. For alterations see next sections where are defined initialization, customization and configurations.
 
Gitea can be customized: just '''take same path from <code>/usr/share/webapps/gitea/</code> and put in same manner at <code>/var/lib/gitea/custom/</code> place'''.
 
=== Initialization ===
 
Gitea just after install does not need many configurations, the daemon service init all the needs, take in consideration that this means:  


{| class="wikitable"
{| class="wikitable"
|-
|-
! Config !! Default
! Description !! Configuration Variable !! Default Value
|-
|-
| Start to use || <nowiki>http://localhost:3000</nowiki>
| Gitea customization directory || <code>Cannot be configured</code> || /var/lib/gitea/custom/
|-
|-
| Git repositories || /var/lib/gitea/git
| Web files || STATIC_ROOT_PATH || /usr/share/webapps/gitea/
|-
|-
| Database files || Sqlite at /var/lib/gitea/db/gitea.db
| Data files || APP_DATA_PATH || /var/lib/gitea/data/
|-
|-
| Loggin files || /var/log/gitea
| Git repository storage directory || ROOT || /var/lib/gitea/git/
|-
| Log directory || ROOT_PATH || /var/log/gitea/
|}
|}


For others configurations please check next sections.
{{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].}}


==== Controlling and starting gitea ====
{{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.}}


Gitea binary itselt '''cannot be start alone''', without parameters will put lot of directories and files in the default path, so to start to use must be:
== Controlling and starting gitea ==


# Start from init script!
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:
# Make enabled the init script!
{{cmd|service gitea start}}
# Stop from init script


<pre><nowiki>
To add Gitea to the default runlevel (such that it runs automatically on every boot):
rc-update add gitea default
{{cmd|rc-update add gitea}}


rc-service gitea restart
To stop the Gitea service:
</nowiki></pre>
{{cmd|service gitea stop}}


To stop:
=== Running Gitea without the init script ===


<pre><nowiki>
If (for whatever reason), you would like to start Gitea without using the initscript, you should first stop the Gitea service:
rc-service gitea stop
{{cmd|service gitea stop}}
</nowiki></pre>


A '''manual start without init script can be done''' but to use the files installed on the system the steps are:
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>}}


# stop any running instance
This will use the correct configuration file and write to the correct directories.
# make a command to run with proper arguments


<pre><nowiki>
== Post installation ==
rc-service gitea stop


GITEA_WORK_DIR='/var/lib/gitea' /usr/bin/gitea web --config /etc/gitea/app.ini
{{Expand}}
</nowiki></pre>


This will use the config files and installed files from the package.
After installing Gitea, go to <nowiki>http://localhost:3000</nowiki> and start the post-installation process.


==== Post installation ====
== Setting up SSH Git access ==


'''After install and initialized''' the daemon, you now can just go to <code><nowiki>http://localhost:3000</nowiki></code> and start the post-installation process, '''''if you dont want to change any configuration.. if not check next sections.''''' A starting page will be show.
'''Do not''' try to be clever and use <code>ssh-copy-id</code>, as it will not have the correct command set.


'''The post install page''', only are show when try to use the system, away of the starting page, by example if browse the repositories or try to login. You must not forget to setup that installation.
As an example, if this is the public key:
<pre>
ssh-ed25519 ******************************************************************** **********@gmail.com
</pre>


'''Administrator account must be configured''' before push "install gitea", the button at the end of the post-configuration page when you first visit the installation. Provide and username for admin user, take note "admin" are a reserved word so choose another name. after provide passowrd you will continue the installation.
The line in {{path|.ssh/authorized_keys}} needs to be:
 
<pre>
=== Configuring ===
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>
Gitea can be customized: just '''take same path from <code>/usr/share/webapps/gitea/</code> and put in same manner at <code>/var/lib/gitea/custom/</code> place''', by example to customize default landing page, just take a copy of the <code>/usr/share/webapps/gitea/templates/home.tmpl</code> and put modified one as <code>/var/lib/gitea/custom/templates/home.tmpl</code> as well.
 
 
=== Database configurations ===
 
Gitea for data '''database backend''' for storing configurations.. SQLite are the default. But for others database backends alpine packages of MySQL/MariaDB or PostgreSQL are like normal tarball of each one, admins must know what they want.. there's no automatic window-like installation here. So first go to [[MariaDB]] or [[PostgreSQL]] wiki pages and with a user database configure in the <code>/etc/gitea/app.ini</code> and modify the <code>DB_TYPE</code> change from sqlite to postgres or mysql, <code>NAME</code> as the database access where gitea will store the data, <code>USER</code> as the user that will access the database, <code>PASSWORD</code> with the password of the user to access to the database defined. <code>HOST</code> must be with "localhost" value since this wiki assumes local installation.
 
'''Setup the database to MySQL:'''
 
<pre><nowiki>
service gitea stop
</nowiki></pre>
 
Of course you must changed ''"secret_new_root_password"'' by a proper password provided by you.
 
'''Setup the database to PosgreSQL:'''
 
<pre><nowiki>
service gitea stop
</nowiki></pre>
 
Of course you must changed ''"secret_new_root_password"'' by a proper password provided by you.


= See Also =
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.


* [[Alpine newbie]]
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:Server]]
[[Category:Git]]
[[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.

Note: This guide is not for installing Gitea in Docker. If you want to install Gitea in a Docker container, follow the official documentation

Installation

First, Enable the Community Repository

Then install the gitea package:

apk add gitea

Setting up the Database

Note: These instructions are for MariaDB. If you would like to set up another database, follow the official documentation

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:

Note: Everything after the mysql -u root -p should be typed in the MariaDB prompt (looks like MariaDB [(none)]>)
Note: Replace the above username 'giteauser' and password 'giteapassword' with something secure. Remember these settings. You will need them later when setting up Gitea.

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/
Note: Gitea has a built-in web server, so there is no need to configure one. However, you can set up a reverse proxy.
Note: To customize the look and feel of Gitea, find the correct path in /usr/share/webapps/gitea/ and make the same path in /var/lib/gitea/custom/. For example, to add a new Gitea theme, create the /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:

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.