Compare commits

...

3 commits

Author SHA1 Message Date
Mathieu Gauthier-Pilote 1ea5401211 Gitea upgrade : v1.18.5 => v1.21.3
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |4831|5|4826|5|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/gitea/2//ansiblelint">Evolix » ansible-roles » gitea #2</a>
gitea/ansible-roles/pipeline/head This commit looks good
2024-01-10 14:33:19 -05:00
Mathieu Gauthier-Pilote 56abcb1778 Now installs a LE SSL cert via certbot by default
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |4831|40|4791|48|:+1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/gitea/1//ansiblelint">Evolix » ansible-roles » gitea #1</a>
gitea/ansible-roles/pipeline/head This commit looks good
2023-04-26 15:51:49 -04:00
Mathieu Gauthier-Pilote aad108d6c0 New role to install + upgrade Gitea
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |4839|0|4839|0|:zzz:
gitea/ansible-roles/pipeline/head This commit looks good
2023-03-10 10:43:44 -05:00
17 changed files with 528 additions and 0 deletions

49
webapps/gitea/LISEZMOI.md Normal file
View file

@ -0,0 +1,49 @@
gitea
=====
Ce rôle installe un serveur gitea.
Notez qu'hormis le présent fichier LISEZMOI.md, tous les fichiers du rôle gitea sont rédigés en anglais afin de suivre les conventions de la communauté Ansible, favoriser sa réutilisation et son amélioration, etc. Libre à vous cependant de faire appel à ce role dans un playbook rédigé principalement en français ou toute autre langue.
Requis
------
...
Variables du rôle
-----------------
Plusieurs des valeurs par défaut dans defaults/main.yml doivent être changées soit directement dans defaults/main.yml ou mieux encore en les supplantant ailleurs, par exemple dans votre playbook (voir l'exemple ci-bas).
Dépendances
------------
Ce rôle Ansible dépend des rôles suivants :
- nodejs
Exemple de playbook
-------------------
```
- name: "Déployer un serveur gitea"
hosts:
- all
vars:
# Supplanter ici les variables du rôle
domains: ['votre-vrai-domaine.org']
service: 'mon-gitea'
roles:
- { role: webapps/gitea , tags: "gitea" }
```
Licence
-------
GPLv3
Infos sur l'auteur
------------------
Mathieu Gauthier-Pilote, administrateur de systèmes chez Evolix.

49
webapps/gitea/README.md Normal file
View file

@ -0,0 +1,49 @@
gitea
=====
This role installs or upgrades the server for gitea.
FRENCH: Voir le fichier LISEZMOI.md pour le français.
Requirements
------------
...
Role Variables
--------------
Several of the default values in defaults/main.yml must be changed either directly in defaults/main.yml or better even by overwriting them somewhere else, for example in your playbook (see the example below).
Dependencies
------------
This Ansible role depends on the following other roles:
- nodejs
Example Playbook
----------------
```
- name: "Deploy an gitea server"
hosts:
- all
vars:
# Overwrite the role variable here
domains: ['your-real-domain.org']
service: 'my-gitea'
roles:
- { role: webapps/gitea , tags: "gitea" }
```
License
-------
GPLv3
Author Information
------------------
Mathieu Gauthier-Pilote, sys. admin. at Evolix.

View file

@ -0,0 +1,14 @@
---
# defaults file for vars
system_dep: "['apt-transport-https', 'git', 'nginx', 'mariadb-server', 'mariadb-client', 'python3-mysqldb', 'redis-server', 'certbot']"
git_version: '1.21.3'
gitea_url: "https://dl.gitea.io/gitea/{{ git_version }}/gitea-{{ git_version }}-linux-amd64"
gitea_checksum: "sha256:ccf6cc2077401e382bca0d000553a781a42c9103656bd33ef32bf093cca570eb"
domains: ['example.domain.org']
certbot_admin_email: 'security@example.domain.org'
db_host: '127.0.0.1:3306'
db_name: "{{ service }}"
db_user: "{{ service }}"
db_password: 'UQ6_CHANGE_ME_Gzb'
redis_maxclients: '128'
redis_maxmemory: '300M'

View file

@ -0,0 +1,2 @@
---
# handlers file

View file

@ -0,0 +1,52 @@
galaxy_info:
author: Mathieu Gauthier-Pilote
description: sys. admin.
company: Evolix
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license GPL-3.0-only
min_ansible_version: 2.10
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View file

@ -0,0 +1,165 @@
---
# tasks file for gitea install
- name: Install main system dependencies
apt:
name: "{{ system_dep }}"
update_cache: yes
- name: Download gitea binary
get_url:
url: "{{ gitea_url }}"
dest: /usr/local/bin
checksum: "{{ gitea_checksum }}"
mode: '0755'
- name: Create symbolic link
file:
src: "/usr/local/bin/gitea-{{ git_version }}-linux-amd64"
dest: "/usr/local/bin/gitea"
state: link
- name: Add UNIX account
user:
name: "{{ service }}"
shell: /bin/bash
- name: Add www-data (nginx) to service's group
user:
name: www-data
#group: www-data
groups: "{{ service }}"
append: true
- name: Add database
mysql_db:
name: "{{ db_name }}"
- name: Add database user
mysql_user:
name: "{{ db_user }}"
password: "{{ db_password }}"
priv: "{{ db_name }}.*:{{privileges |default('SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES')}}"
update_password: on_create
- name: Create the gitea conf dir if needed
file:
path: /etc/gitea
state: directory
mode: '0755'
- name: Template gitea ini file
template:
src: "gitea.ini.j2"
dest: "/etc/gitea/{{ service }}.ini"
owner: 'root'
group: "{{ service }}"
mode: '0660'
- name: Template gitea systemd unit
template:
src: "gitea.service.j2"
dest: "/etc/systemd/system/gitea@.service"
- name: Start gitea systemd unit
service:
name: "gitea@{{ service }}"
state: restarted
- name: Create the redis dir if needed
file:
path: /home/{{ service }}/redis
state: directory
owner: "{{ service }}"
group: "{{ service }}"
mode: '0750'
- name: Create the log dir if needed
file:
path: /home/{{ service }}/log
state: directory
owner: "{{ service }}"
group: "{{ service }}"
mode: '0750'
- name: Template redis conf
template:
src: "redis.conf.j2"
dest: "/home/{{ service }}/redis/redis.conf"
owner: "{{ service }}"
group: "{{ service }}"
mode: '0640'
- name: Template redis systemd unit
template:
src: "redis.service.j2"
dest: "/etc/systemd/system/redis@.service"
- name: Start redis systemd unit
service:
name: "redis@{{ service }}"
state: started
- name: Template nginx snippet for Let's Encrypt/Certbot
template:
src: "letsencrypt.conf.j2"
dest: "/etc/nginx/snippets/letsencrypt.conf"
- name: Check if SSL certificate is present and register result
stat:
path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem"
register: ssl
- name: Generate certificate only if required (first time)
block:
- name: Template vhost without SSL for successfull LE challengce
template:
src: "vhost.conf.j2"
dest: "/etc/nginx/sites-available/{{ service }}.conf"
- name: Enable temporary nginx vhost for gitea
file:
src: "/etc/nginx/sites-available/{{ service }}.conf"
dest: "/etc/nginx/sites-enabled/{{ service }}.conf"
state: link
- name: Reload nginx conf
service:
name: nginx
state: reloaded
- name: Make sure /var/lib/letsencrypt exists and has correct permissions
file:
path: /var/lib/letsencrypt
state: directory
mode: '0755'
- name: Generate certificate with certbot
shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ certbot_admin_email }} -d {{ domains |first }}
- name: Create the ssl dir if needed
file:
path: /etc/nginx/ssl
state: directory
mode: '0750'
- name: Template ssl bloc for nginx vhost
template:
src: "ssl.conf.j2"
dest: "/etc/nginx/ssl/{{ domains |first }}.conf"
when: ssl.stat.exists != true
- name: (Re)check if SSL certificate is present and register result
stat:
path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem"
register: ssl
- name: (Re)template conf file for nginx vhost with SSL
template:
src: "vhost.conf.j2"
dest: "/etc/nginx/sites-available/{{ service }}.conf"
- name: Enable nginx vhost for gitea
file:
src: "/etc/nginx/sites-available/{{ service }}.conf"
dest: "/etc/nginx/sites-enabled/{{ service }}.conf"
state: link
- name: Reload nginx conf
service:
name: nginx
state: reloaded

