From e27ef2770618f9f3b131646209e76437d25dbcd4 Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 3 Jun 2021 17:59:14 +0200 Subject: [PATCH] implement custom logos --- README.md | 17 +++++++++++++ defaults/main.yml | 5 ++++ tasks/customize_logo.yml | 52 ++++++++++++++++++++++++++++++++++++++ tasks/directory.yml | 6 ++--- tasks/main.yml | 4 +++ templates/gitea.service.j2 | 2 +- vars/main.yml | 30 +++++++++++++++++++++- 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 tasks/customize_logo.yml diff --git a/README.md b/README.md index 2efaf39..e91afbd 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,23 @@ As this will only deploy config files, fail2ban already has to be installed or o | `gitea_fail2ban_jail_bantime` | `900` | fail2ban jail `bantime` setting. | | `gitea_fail2ban_jail_action` | `iptables-allports` | fail2ban jail `action` setting. | +### optional customisation +You can optionally customize your gitea using this ansible role. We got our information about customisation from [docs.gitea.io/en-us/customizing-gitea](https://docs.gitea.io/en-us/customizing-gitea/). +To deploy multiple files we created the ``gitea_custom_search`` variable, that can point to the path where you put the custom gitea files *( default ``"files/host_files/{{ inventory_hostname }}/gitea"``. + ++ LOGO + - Set ``gitea_customize_logo`` to ``true`` + - We search for: + * ``logo.svg`` - Used for favicon, site icon, app icon + * ``logo.png`` - Used for Open Graph + * ``favicon.png`` - Used as fallback for browsers that don’t support SVG favicons + * ``apple-touch-icon.png`` - Used on iOS devices for bookmarks + - We search in *(using [first_found](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/first_found_lookup.html))*: + * ``{{ gitea_custom_search }}/gitea_logo/`` + * ``files/{{ inventory_hostname }}/gitea_logo/`` + * ``files/{{ gitea_http_domain }}/gitea_logo/`` + * ``files/gitea_logo/`` + ## Contributing Don't hesitate to create a pull request, and when in doubt you can reach me on Mastodon [@l3d@chaos.social](https://chaos.social/@l3d). diff --git a/defaults/main.yml b/defaults/main.yml index fc2e6fa..cddd8cf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -146,3 +146,8 @@ gitea_fail2ban_jail_maxretry: '10' gitea_fail2ban_jail_findtime: '3600' gitea_fail2ban_jail_bantime: '900' gitea_fail2ban_jail_action: 'iptables-allports' + +# gitea customisation +gitea_custom_search: "files/host_files/{{ inventory_hostname }}/gitea" +gitea_customize_logo: false +gitea_custom: "{{ gitea_home }}/custom" diff --git a/tasks/customize_logo.yml b/tasks/customize_logo.yml new file mode 100644 index 0000000..eb344a8 --- /dev/null +++ b/tasks/customize_logo.yml @@ -0,0 +1,52 @@ +--- +- name: create directory for custom logos + become: true + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: 'u=rwX,g=rX,o=' + with_items: + - "{{ gitea_custom }}/public" + - "{{ gitea_custom }}/public/img" + +- name: transfer custom logo.svg + become: true + ansible.builtin.copy: + src: "{{ lookup('first_found', transfer_custom_logo_logosvg) }}" + dest: "{{ gitea_custom }}/public/img/logo.svg" + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: '0644' + ignore_errors: true + +- name: transfer custom logo.png + become: true + ansible.builtin.copy: + src: "{{ lookup('first_found', transfer_custom_logo_logopng) }}" + dest: "{{ gitea_custom }}/public/img/logo.png" + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: '0644' + ignore_errors: true + +- name: transfer custom favicon.png + become: true + ansible.builtin.copy: + src: "{{ lookup('first_found', transfer_custom_logo_faviconpng) }}" + dest: "{{ gitea_custom }}/public/img/favicon.png" + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: '0644' + ignore_errors: true + +- name: transfer custom apple-touch-icon.png + become: true + ansible.builtin.copy: + src: "{{ lookup('first_found', transfer_custom_logo_appletouchiconpng) }}" + dest: "{{ gitea_custom }}/public/img/apple-touch-icon.png" + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: '0644' + ignore_errors: true diff --git a/tasks/directory.yml b/tasks/directory.yml index 2a42b6a..6d4b291 100644 --- a/tasks/directory.yml +++ b/tasks/directory.yml @@ -11,9 +11,9 @@ - "/etc/gitea" - "{{ gitea_home }}" - "{{ gitea_home }}/data" - - "{{ gitea_home }}/custom" - - "{{ gitea_home }}/custom/https" - - "{{ gitea_home }}/custom/mailer" + - "{{ gitea_custom }}" + - "{{ gitea_custom }}/https" + - "{{ gitea_custom }}/mailer" - "{{ gitea_home }}/indexers" - "{{ gitea_home }}/log" - "{{ gitea_repository_root }}" diff --git a/tasks/main.yml b/tasks/main.yml index 461d49d..cd78226 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -48,3 +48,7 @@ - name: deploy optional fail2ban rules ansible.builtin.include_tasks: fail2ban.yml when: gitea_fail2ban_enabled|bool + +- name: optionally customize gitea + ansible.builtin.include_tasks: customize_logo.yml + when: gitea_customize_logo|bool diff --git a/templates/gitea.service.j2 b/templates/gitea.service.j2 index 3434766..ebdf810 100644 --- a/templates/gitea.service.j2 +++ b/templates/gitea.service.j2 @@ -5,7 +5,7 @@ After=network.target [Service] User={{ gitea_user }} Group={{ gitea_group }} -ExecStart=/usr/local/bin/gitea web -c /etc/gitea/gitea.ini --custom-path {{ gitea_home }}/custom/ +ExecStart=/usr/local/bin/gitea web -c /etc/gitea/gitea.ini --custom-path {{ gitea_custom }}/ Restart=on-failure WorkingDirectory={{ gitea_home }} {% if gitea_systemd_cap_net_bind_service %} diff --git a/vars/main.yml b/vars/main.yml index 53c40f5..c223ce1 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -20,5 +20,33 @@ gitea_variables: paths: - 'vars' -playbook_version_number: 15 # should be int +transfer_custom_logo_logosvg: + files: + - "{{ gitea_custom_search }}/gitea_logo/logo.svg" + - "files/{{ inventory_hostname }}/gitea_logo/logo.svg" + - "files/{{ gitea_http_domain }}/gitea_logo/logo.svg" + - 'files/gitea_logo/logo.svg' + +transfer_custom_logo_logopng: + files: + - "{{ gitea_custom_search }}/gitea_logo/logo.png" + - "files/{{ inventory_hostname }}/gitea_logo/logo.png" + - "files/{{ gitea_http_domain }}/gitea_logo/logo.png" + - 'files/gitea_logo/logo.png' + +transfer_custom_logo_faviconpng: + files: + - "{{ gitea_custom_search }}/gitea_logo/favicon.png" + - "files/{{ inventory_hostname }}/gitea_logo/favicon.png" + - "files/{{ gitea_http_domain }}/gitea_logo/favicon.png" + - 'files/gitea_logo/favicon.png' + +transfer_custom_logo_appletouchiconpng: + files: + - "{{ gitea_custom_search }}/gitea_logo/apple-touch-icon.png" + - "files/{{ inventory_hostname }}/gitea_logo/apple-touch-icon.png" + - "files/{{ gitea_http_domain }}/gitea_logo/apple-touch-icon.png" + - 'files/gitea_logo/apple-touch-icon.png' + +playbook_version_number: 16 # should be int playbook_version_path: 'do1jlr.gitea.version'