Skip to content

Commit 09b675c

Browse files
committed
https and migration
Adds environment vars to support HTTPS. Adds documentation: * enabling HTTPS * migrating existing repositories Signed-off-by: Phill Kelley <[email protected]>
1 parent 9408baa commit 09b675c

File tree

2 files changed

+141
-1
lines changed

2 files changed

+141
-1
lines changed

.templates/gitea/service.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ gitea:
1212
- GITEA__database__NAME=${GITEA_DB_NAME:-gitea}
1313
- GITEA__database__USER=${GITEA_DB_USER:-gitea}
1414
- GITEA__database__PASSWD=${GITEA_DB_PASSWORD:?eg echo GITEA_DB_PASSWORD=userPassword >>~/IOTstack/.env}
15+
- GITEA__server__PROTOCOL=${GITEA_WEB_PROTOCOL:-http}
1516
- GITEA__server__ROOT_URL=${GITEA_ROOT_URL}
17+
# - GITEA__server__KEY_FILE=/data/git/key.pem
18+
# - GITEA__server__CERT_FILE=/data/git/cert.pem
1619
- GITEA__security__INSTALL_LOCK=true
1720
- GITEA__security__SECRET_KEY=${GITEA_SECRET_KEY}
21+
1822
healthcheck:
1923
test: ["CMD", "curl", "-f", "http://localhost:3000"]
2024
interval: 30s

docs/Containers/Gitea.md

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,51 @@ Environment variables need to be set in several stages:
106106

107107
See [Gitea Server](https://docs.gitea.com/next/administration/config-cheat-sheet#server-server) for more information.
108108

109-
### database root password { #rootpw }
109+
4. By default, Gitea expects to communicate using the HTTP protocol. If you want Gitea to switch to HTTPS, you need to do the following:
110+
111+
- Generate a self-signed certificate:
112+
113+
``` console
114+
$ docker exec gitea gitea cert --host «hostname»
115+
```
116+
117+
where `«hostname»` should be the first part of the fully-qualified domain name that the **user** uses to reach the Gitea service. Examples:
118+
119+
* `gitea.my.domain.com` = `gitea`
120+
* `host.my.domain.com` = `host`
121+
122+
- Uncomment the following environment variables in the service definition:
123+
124+
``` yaml
125+
environment:
126+
...
127+
# - GITEA__server__KEY_FILE=/data/git/key.pem
128+
# - GITEA__server__CERT_FILE=/data/git/cert.pem
129+
```
130+
131+
These variables tell Gitea where to find the X.509 certificate and matching private key that were generated in the first step.
132+
133+
- Tell Gitea to enable HTTPS:
134+
135+
``` console
136+
$ echo "GITEA_WEB_PROTOCOL=https" >>~/IOTstack/.env
137+
```
138+
139+
- Recreate the container:
140+
141+
``` console
142+
$ cd ~/IOTstack
143+
$ docker compose up -d gitea
144+
```
145+
146+
If everything has gone according to plan, Gitea will be expecting HTTPS traffic and will perform SSL authentication using the key and certificate generated in the first step.
147+
148+
Notes:
149+
150+
* The certificate has a one-year lifetime. It can be regenerated at any time by re-running the command provided earlier.
151+
* Gitea also supports LetsEncrypt. See [using ACME with Let's Encrypt](https://docs.gitea.com/administration/https-setup#using-acme-default-lets-encrypt).
152+
153+
## database root password { #rootpw }
110154

111155
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.
112156

@@ -215,3 +259,95 @@ $ docker compose up -d gitea_db
215259
$ docker system prune -f
216260
```
217261

262+
## migrating existing repositories
263+
264+
The simplest approach to migrating an existing repository into Gitea is:
265+
266+
1. Start with an existing clone of the repository you want to migrate;
267+
2. Convert the existing clone to a "bare" repository;
268+
3. Copy the "bare" repository into Gitea's persistent store; and
269+
4. Use the Gitea GUI to adopt it.
270+
271+
### existing clone
272+
273+
Let's assume you have an existing clone of a repository named "my-project" at the path:
274+
275+
```
276+
~/my-repos/my-project
277+
```
278+
279+
### convert to bare
280+
281+
To convert that existing clone to a "bare" repository:
282+
283+
``` console
284+
$ mkdir ~/bare
285+
$ cd ~/bare
286+
$ git clone --bare ~/my-repos/my-project
287+
```
288+
289+
The result will be a folder at the path:
290+
291+
```
292+
~/bare/my-project.git
293+
```
294+
295+
Note:
296+
297+
* If you already have a "bare" repository stored somewhere then the only thing you are likely to need to do is to rename the directory to have the `.git` extension.
298+
299+
The bare clone will probably have inherited the remote URL(s) that were associated with the original cloning process. Those don't actually cause any harm but they can be confusing so it is a good idea to get rid of them:
300+
301+
```
302+
$ cd my-project.git
303+
$ git remote -v
304+
origin «pathOrURLTo»/my-project (fetch)
305+
origin «pathOrURLTo»/my-project (push)
306+
$ git remote remove origin
307+
```
308+
309+
This example only had one remote ("origin"). Some projects have multiple remotes (eg "upstream") so keep executing the `git remote remove «remote»` command until all remotes have been removed.
310+
311+
### copy to Gitea's persistent store
312+
313+
Assuming you have been doing all this work on a computer which is **not** where Gitea is running, the next step is to move the `my-project.git` folder onto the host where Gitea is running. How you do that is up to you. For example:
314+
315+
* the `scp -r` command <sup>†</sup>;
316+
* the `sftp` command plus the `put -r` command <sup>†</sup>;
317+
* file-sharing protocols such as SAMBA or SSHFS; or
318+
* "sneaker-net" via a thumb drive.
319+
320+
> <sup>†</sup> in each case, the `-r` (recursive) is needed to copy the directory and its contents
321+
322+
On the host where Gitea is running, I'm going to assume that the bare repository is at:
323+
324+
```
325+
~/my-project.git
326+
```
327+
328+
Move into the Gitea persistent store:
329+
330+
```
331+
$ cd ~/IOTstack/volumes/gitea/data/git/repositories/«user»/
332+
```
333+
334+
where `«user»` is your username as known to Gitea.
335+
336+
Move the bare repository into this scope:
337+
338+
```
339+
$ mv ~/my-project.git .
340+
```
341+
342+
Note:
343+
344+
* There has been no mention thus far of ownership and permissions. That's because the Gitea container runs as userID 1000. Inside the container, that's the username "git". Outside the container, userID 1000 is the first user defined on the Linux system and is the account that the majority of Linux users login under. You will only have to be concerned about ownership and permissions if you depart from this norm.
345+
346+
### adopt the repository
347+
348+
Go to the Gitea GUI and login to your account. From the main menu, choose "Settings".
349+
350+
In the left hand panel, click "Repositories". If all has gone well, `my-project` will be present in the list, associated with <kbd>Adopt Files</kbd> and <kbd>Delete</kbd> buttons. Click <kbd>Adopt Files</kbd>, then click <kbd>Yes</kbd> to adopt pre-existing files.
351+
352+
The end result is a private repository. If you want it to be public, click on the name of the newly-adopted repository in the list, then click <kbd>Settings</kbd>. Scroll to the bottom of the page into the "Danger Zone" and click <kbd>Make Public</kbd> followed by <kbd>Yes</kbd>.
353+

0 commit comments

Comments
 (0)