diff --git a/README.md b/README.md index 52d32dc..3be6535 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Role Variables The most important variables are listed below: ``` yaml -gitea_version: 1.11.3 +gitea_version: 1.14.2 gitea_local_postgresql: True gitea_local_mysql: False gitea_local_mariadb: False @@ -23,6 +23,20 @@ gitea_app_configurations: - { section: 'mailer', option: 'SENDMAIL_PATH', value: '{{ gitea_sendmail_path }}', state: 'present' } - { section: 'metrics', option: 'ENABLED', value: 'true', state: 'present' } - { section: 'metrics', option: 'TOKEN', value: '{{ gitea_prometheus_bearer_token }}', state: 'present' } +gitea_install_viewer_addons: True +gitea_addons_deb_packages: + - jupyter + - asciidoctor + - pandoc + +gitea_markup_asciidoc_enabled: True +gitea_markup_jupyter_enabled: True +gitea_markup_restructuredtext_enabled: True +gitea_markup_sanitizer_tex_enabled: True +gitea_markup_markdown_enabled: True +gitea_prometheus_metrics: False +gitea_prometheus_bearer_token: 'Use a vault' +gitea_log_level: Info ``` Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 2d1fe4e..2a5557a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -66,6 +66,18 @@ gitea_session_config: 'network=tcp,addr=127.0.0.1:6379,db=0,pool_size=100,idle_t gitea_require_signin_view: 'false' gitea_users_page_enabled: 'false' +gitea_install_viewer_addons: True +gitea_addons_deb_packages: + - jupyter + - asciidoctor + - pandoc + +gitea_markup_asciidoc_enabled: True +gitea_markup_jupyter_enabled: True +gitea_markup_restructuredtext_enabled: True +gitea_markup_sanitizer_tex_enabled: True +gitea_markup_markdown_enabled: True + gitea_prometheus_metrics: False #gitea_prometheus_bearer_token: put it into a vault file gitea_prometheus_bearer_token: '' diff --git a/meta/main.yml b/meta/main.yml index 84d76cf..92400ca 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -16,13 +16,9 @@ galaxy_info: - name: Ubuntu versions: - bionic - - name: EL - versions: - - 7 - - 8 galaxy_tags: - - users + - git dependencies: - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-postgresql.git diff --git a/tasks/deb-addons.yml b/tasks/deb-addons.yml new file mode 100644 index 0000000..02fddef --- /dev/null +++ b/tasks/deb-addons.yml @@ -0,0 +1,10 @@ +--- +- name: + block: Install the packages required by the gitea viewers + - name: + apt: + pkg: '{{ gitea_addons_deb_packages }}' + state: present + cache_valid_time: 1800 + + tags: [ 'git', 'gitea', 'gitea_addons' ] diff --git a/tasks/gitea.yml b/tasks/gitea.yml new file mode 100644 index 0000000..b1dc276 --- /dev/null +++ b/tasks/gitea.yml @@ -0,0 +1,54 @@ +--- +- block: + - name: Create the gitea service user + user: name={{ gitea_user }} home=/srv/gitea createhome=yes shell=/bin/bash system=yes + + - name: Create the gitea directory tree + file: dest={{ gitea_data_dir }}/{{ item }} state=directory owner={{ gitea_user }} group={{ gitea_group }} + with_items: '{{ gitea_data_subdirs }}' + + - name: Create the gitea conf directory + file: dest={{ gitea_conf_dir }} state=directory owner=root group={{ gitea_group }} mode=0750 + + - name: Download the gitea binary + get_url: url={{ gitea_download_url }} dest={{ gitea_bin_path }} owner=root group={{ gitea_group }} mode=0750 + + - name: Install the required packages + package: state=present use=auto name={{ gitea_required_packages }} + + - name: Check if the gitea configuration file exists + stat: path={{ gitea_conf_dir }}/app.ini + register: gitea_app_ini + + - name: Change the gitea configuration. After the installation + ini_file: + path: '{{ gitea_conf_dir }}/app.ini section={{ item.section }}' + option: '{{ item.option }}' + value: '{{ item.value }}' + state: '{{ item.state }}' + owner: '{{ gitea_user }}' + group: '{{ gitea_group }}' + mode: '0640' + create: no + with_items: '{{ gitea_app_configurations }}' + when: + - gitea_app_ini.stat.exists + - gitea_app_configurations is defined + notify: restart gitea + + - name: Install the gitea configuration file. At install time only + template: src=app.ini.j2 dest={{ gitea_conf_dir }}/app.ini owner={{ gitea_user }} group={{ gitea_group }} mode=0640 force=no + notify: restart gitea + + - name: Install the gitea systemd unit + template: src=gitea.service.systemd dest=/etc/systemd/system/gitea.service + register: gitea_systemd_unit + + - name: Reload the systemd configuration + command: systemctl daemon-reload + when: gitea_systemd_unit is changed + + - name: Ensure that the gitea service is running and enabled + service: name=gitea state=started enabled=yes + + tags: [ 'git', 'gitea' ] diff --git a/tasks/main.yml b/tasks/main.yml index b1dc276..b145df7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,54 +1,4 @@ --- -- block: - - name: Create the gitea service user - user: name={{ gitea_user }} home=/srv/gitea createhome=yes shell=/bin/bash system=yes - - - name: Create the gitea directory tree - file: dest={{ gitea_data_dir }}/{{ item }} state=directory owner={{ gitea_user }} group={{ gitea_group }} - with_items: '{{ gitea_data_subdirs }}' - - - name: Create the gitea conf directory - file: dest={{ gitea_conf_dir }} state=directory owner=root group={{ gitea_group }} mode=0750 - - - name: Download the gitea binary - get_url: url={{ gitea_download_url }} dest={{ gitea_bin_path }} owner=root group={{ gitea_group }} mode=0750 - - - name: Install the required packages - package: state=present use=auto name={{ gitea_required_packages }} - - - name: Check if the gitea configuration file exists - stat: path={{ gitea_conf_dir }}/app.ini - register: gitea_app_ini - - - name: Change the gitea configuration. After the installation - ini_file: - path: '{{ gitea_conf_dir }}/app.ini section={{ item.section }}' - option: '{{ item.option }}' - value: '{{ item.value }}' - state: '{{ item.state }}' - owner: '{{ gitea_user }}' - group: '{{ gitea_group }}' - mode: '0640' - create: no - with_items: '{{ gitea_app_configurations }}' - when: - - gitea_app_ini.stat.exists - - gitea_app_configurations is defined - notify: restart gitea - - - name: Install the gitea configuration file. At install time only - template: src=app.ini.j2 dest={{ gitea_conf_dir }}/app.ini owner={{ gitea_user }} group={{ gitea_group }} mode=0640 force=no - notify: restart gitea - - - name: Install the gitea systemd unit - template: src=gitea.service.systemd dest=/etc/systemd/system/gitea.service - register: gitea_systemd_unit - - - name: Reload the systemd configuration - command: systemctl daemon-reload - when: gitea_systemd_unit is changed - - - name: Ensure that the gitea service is running and enabled - service: name=gitea state=started enabled=yes - - tags: [ 'git', 'gitea' ] +- import_tasks: gitea.yml +- import_tasks: deb-addons.yml + when: ansible_distribution_file_variety == "Debian" diff --git a/templates/app.ini.j2 b/templates/app.ini.j2 index 11c3388..cc050a6 100644 --- a/templates/app.ini.j2 +++ b/templates/app.ini.j2 @@ -61,6 +61,49 @@ ENABLED = true TOKEN = '{{ gitea_prometheus_bearer_token }}' {% endif %} +{% if gitea_install_viewer_addons %} +{% if gitea_markup_asciidoc_enabled %} +[markup.asciidoc] +ENABLED = true +FILE_EXTENSIONS = .adoc,.asciidoc +RENDER_COMMAND = "asciidoctor -s -a showtitle --out-file=- -" +; Input is not a standard input but a file +IS_INPUT_FILE = false +{%endif %} + +{% if gitea_markup_jupyter_enabled %} +[markup.jupyter] +ENABLED = true +FILE_EXTENSIONS = .ipynb +RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template basic " +IS_INPUT_FILE = true +{%endif %} + +{% if gitea_markup_restructuredtext_enabled %} +[markup.restructuredtext] +ENABLED = true +FILE_EXTENSIONS = .rst +RENDER_COMMAND = "timeout 30s pandoc +RTS -M512M -RTS -f rst" +IS_INPUT_FILE = false +{%endif %} + +{% if gitea_markup_sanitizer_tex_enabled %} +[markup.sanitizer.TeX] +; Pandoc renders TeX segments as s with the "math" class, optionally +; with "inline" or "display" classes depending on context. +ELEMENT = span +ALLOW_ATTR = class +REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+ +{%endif %} + +{% if gitea_markup_markdown_enabled %} +[markup.markdown] +ENABLED = true +FILE_EXTENSIONS = .md,.markdown +RENDER_COMMAND = pandoc -f markdown -t html --katex +{%endif %} +{%endif %} + [other] SHOW_FOOTER_VERSION = false SHOW_FOOTER_TEMPLATE_LOAD_TIME = false