gitea: set custom avatars for orgs
Over a few upgrades, we've managed to break some of the default avatar logos you see when browsing code on opendev.org. After investigating ways to fix this up, we established that there isn't an exposed API for setting these, but we can do a simple query to point to logo files on disk. This implements that. One caveat is that the logos should be PNG files; particiularly we note that SVG files don't work reliably because they don't get served with the image/svg+xml mime-type. Change-Id: Ie6799de2fb27e09f936c488258dc1bd1c638c370
This commit is contained in:
parent
e9e63f1d52
commit
2d9c8b620f
playbooks/roles
gitea-git-repos/tasks
gitea-set-org-logos
testinfra
@ -6,3 +6,7 @@
|
|||||||
# Lookup runs locally on the calling machine, so doesn't need
|
# Lookup runs locally on the calling machine, so doesn't need
|
||||||
# project-config remotely
|
# project-config remotely
|
||||||
projects: "{{ lookup('file', project_config_src + '/gerrit/projects.yaml') | from_yaml }}"
|
projects: "{{ lookup('file', project_config_src + '/gerrit/projects.yaml') | from_yaml }}"
|
||||||
|
|
||||||
|
- name: Setup logos
|
||||||
|
include_role:
|
||||||
|
name: gitea-set-org-logos
|
||||||
|
7
playbooks/roles/gitea-set-org-logos/README.rst
Normal file
7
playbooks/roles/gitea-set-org-logos/README.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Set custom logos for organisations in gitea
|
||||||
|
|
||||||
|
Note that logos should be a PNG file. We've standardised on a 400x400
|
||||||
|
to keep it simple.
|
||||||
|
|
||||||
|
Images should respect the limits set by gitea; see
|
||||||
|
`<https://docs.gitea.io/en-us/config-cheat-sheet/#picture-picture>`_
|
BIN
playbooks/roles/gitea-set-org-logos/files/airship.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/airship.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 25 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/default.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/default.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 10 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/opendev.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/opendev.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 10 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/openstack.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/openstack.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 5.2 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/starlingx.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/starlingx.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 18 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/vexxhost.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/vexxhost.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 4.1 KiB |
BIN
playbooks/roles/gitea-set-org-logos/files/zuul.png
Normal file
BIN
playbooks/roles/gitea-set-org-logos/files/zuul.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 6.2 KiB |
48
playbooks/roles/gitea-set-org-logos/tasks/main.yaml
Normal file
48
playbooks/roles/gitea-set-org-logos/tasks/main.yaml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
- name: Get list of orgs
|
||||||
|
uri:
|
||||||
|
url: 'https://localhost:3000/api/v1/orgs'
|
||||||
|
method: GET
|
||||||
|
user: root
|
||||||
|
password: '{{ gitea_root_password }}'
|
||||||
|
return_content: yes
|
||||||
|
validate_certs: false
|
||||||
|
status_code: 200
|
||||||
|
body_format: json
|
||||||
|
register: _org_list_raw
|
||||||
|
no_log: True
|
||||||
|
|
||||||
|
- name: Filter org list
|
||||||
|
set_fact:
|
||||||
|
_org_list: '{{ _org_list_raw.json | map(attribute="username") | list }}'
|
||||||
|
|
||||||
|
- name: Copy org logos
|
||||||
|
copy:
|
||||||
|
src: '{{ lookup("first_found", _org_logos) }}'
|
||||||
|
dest: '/var/gitea/data/gitea/avatars/{{ item }}'
|
||||||
|
owner: 1000
|
||||||
|
group: 1000
|
||||||
|
mode: 0644
|
||||||
|
vars:
|
||||||
|
_org_logos:
|
||||||
|
- '{{ item }}.png'
|
||||||
|
- 'default.png'
|
||||||
|
loop: '{{ _org_list }}'
|
||||||
|
register: _logos_updated
|
||||||
|
|
||||||
|
- name: Get changed logos
|
||||||
|
set_fact:
|
||||||
|
_changed_logos: '{{ _logos_updated.results | selectattr("changed", "equalto", true) | map(attribute="item") | list }}'
|
||||||
|
|
||||||
|
# NOTE(ianw) 2022-03-17 There is currently no API to update avatar
|
||||||
|
# logos with gitea, so we direct update for now.
|
||||||
|
# * orgs are just entries in the "users" table
|
||||||
|
# * the "avatar" field is a plain-text name of a file in
|
||||||
|
# /var/gitea/data/gitea/avatars
|
||||||
|
- name: Run update query
|
||||||
|
shell: >-
|
||||||
|
/usr/local/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml
|
||||||
|
exec mariadb bash -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e
|
||||||
|
"USE gitea; UPDATE user SET avatar = '\''{{ item }}'\'', use_custom_avatar = 1 WHERE name = '\''{{ item }}'\''"'
|
||||||
|
args:
|
||||||
|
executable: '/bin/bash'
|
||||||
|
loop: '{{ _changed_logos }}'
|
@ -93,7 +93,12 @@ def test_gitea_screenshots(host):
|
|||||||
('https://localhost:3081/opendev/system-config', None,
|
('https://localhost:3081/opendev/system-config', None,
|
||||||
'gitea-project-system-config.png'),
|
'gitea-project-system-config.png'),
|
||||||
('https://localhost:3081/opendev/disk-image-builder', None,
|
('https://localhost:3081/opendev/disk-image-builder', None,
|
||||||
'gitea-project-dib.png')
|
'gitea-project-dib.png'),
|
||||||
|
('https://localhost:3081/opendev/', None,
|
||||||
|
'gitea-org-opendev.png'),
|
||||||
|
('https://localhost:3081/explore/organizations', None,
|
||||||
|
'gitea-org-expore.png'),
|
||||||
)
|
)
|
||||||
|
|
||||||
take_screenshots(host, shots)
|
take_screenshots(host, shots)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user