|
| 1 | +# Gitea |
| 2 | + |
| 3 | +Gitea is a self-hosted software development service similar to GitHub, Bitbucket and GitLab. The IOTstack implementation runs as a pair of containers using a MariaDB database as the back-end. |
| 4 | + |
| 5 | +## references { #references } |
| 6 | + |
| 7 | +* [Gitea Home](https://about.gitea.com) |
| 8 | +* [Gitea on Dockerhub](https://hub.docker.com/r/gitea/gitea) |
| 9 | +* [Gitea documentation](https://docs.gitea.com) |
| 10 | +* [GitHub](https://github.com/go-gitea/gitea) |
| 11 | + |
| 12 | +## environment variables { #envVars } |
| 13 | + |
| 14 | +Environment variables need to be set in several stages: |
| 15 | + |
| 16 | +1. **Before** you start the container for the first time, you should define the following environment variables. If you make a mistake or change your mind later, the best course of action is to start over from a [clean slate](#cleanSlate): |
| 17 | + |
| 18 | + * `GITEA_DB_NAME` is the name of the database that Gitea (the service) will use to store its information in MariaDB. Example: |
| 19 | + |
| 20 | + ``` console |
| 21 | + echo "GITEA_DB_NAME=gitea" >>~/IOTstack.env |
| 22 | + ``` |
| 23 | + |
| 24 | + If omitted, defaults to "gitea". |
| 25 | + |
| 26 | + * `GITEA_DB_USER` is the name of the user that Gitea (the service) will use to authenticate with MariaDB. Example: |
| 27 | + |
| 28 | + ``` console |
| 29 | + echo "GITEA_DB_USER=gitea" >>~/IOTstack.env |
| 30 | + ``` |
| 31 | + |
| 32 | + If omitted, defaults to "gitea". |
| 33 | + |
| 34 | + * `GITEA_DB_PASSWORD` is the password associated with the above user. Example: |
| 35 | + |
| 36 | + ``` console |
| 37 | + $ echo "GITEA_DB_PASSWORD=$(uuidgen)" >>~/IOTstack.env |
| 38 | + ``` |
| 39 | + |
| 40 | + If omitted, the container will not start. |
| 41 | + |
| 42 | + * `GITEA_DB_ROOT_PASSWORD` is the administative password for the MariaDB service. Keep in mind that the `gitea_db` service is dedicated to Gitea. You can run other MariaDB instances in parallel. They will not interfere with each other and neither will they share data or credentials. Example: |
| 43 | + |
| 44 | + ``` console |
| 45 | + $ echo "GITEA_DB_ROOT_PASSWORD=$(uuidgen)" >>~/IOTstack.env |
| 46 | + ``` |
| 47 | + |
| 48 | + If omitted, the container will not start. See [note below](#rootpw). |
| 49 | + |
| 50 | + You (the human user) will **never** need to know the username and passwords set here. You will not need to use these values in practice. |
| 51 | + |
| 52 | +2. **After** you have set the environment variables listed above, start the container: |
| 53 | + |
| 54 | + ``` console |
| 55 | + $ cd ~/IOTstack |
| 56 | + $ docker compose up -d gitea |
| 57 | + ``` |
| 58 | + |
| 59 | + If this is the first time you have launched Gitea, docker compose will also build and run the `gitea_db` service. |
| 60 | + |
| 61 | + You can expect to see the following warning: |
| 62 | + |
| 63 | + ``` |
| 64 | + WARN[0000] The "GITEA_SECRET_KEY" variable is not set. Defaulting to a blank string. |
| 65 | + ``` |
| 66 | + |
| 67 | + This is actually a reminder to execute this command: |
| 68 | + |
| 69 | + ``` console |
| 70 | + $ echo "GITEA_SECRET_KEY=$(docker exec gitea gitea generate secret SECRET_KEY)" >>~/IOTstack/.env |
| 71 | + ``` |
| 72 | + |
| 73 | + After that command has run, start the container again: |
| 74 | + |
| 75 | + ``` console |
| 76 | + $ docker compose up -d gitea |
| 77 | + ``` |
| 78 | + |
| 79 | + The warning message will go away. |
| 80 | + |
| 81 | + See [Managing Deployments With Environment Variables](https://docs.gitea.com/installation/install-with-docker#managing-deployments-with-environment-variables) for more information. |
| 82 | + |
| 83 | +3. The `GITEA_ROOT_URL` environment variable should be set to the URL that the **user** uses to reach the Gitea service. If you use a proxy host such as Nginx then this would be the URL you present to the proxy. For example: |
| 84 | + |
| 85 | + ``` console |
| 86 | + $ echo "GITEA_ROOT_URL=https://gitea.my.domain.com >>~/IOTstack.env |
| 87 | + ``` |
| 88 | + |
| 89 | + Alternatively, if you connect directly to the host on which the service is running, the URL will be that of the host plus the external port of the Gitea container. For example: |
| 90 | + |
| 91 | + ``` console |
| 92 | + $ echo "GITEA_ROOT_URL=http://host.my.domain.com:7920 >>~/IOTstack.env |
| 93 | + ``` |
| 94 | + |
| 95 | + If omitted, defaults to null in which case the container will make a best-efforts determination (which is unlikely to be correct). You will also see this warning: |
| 96 | + |
| 97 | + ``` |
| 98 | + WARN[0000] The "GITEA_ROOT_URL" variable is not set. Defaulting to a blank string. |
| 99 | + ``` |
| 100 | + |
| 101 | + You can change this variable whenever you like. Simply edit the value in `~/IOTstack/.env` and apply the change by running: |
| 102 | + |
| 103 | + ``` console |
| 104 | + $ docker compose up -d gitea |
| 105 | + ``` |
| 106 | + |
| 107 | + See [Gitea Server](https://docs.gitea.com/next/administration/config-cheat-sheet#server-server) for more information. |
| 108 | + |
| 109 | +### database root password { #rootpw } |
| 110 | + |
| 111 | +At the time of writing (April 2025), the MariaDB instance was not respecting the environment variable being used to pass the root password into the container. |
| 112 | + |
| 113 | +> See [MariaDB issue 163](https://github.com/linuxserver/docker-mariadb/issues/163) |
| 114 | +
|
| 115 | +You can ensure that the root password is set by running the following command: |
| 116 | + |
| 117 | +``` console |
| 118 | +$ docker exec gitea_db bash -c 'mariadb-admin -u root password $MYSQL_ROOT_PASSWORD' |
| 119 | +``` |
| 120 | + |
| 121 | +If this command returns an error, it means that the root password was already set (presumably because Issue 163 has been resolved). |
| 122 | + |
| 123 | +If this command succeeds without error, it means that the root password was not set but is now set. |
| 124 | + |
| 125 | +Also notice that you did not need to know or copy/paste the root password to run the above command. It was sufficient to know the name of the environment variable containing the database root password. |
| 126 | + |
| 127 | +## default ports |
| 128 | + |
| 129 | +The IOTstack implementation listens on the following ports: |
| 130 | + |
| 131 | +* 7920 the Gitea graphical user interface |
| 132 | +* 2222 the SSH passthrough service |
| 133 | + |
| 134 | +## getting started |
| 135 | + |
| 136 | +Use your browser to connect to the Gitea service, either: |
| 137 | + |
| 138 | +* directly: |
| 139 | + |
| 140 | + ``` |
| 141 | + http://«host»:7920 |
| 142 | + ``` |
| 143 | + |
| 144 | + where `«host»` is: |
| 145 | + |
| 146 | + - an IP address (eg 192.168.1.10) |
| 147 | + - a hostname (eg `iot-hub` |
| 148 | + - a domain name (eg `iot-hub.my.domain.com`) |
| 149 | + - a multicast domain name (eg `iot-hub.local`) |
| 150 | + |
| 151 | +* indirectly, via a reverse proxy: |
| 152 | + |
| 153 | + ``` |
| 154 | + https://gitea.my.domain.com |
| 155 | + ``` |
| 156 | + |
| 157 | + This assumes that the reverse proxy redirects the *indirect* form (using HTTPS) to one of the *direct* forms (using HTTP). |
| 158 | + |
| 159 | +Click on the <kbd>Register</kbd> button to create an account for yourself. |
| 160 | + |
| 161 | +After that, please rely on the [Gitea documentation](https://docs.gitea.com). |
| 162 | + |
| 163 | +## launch times |
| 164 | + |
| 165 | +When you start the `gitea` service, docker compose auto-starts the `gitea_db` service (a MariaDB aka MySQL implementation). The database service can take some time to start and that, in turn, affects the availability of the `gitea` service. |
| 166 | + |
| 167 | +The time it takes for the `gitea` service to become fully available depends on your hardware (CPU speed, RAM, SD/HD/SSD). As an example, the `gitea` service takes about 30 seconds to become available on a 4GB Raspberry Pi 4 with SSD. |
| 168 | + |
| 169 | +You may get strange error messages if you attempt to connect to `gitea` while it is still coming up. |
| 170 | + |
| 171 | +The moral is: be patient! |
| 172 | + |
| 173 | +## starting over from a clean slate { #cleanSlate } |
| 174 | + |
| 175 | +Proceed as follows: |
| 176 | + |
| 177 | +``` console |
| 178 | +$ cd ~/IOTstack |
| 179 | +$ docker compose down gitea gitea_db |
| 180 | +$ sudo rm -rf ./volumes/gitea |
| 181 | +$ docker compose up -d |
| 182 | +``` |
| 183 | + |
| 184 | +In this situation, you should also regenerate the secret key: |
| 185 | + |
| 186 | +``` console |
| 187 | +$ echo "$(docker exec gitea gitea generate secret SECRET_KEY)" |
| 188 | +``` |
| 189 | + |
| 190 | +> The reason for wrapping the command in an `echo` is because the `generate` command does not terminate the line so the value of the key has a tendency to run into the next Linux prompt. |
| 191 | +
|
| 192 | +Copy the value that is returned to the clipboard, then edit `~/IOTstack.env` to replace the right hand side of `GITEA_SECRET_KEY` with whatever is on the clipboard. Save your work then start the container again: |
| 193 | + |
| 194 | +``` console |
| 195 | +$ docker compose up -d |
| 196 | +``` |
| 197 | + |
| 198 | +## container maintenance |
| 199 | + |
| 200 | +You can maintain the Gitea container with normal `pull` commands: |
| 201 | + |
| 202 | +``` console |
| 203 | +$ cd ~/IOTstack |
| 204 | +$ docker compose pull gitea |
| 205 | +$ docker compose up -d gitea |
| 206 | +$ docker system prune -f |
| 207 | +``` |
| 208 | + |
| 209 | +The Gitea_DB container needs special handling: |
| 210 | + |
| 211 | +``` console |
| 212 | +$ cd ~/IOTstack |
| 213 | +$ docker-compose build --no-cache --pull gitea_db |
| 214 | +$ docker compose up -d gitea_db |
| 215 | +$ docker system prune -f |
| 216 | +``` |
| 217 | + |
0 commit comments