22 Commits

Author SHA1 Message Date
DeadSwitch
7b0b2e8194 Merge pull request 'Proxy and SSL support' (#7) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/7
2026-02-10 13:52:44 +01:00
2cca3d5403 Fixed the SSH clone issue.
The git user needs shell and a disabled password.
2026-02-10 13:36:42 +01:00
9e68459916 Minor readme update. 2026-02-10 12:31:20 +01:00
e23f9b1901 Added reverse proxy support. 2026-02-10 12:13:24 +01:00
DeadSwitch
c8fa7680ca Merge pull request 'Service file update with the Postgresql service' (#6) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/6
2026-02-10 10:18:17 +01:00
007ae9a90a New defaults added.
HTTP & SSH port.
2026-02-10 09:37:13 +01:00
557fe0d5dc Added the new defaults to the readme.
HTTP & SSH ports.
2026-02-10 09:36:44 +01:00
ab06bc177e Updated the service file with Postgresql
When the pgsql is used as backend, the gitea service
must wait for the database.
2026-02-10 09:31:52 +01:00
DeadSwitch
0f2c17071c Merge pull request 'Added the PostgreSQL support to the role.' (#5) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/5
2026-02-09 20:33:58 +01:00
2b3391bf18 Added the example posgresql config to the readme. 2026-02-09 20:18:43 +01:00
18e2fe1204 Postgresql support added. 2026-02-09 20:16:17 +01:00
DeadSwitch
4340021552 Merge pull request 'Updated the readme for more clarity.' (#4) from dev-update-readme into development
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/4
2026-02-09 17:01:32 +01:00
f0aecb43dd Updated the readme for more clarity. 2026-02-09 16:56:29 +01:00
DeadSwitch
d716fefb88 Merge pull request 'Fixed a typo in the readme.' (#3) from development into main
Reviewed-on: http://gitea.tomsitcafe.com:3000/iron/ds-gitea/pulls/3
2026-02-09 15:44:16 +01:00
c088b18b49 Fixing a typo in the readme. 2026-02-09 15:40:33 +01:00
d010774f45 SSH port is configurable for the template. 2026-02-09 15:32:23 +01:00
fe98b961ab Clarifications. 2026-02-09 14:59:38 +01:00
a8a8907463 Set the owner and group of the gitea binary. 2026-02-09 14:18:40 +01:00
f6a20bb16f Set the binary permissions (run). 2026-02-09 14:10:01 +01:00
852791e15a Clarified the secret generation task. 2026-02-09 13:36:38 +01:00
fe2672d55b Added the doc for generating secret keys. 2026-02-09 13:26:28 +01:00
56d6401155 Added the example playbook to the readme. 2026-02-09 13:21:15 +01:00
7 changed files with 215 additions and 29 deletions

View File

@@ -4,30 +4,39 @@
* ds-gitea * ds-gitea
This role installs and configures a basic [[https://docs.gitea.com/][Gitea]] server. This role installs and configures a [[https://docs.gitea.com/][Gitea]] server.
Currently it uses SQLite as its database service. It uses SQLite as its default database service - with optional PostgreSQL support.
Use the =ds-ufw= role to set up the firewall. The role can set up a reverse proxy with SSL using Nginx.
* Features - 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.
- Download and install the Gitea binary * Role Behavior
- Set up the user and group for the service
- Create the required directory structure 1. Download and install the Gitea binary
- Deploy the Gitea configuration 2. (Optionally) Set up the PostgreSQL user and database
- Deploy the Gitea service file 3. Set up the user and group for the service
- Enable and start 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
* Defaults * Defaults
#+begin_src yaml #+begin_src yaml
gitea_user: git gitea_user: git
gitea_group: git gitea_group: git
gitea_http_port: 3000
gitea_ssh_port: 22
gitea_database_server: ''
gitea_reverse_proxy: ''
#+end_src #+end_src
The remaining variables must be declared in the inventory.
* Requirements * Requirements
- Ansible >= 2.12 - Ansible >= 2.12
@@ -35,23 +44,34 @@ The remaining variables must be declared in the inventory.
- git - git
- sudo - sudo
- ca-certificates - ca-certificates
- (optional) PosgreSQL database
- (optional) Nginx server
* Variables * Variables
| Variable | Type | Comment | | Variable | Type | Comment |
|----------------------+--------+----------------------------| |----------------------------+---------+----------------------------------------------|
| gitea_user | string | Gitea user | | gitea_user | string | Gitea user |
| gitea_group | string | Gitea group | | gitea_group | string | Gitea group |
| gitea_binary_url | string | Download URL of Gitea | | gitea_binary_url | string | Download URL of Gitea |
| gitea_checksum_url | string | Checksum URL of the binary | | gitea_checksum_url | string | Checksum URL of the binary |
| gitea_app_name | string | Gitea application title | | gitea_app_name | string | Gitea server title |
| gitea_ssh_domain | string | SSH domain | | gitea_ssh_domain | string | SSH domain |
| gitea_domain | string | Domain to reach Gitea | | gitea_domain | string | Domain to reach Gitea |
| gitea_http_port | int | Gitea HTTP port | | gitea_http_port | int | HTTP port |
| gitea_root_url | string | Protocoll + FQDN | | gitea_ssh_port | int | SSH port |
| gitea_lfs_jwt_secret | string | LFS storage secret | | gitea_root_url | string | Protocol + FQDN + port |
| gitea_internal_token | string | Internal token | | gitea_lfs_jwt_secret | string | LFS storage secret |
| gitea_jwt_secret | string | JWT secret | | gitea_internal_token | string | Internal token |
| gitea_jwt_secret | string | JWT secret |
| gitea_database_server | string | DB server - 'postgresql' or empty for sqlite |
| gitea_db_password | string | PosgreSQL db password (if pgsql is used) |
| gitea_reverse_proxy | string | Reverse proxy to use or not set for no proxy |
| gitea_enable_https | boolean | Configure HTTPS in the proxy |
| gitea_ssl_cert | string | SSL certificate |
| 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 |
* Handlers * Handlers
@@ -60,7 +80,7 @@ The remaining variables must be declared in the inventory.
* Secrets * Secrets
Always store the production secrets in SOPS, or in Ansible Vault. Always save the production secrets in SOPS, or in Ansible Vault.
Generate the secrets manually when the playbook stops: Generate the secrets manually when the playbook stops:
@@ -90,10 +110,23 @@ Then re-run the playbook to finish the installation.
gitea_domain: gitea.tomsitcafe.com gitea_domain: gitea.tomsitcafe.com
gitea_http_port: 3000 gitea_http_port: 3000
gitea_root_url: http://gitea.tomsitcafe.com:3000 gitea_root_url: http://gitea.tomsitcafe.com:3000
# 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
# In prod put these secrets in SOPS: # In prod put these secrets in SOPS:
gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4 gitea_lfs_jwt_secret: G9bZrRHMhRQ8w4R0KkH2VLnx2rzq81ROQ951IQjlMs4
gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw gitea_internal_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3NzA2Mzk1Njh9.ybbaeNLFiLbyvxfj4vkqhXSAXKRGpwvP8jIm9YLPgXw
gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU gitea_jwt_secret: uJni4x4e0AzpkLYc-t4keRJKOB6EaLzwVsdLeamkFyU
gitea_db_password: Eegh7Aothooph7pa6eu7eitha_zaim0G
roles: roles:
- role: ds-gitea - role: ds-gitea

View File

@@ -1,3 +1,5 @@
--- ---
gitea_user: git gitea_user: git
gitea_group: git gitea_group: git
gitea_http_port: 3000
gitea_ssh_port: 22

View File

@@ -8,6 +8,64 @@
update_cache: true update_cache: true
state: present state: present
- name: Set up the PostgreSQL database
block:
- name: Ensure PostgreSQL Python client is installed
ansible.builtin.apt:
name: python3-psycopg2
update_cache: true
state: present
- name: Create the gitea DB role
community.postgresql.postgresql_user:
name: gitea
password: "{{ gitea_db_password }}"
role_attr_flags: "NOSUPERUSER,NOCREATEDB,NOCREATEROLE"
become_user: postgres
- name: Create the gitea database
community.postgresql.postgresql_db:
name: giteadb
owner: gitea
template: template0
encoding: UTF8
lc_collate: en_US.UTF-8
lc_ctype: en_US.UTF-8
become_user: postgres
- name: Ensure pg_hba.conf has local access for gitea
ansible.builtin.lineinfile:
path: /etc/postgresql/{{ postgresql_version }}/main/pg_hba.conf
regexp: '^local\s+giteadb\s+gitea\s+'
line: 'local giteadb gitea scram-sha-256'
state: present
backup: yes
notify:
- Reload_postgresql
when: gitea_database_server | default('') == "postgresql"
- name: Set up the reverse proxy
block:
- name: Deploy the site configuration
ansible.builtin.template:
src: gitea.j2
dest: /etc/nginx/sites-available/gitea
owner: root
group: root
mode: '0644'
notify: Reload_nginx
- name: Enable the gitea site
ansible.builtin.file:
src: /etc/nginx/sites-available/gitea
dest: /etc/nginx/sites-enabled/gitea
state: link
owner: root
group: root
force: true
notify: Reload_nginx
when: gitea_reverse_proxy | default('') == "nginx"
- name: Create the gitea group - name: Create the gitea group
ansible.builtin.group: ansible.builtin.group:
name: "{{ gitea_group }}" name: "{{ gitea_group }}"
@@ -18,7 +76,8 @@
name: "{{ gitea_user }}" name: "{{ gitea_user }}"
group: "{{ gitea_group }}" group: "{{ gitea_group }}"
home: /home/{{ gitea_user }} home: /home/{{ gitea_user }}
shell: /usr/sbin/nologin shell: /bin/bash
password: '*'
system: true system: true
create_home: true create_home: true
@@ -35,6 +94,11 @@
group: "{{ gitea_group }}" group: "{{ gitea_group }}"
mode: '0750' mode: '0750'
- name: Generate self-signed certificates
ansible.builtin.include_tasks:
file: self-signed-cert.yml
when: gitea_self_signed | default(false)
- name: Pause to generate and save the secrets in SOPS - name: Pause to generate and save the secrets in SOPS
ansible.builtin.pause: ansible.builtin.pause:
prompt: | prompt: |

View File

@@ -0,0 +1,18 @@
---
- name: Create the certs directory
ansible.builtin.file:
path: /var/lib/gitea/certs
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: '0750'
state: directory
- name: Generate the self-signed certs for Gitea
ansible.builtin.command: >
gitea cert
--host {{ gitea_domain }},{{ gitea_ssh_domain }}
--out /var/lib/gitea/certs/cert.pem
--keyout /var/lib/gitea/certs/key.pem
become_user: "{{ gitea_user }}"
args:
creates: /var/lib/gitea/certs/cert.pem

View File

@@ -5,6 +5,15 @@ RUN_USER = {{ gitea_user }}
WORK_PATH = /var/lib/gitea WORK_PATH = /var/lib/gitea
RUN_MODE = prod RUN_MODE = prod
{% if gitea_database_server | default('') == "postgresql" %}
[database]
DB_TYPE = postgres
HOST = 127.0.0.1:5432
NAME = giteadb
USER = gitea
PASSWD = {{ gitea_db_password }}
SSL_MODE = disable
{% else %}
[database] [database]
DB_TYPE = sqlite3 DB_TYPE = sqlite3
HOST = 127.0.0.1:3306 HOST = 127.0.0.1:3306
@@ -15,6 +24,7 @@ SCHEMA =
SSL_MODE = disable SSL_MODE = disable
PATH = /var/lib/gitea/data/gitea.db PATH = /var/lib/gitea/data/gitea.db
LOG_SQL = false LOG_SQL = false
{% endif %}
[repository] [repository]
ROOT = /var/lib/gitea/data/gitea-repositories ROOT = /var/lib/gitea/data/gitea-repositories
@@ -26,7 +36,7 @@ HTTP_PORT = {{ gitea_http_port }}
ROOT_URL = {{ gitea_root_url }} ROOT_URL = {{ gitea_root_url }}
APP_DATA_PATH = /var/lib/gitea/data APP_DATA_PATH = /var/lib/gitea/data
DISABLE_SSH = false DISABLE_SSH = false
SSH_PORT = 22 SSH_PORT = {{ gitea_ssh_port }}
LFS_START_SERVER = true LFS_START_SERVER = true
LFS_JWT_SECRET = {{ gitea_lfs_jwt_secret }} LFS_JWT_SECRET = {{ gitea_lfs_jwt_secret }}
OFFLINE_MODE = true OFFLINE_MODE = true

55
templates/gitea.j2 Normal file
View File

@@ -0,0 +1,55 @@
# {{ ansible_managed }}
{% if gitea_enable_https | default(false) %}
server {
listen 443 ssl http2;
server_name {{ gitea_domain }};
ssl_certificate {{ gitea_ssl_cert }};
ssl_certificate_key {{ gitea_ssl_key }};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50M;
location / {
client_max_body_size 512M;
proxy_pass http://localhost:{{ gitea_http_port }};
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
{% if gitea_enable_http_redirect | default(true) %}
server {
listen 80;
server_name {{ gitea_domain }};
return 301 https://$host$request_uri;
}
{% endif %}
{% else %}
# HTTP-only configuration
server {
listen 80;
server_name {{ gitea_domain }};
client_max_body_size 50M;
location / {
client_max_body_size 512M;
proxy_pass http://localhost:{{ gitea_http_port }};
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
{% endif %}

View File

@@ -3,6 +3,10 @@
[Unit] [Unit]
Description=Gitea (Git with a cup of tea) Description=Gitea (Git with a cup of tea)
After=network.target After=network.target
{% if gitea_database_server | default('') == "postgresql" %}
Wants=postgresql.service
After=postgresql.service
{% endif %}
[Service] [Service]
RestartSec=2s RestartSec=2s