View file

@ -0,0 +1,26 @@
---
# tasks file for gitea upgrade
- name: Download gitea binary
get_url:
url: "{{ gitea_url }}"
dest: /usr/local/bin
checksum: "{{ gitea_checksum }}"
mode: '0755'
- name: Create symbolic link
file:
src: "/usr/local/bin/gitea-{{ git_version }}-linux-amd64"
dest: "/usr/local/bin/gitea"
state: link
- name: Start gitea systemd unit
service:
name: "gitea@{{ service }}"
state: restarted
- name: Reload nginx conf
service:
name: nginx
state: reloaded

View file

@ -0,0 +1,39 @@
APP_NAME = Gitea
RUN_USER = {{ service }}
RUN_MODE = prod
[server]
PROTOCOL = unix
DOMAIN = {{ domains | first }}
HTTP_ADDR = /home/{{ service }}/gitea.sock
UNIX_SOCKET_PERMISSION = 660
OFFLINE_MODE = true
SSH_DOMAIN = {{ domains | first }}
ROOT_URL = https://{{ domains | first }}/
[repository]
ROOT = /home/{{ service }}/repositories
[log]
ROOT_PATH = /home/{{ service }}/log/
MODE = console
LEVEL = info
[i18n]
LANGS = fr-FR, en-US
NAMES = Français,English
[database]
DB_TYPE = mysql
HOST = {{ db_host }}
NAME = {{ db_name }}
USER = {{ db_user }}
PASSWD = {{ db_password }}
[session]
PROVIDER = redis
PROVIDER_CONFIG = network=unix,addr=/home/{{ service }}/redis/redis.sock,db=0,pool_size=100,idle_timeout=180
[cache]
ADAPTER = redis
HOST = network=unix,addr=/home/{{ service }}/redis/redis.sock,db=1,pool_size=100,idle_timeout=180

