16 Commits

Author SHA1 Message Date
Tom
bfabc38a46 Merge pull request 'New options in the app.ini template.' (#2) from development into main
Reviewed-on: ghost-automation/ds-gitea#2
2026-02-15 15:37:27 +01:00
818626b236 New options in the app.ini template. 2026-02-15 15:29:33 +01:00
Tom
d3927f6c5d Merge pull request 'Templated registration config.' (#1) from development into main
Reviewed-on: ghost-automation/ds-gitea#1
2026-02-12 07:20:30 +01:00
1120daab40 Templated registration config.
Self-registration can be turned off.
Admin verification can be set.
Guest users' read-only view can be configured.
2026-02-12 07:16:52 +01:00
Tom
e4ea3a420d Merge pull request 'Added unregistered view.' (#10) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/10
2026-02-11 21:43:35 +01:00
14d463a882 Added unregistered view. 2026-02-11 21:41:48 +01:00
DeadSwitch
1816d8a585 Merge pull request 'Readme update and registration admin verification.' (#9) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/9
2026-02-11 17:18:47 +01:00
a22b78d585 Registered users must be activated by admin. 2026-02-11 17:07:40 +01:00
aafa72a464 Removed the db password from the light example. 2026-02-11 17:07:23 +01:00
ae3af7ea83 Major readme update. 2026-02-11 15:17:09 +01:00
DeadSwitch
09e8534569 Merge pull request 'Certbot (Let's Encrypt) support.' (#8) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/8
2026-02-11 13:20:18 +01:00
6928e8cf54 Readme license and version badges. 2026-02-11 13:17:51 +01:00
dc1b18019a Https to http in the lightweight example. 2026-02-11 13:14:05 +01:00
02426968fb Added an examples folder. 2026-02-11 13:12:25 +01:00
edb227a763 Let's Encrypt support with certbot. 2026-02-11 13:01:55 +01:00
c03f0a0f4f Fixed a minor nginx warning.
And re-indented the template.
2026-02-10 14:43:29 +01:00
9 changed files with 248 additions and 84 deletions

View File

@@ -1,30 +1,33 @@
#+TITLE: Gitea Server Installer Role
#+TITLE: Gitea Server Role
#+AUTHOR: DeadSwitch | The Silent Architect
#+OPTIONS: toc:nil num:nil \n:t
[[https://opensource.org/licenses/MIT][https://img.shields.io/badge/license-MIT-blue.svg]] [[https://img.shields.io/badge/version-3.0.2-green.svg]]
* ds-gitea
This role installs and configures a [[https://docs.gitea.com/][Gitea]] server.
This role can install and configures a [[https://docs.gitea.com/][Gitea]] server.
It uses SQLite as its default database service - with optional PostgreSQL support.
It uses SQLite as its default database service - with optional PostgreSQL support (=ds-posgresql=).
The role can set up a reverse proxy with SSL using Nginx.
The role can set up a reverse proxy with SSL using Nginx (=ds-nginx=).
Self-signed certificates and Let's Encrypt with =certbot= are supported.
- Use the =ds-ufw= role to configure the firewall.
- Use the =ds-posgresql= role to configure the database.
- Use the =ds-nginx= role to install the proxy server.
The =ds-ufw= role can configure the firewall.
The =ds-act_runner= role can configure and register Actions runners.
* Role Behavior
1. Download and install the Gitea binary
2. (Optionally) Set up the PostgreSQL user and database
3. Set up the user and group for the service
4. Create the required directory structure
5. Wait for the secret creation and storage in SOPS - if secrets are not present
6. Deploy the Gitea configuration
7. Deploy the Gitea systemd service file
8. (Optionally) Set up the reverse proxy with optional SSL
9. Enable and start the service
3. (Optionally) Set up an =nginx= reverse proxy with SSL support
4. Create a user and group for the service
5. Create the required directory structure
6. Wait to save the secrets in SOPS (only if secrets are not present)
7. Deploy the Gitea =app.ini= configuration
8. Deploy the Gitea systemd service
9. Enable and start the services
* Defaults
@@ -33,24 +36,28 @@ gitea_user: git
gitea_group: git
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_database_server: ''
gitea_reverse_proxy: ''
gitea_require_signin_view: true
gitea_disable_registration: true
gitea_register_manual_confirm: false
gitea_enable_captcha: false
gitea_default_keep_email_private: true
#+end_src
* Requirements
- Ansible >= 2.12
- Debian-based OS (Bookworm, Trixie)
- Debian 12+ or compatible
- git
- sudo
- ca-certificates
- (optional) PosgreSQL database
- (optional) Nginx server
- (optional) certbot for Let's Encrypt
* Variables
| Variable | Type | Comment |
|----------------------------+---------+----------------------------------------------|
|----------------------------------+---------+--------------------------------------------------|
| gitea_user | string | Gitea user |
| gitea_group | string | Gitea group |
| gitea_binary_url | string | Download URL of Gitea |
@@ -72,6 +79,13 @@ gitea_reverse_proxy: ''
| gitea_ssl_key | string | SSL key |
| gitea_enable_http_redirect | boolean | Redirect HTTP to HTTPS |
| gitea_self_signed | boolean | Generate a self-signed cert and key |
| gitea_lets_encrypt | boolean | Use certbot to configure the SSL |
| gitea_certbot_email | string | Email to register the certificates |
| gitea_require_signin_view | boolean | If false, public repos are visible without login |
| gitea_disable_registration | boolean | Turn off the user registration feature |
| gitea_register_manual_confirm | boolean | Registration requires admin verification |
| gitea_enable_captcha | boolean | Enable captcha for registration |
| gitea_default_keep_email_private | boolean | Default email policy: private |
* Handlers
@@ -82,7 +96,7 @@ gitea_reverse_proxy: ''
Always save the production secrets in SOPS, or in Ansible Vault.
Generate the secrets manually when the playbook stops:
You can generate the secrets manually when the playbook stops:
#+begin_src shell
gitea generate secret INTERNAL_TOKEN
@@ -95,6 +109,8 @@ Then re-run the playbook to finish the installation.
* Example Playbook
You can find more playbook examples in the =examples= directory.
#+begin_src yaml
- name: Deploy a Gitea server
hosts: gitea
@@ -109,20 +125,25 @@ Then re-run the playbook to finish the installation.
gitea_ssh_domain: gitea.tomsitcafe.com
gitea_domain: gitea.tomsitcafe.com
gitea_http_port: 3000
gitea_root_url: http://gitea.tomsitcafe.com:3000
gitea_root_url: https://gitea.tomsitcafe.com
# Optional Postgresql database backend
gitea_database_server: postgresql
# Optional Nginx reverse proxy configuration
gitea_reverse_proxy: nginx
gitea_enable_https: true
gitea_self_signed: true
gitea_ssl_cert: /var/lib/gitea/certs/cert.pem
gitea_ssl_key: /var/lib/gitea/certs/key.pem
gitea_enable_http_redirect: true
gitea_enable_https: true # Use HTTPS
gitea_self_signed: false # Don't generate self-signed certs
gitea_lets_encrypt: true # Use certbot
gitea_enable_http_redirect: true # Redirect HTTP to HTTPS
# In prod put these secrets in SOPS:
# Certbot configuration
gitea_certbot_email: email@domain.tld
gitea_ssl_cert: /etc/letsencrypt/live/{{ gitea_domain }}/fullchain.pem
gitea_ssl_key: /etc/letsencrypt/live/{{ gitea_domain }}/privkey.pem
gitea_ssl_trusted_certificate: /etc/letsencrypt/live/{{ gitea_domain }}/chain.pem
# In prod put the secrets in SOPS:
gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4
gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw
gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU

View File

@@ -3,3 +3,8 @@ gitea_user: git
gitea_group: git
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_require_signin_view: true
gitea_disable_registration: true
gitea_register_manual_confirm: false
gitea_enable_captcha: false
gitea_default_keep_email_private: true

View File

@@ -0,0 +1,34 @@
---
- name: Install Gitea
hosts: gitea
become: true
roles:
- role: ds-postgresql
- role: ds-nginx
- role: ds-gitea
vars:
gitea_user: git
gitea_group: git
gitea_database_server: postgresql
gitea_binary_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64
gitea_checksum_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64.sha256
gitea_app_name: Tom's IT Cafe Test Gitea Server
gitea_domain: gitea.tomsitcafe.com
gitea_ssh_domain: "{{ gitea_domain }}"
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_root_url: https://{{ gitea_domain }}
gitea_reverse_proxy: nginx
gitea_enable_https: true
gitea_lets_encrypt: true
gitea_enable_http_redirect: true
gitea_certbot_email: tom@tomsitcafe.com
gitea_ssl_cert: /etc/letsencrypt/live/{{ gitea_domain }}/fullchain.pem
gitea_ssl_key: /etc/letsencrypt/live/{{ gitea_domain }}/privkey.pem
gitea_ssl_trusted_certificate: /etc/letsencrypt/live/{{ gitea_domain }}/chain.pem
# Secrets to SOPS
gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4
gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw
gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU
gitea_db_password: Eegh7Aothooph7pa6eu7eitha_zaim0G

View File

@@ -0,0 +1,21 @@
- name: Install Gitea
hosts: gitea
become: true
roles:
- role: ds-gitea
vars:
gitea_user: git
gitea_group: git
gitea_binary_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64
gitea_checksum_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64.sha256
gitea_app_name: Tom's IT Cafe Test Gitea Server
gitea_domain: gitea.tomsitcafe.com
gitea_ssh_domain: "{{ gitea_domain }}"
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_root_url: http://{{ gitea_domain }}:{{ gitea_http_port }}
# Secrets to SOPS
gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4
gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw
gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU

View File

@@ -0,0 +1,31 @@
- name: Install Gitea
hosts: gitea
become: true
roles:
- role: ds-postgresql
- role: ds-nginx
- role: ds-gitea
vars:
gitea_user: git
gitea_group: git
gitea_database_server: postgresql
gitea_binary_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64
gitea_checksum_url: https://dl.gitea.com/gitea/1.25.4/gitea-1.25.4-linux-amd64.sha256
gitea_app_name: Tom's IT Cafe Test Gitea Server
gitea_domain: gitea.tomsitcafe.com
gitea_ssh_domain: "{{ gitea_domain }}"
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_root_url: https://{{ gitea_domain }}
gitea_reverse_proxy: nginx
gitea_enable_https: true
gitea_self_signed: true
gitea_ssl_cert: /var/lib/gitea/certs/cert.pem
gitea_ssl_key: /var/lib/gitea/certs/key.pem
gitea_enable_http_redirect: true
# Secrets to SOPS
gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4
gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw
gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU
gitea_db_password: Eegh7Aothooph7pa6eu7eitha_zaim0G

29
tasks/lets-encrypt.yml Normal file
View File

@@ -0,0 +1,29 @@
---
- name: Install certbot
ansible.builtin.apt:
name:
- certbot
state: present
- name: Ensure webroot directory exists
ansible.builtin.file:
path: /var/www/html/.well-known/acme-challenge
state: directory
owner: www-data
group: www-data
mode: '0755'
- name: Obtain or renew TLS certificate (non-destructive)
ansible.builtin.command:
cmd: >
certbot certonly
--webroot
-w /var/www/html
-d {{ gitea_domain }}
--agree-tos
--email {{ gitea_certbot_email }}
--non-interactive
--keep-until-expiring
register: certbot_result
changed_when: "'Congratulations' in certbot_result.stdout"
notify: Reload_nginx

View File

@@ -99,6 +99,11 @@
file: self-signed-cert.yml
when: gitea_self_signed | default(false)
- name: Configure the Let's Encrypt certificates
ansible.builtin.include_tasks:
file: lets-encrypt.yml
when: gitea_lets_encrypt | default(false)
- name: Pause to generate and save the secrets in SOPS
ansible.builtin.pause:
prompt: |

View File

@@ -50,14 +50,15 @@ ENABLED = false
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
DISABLE_REGISTRATION = false
DISABLE_REGISTRATION = {{ gitea_disable_registration }}
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
ENABLE_CAPTCHA = {{ gitea_enable_captcha }}
REQUIRE_SIGNIN_VIEW = {{ gitea_require_signin_view }}
DEFAULT_KEEP_EMAIL_PRIVATE = {{ gitea_default_keep_email_private }}
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING = true
NO_REPLY_ADDRESS = noreply.localhost
REGISTER_MANUAL_CONFIRM = {{ gitea_register_manual_confirm }}
[openid]
ENABLE_OPENID_SIGNIN = false

View File

@@ -2,14 +2,17 @@
{% if gitea_enable_https | default(false) %}
server {
listen 443 ssl http2;
listen 443 ssl;
http2 on;
server_name {{ gitea_domain }};
ssl_certificate {{ gitea_ssl_cert }};
ssl_certificate_key {{ gitea_ssl_key }};
{% if gitea_lets_encrypt | default(false) %}
ssl_trusted_certificate {{ gitea_ssl_trusted_certificate }};
{% endif %}
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50M;
@@ -29,8 +32,22 @@ server {
server {
listen 80;
server_name {{ gitea_domain }};
{% if gitea_lets_encrypt | default(false) %}
# Allow Let's Encrypt to verify certificates
location ^~ /.well-known/acme-challenge/ {
root /var/www/html;
allow all;
}
# Redirect everything else to HTTPS
location / {
return 301 https://$host$request_uri;
}
{% else %}
return 301 https://$host$request_uri;
{% endif %}
}
{% endif %}
{% else %}