View file

@ -0,0 +1,22 @@
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=mysqld.service
[Service]
User=%i
Group=%i
Type=simple
RestartSec=2s
Restart=always
WorkingDirectory=/home/%i
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/%i.ini
Environment=GITEA_WORK_DIR=/home/%i/internals
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,5 @@
location ~ /.well-known/acme-challenge {
alias /var/lib/letsencrypt/;
try_files $uri =404;
allow all;
}

View file

@ -0,0 +1,22 @@
bind 127.0.0.1 ::1
protected-mode yes
port 0
unixsocket /home/{{ service }}/redis/redis.sock
unixsocketperm 770
timeout 0
tcp-keepalive 300
loglevel notice
logfile /home/{{ service }}/log/redis-server.log
databases 16
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /home/{{ service }}/redis
maxclients {{ redis_maxclients }}
maxmemory {{ redis_maxmemory }}

View file

@ -0,0 +1,14 @@
[Unit]
Description=Advanced key-value store
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/redis-server /home/%i/redis/redis.conf
TimeoutStopSec=0
Restart=always
User=%i
Group=%i
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,22 @@
##
# Certificates
# you need a certificate to run in production. see https://letsencrypt.org/
##
ssl_certificate /etc/letsencrypt/live/{{ domains | first }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domains | first }}/privkey.pem;
##
# Security hardening (as of Nov 15, 2020)
# based on Mozilla Guideline v5.6
##
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; # add ECDHE-RSA-AES256-SHA if you want compatibility with Android 4
ssl_session_timeout 1d; # defaults to 5m
ssl_session_cache shared:SSL:10m; # estimated to 40k sessions
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
# HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives
#add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";

View file

@ -0,0 +1,38 @@
upstream gitea_{{ service }} {
server unix:/home/{{ service }}/gitea.sock;
}
server {
listen 80;
listen [::]:80;
server_name {{ domains | first }};
# For certbot
include /etc/nginx/snippets/letsencrypt.conf;
{% if ssl.stat.exists %}
location / { return 301 https://$host$request_uri; }
{% endif %}
}
{% if ssl.stat.exists %}
server {
listen 0.0.0.0:443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ domains | first }};
access_log /var/log/nginx/{{ service }}.access.log;
error_log /var/log/nginx/{{ service }}.error.log;
include /etc/nginx/snippets/letsencrypt.conf;
include /etc/nginx/ssl/{{ domains | first }}.conf;
location / {
proxy_pass http://gitea_{{ service }};
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 10;
}
}
{% endif %}

View file

@ -0,0 +1,2 @@
localhost

View file

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- privatebin

View file

@ -0,0 +1,2 @@
---
# vars file