From fdd5293dd05890434c5b1660bfc44d493a4f4056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Sun, 12 May 2024 17:33:39 +0200 Subject: feat(roles/cgit): new variables structure --- roles/cgit/defaults/main.yml | 45 ++++++++++++------------ roles/cgit/files/generate-static-git.sh | 28 --------------- roles/cgit/files/httpd.conf | 6 ++-- roles/cgit/meta/main.yml | 61 ++++++++++----------------------- roles/cgit/tasks/main.yml | 37 ++++++++++---------- roles/cgit/templates/cgitrc.j2 | 44 ++++++++++++------------ roles/cgit/templates/httpd.conf.j2 | 4 +-- 7 files changed, 87 insertions(+), 138 deletions(-) delete mode 100644 roles/cgit/files/generate-static-git.sh (limited to 'roles') diff --git a/roles/cgit/defaults/main.yml b/roles/cgit/defaults/main.yml index 503b20b..adf7a97 100644 --- a/roles/cgit/defaults/main.yml +++ b/roles/cgit/defaults/main.yml @@ -1,30 +1,31 @@ --- -cgit_git_dir: /data/git -cgit_cache_size: 10 -cgit_cache_dir: /cache/cgit +cgit__packages: + - cgit + - lowdown -cgit_chroot_dir: /var/www -cgit_chroot_required_files: +cgit__user: "{{ httpd_pre__user }}" +cgit__group: "{{ httpd_pre__group }}" + +cgit__chroot_dir: "{{ httpd_pre__chroot_dir }}" +cgit__cache_dir: "{{ cgit__chroot_dir }}/cache/cgit" +cgit__repositories_dir: "{{ cgit__chroot_dir }}/data/cgit" +cgit__configuration_dir: "{{ cgit__chroot_dir }}/cgit" +cgit__configuration_file: "{{ cgit__configuration_dir }}/cgitrc" +cgit__footer_file: "{{ cgit__configuration_dir }}/footer.html" + +cgit__chroot_required_files: - /bin/sh - /bin/cat - /usr/local/bin/lowdown -cgit_user: www -cgit_group: www - -cgit_listen_address: 0.0.0.0 -cgit_listen_port: 1235 -cgit_footer_path: /conf/footer.html - -cgit_clone_urls: - - git://{{ cgit_domain_name }}/$CGIT_REPO_URL - - ssh://{{ git_user }}@{{ cgit_domain_name }}/$CGIT_REPO_URL - - https://{{ cgit_domain_name }}/$CGIT_REPO_URL +cgit__cache_size: 10 -cgit_domain_name: "" -cgit_favicon_url: "" -cgit_logo_url: "" -cgit_css_url: "" -cgit_description: "" -cgit_readme_url: "" +cgit__clone_urls: [] +cgit__title: "" +cgit__favicon_url: "" +cgit__logo_url: "" +cgit__css_url: "" +cgit__description: "" +cgit__readme_url: "" +cgit__listen_address: localhost diff --git a/roles/cgit/files/generate-static-git.sh b/roles/cgit/files/generate-static-git.sh deleted file mode 100644 index dd0db32..0000000 --- a/roles/cgit/files/generate-static-git.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -GIT_DIR="/data/git" - -repositories="" -repo="" - -for repo in "${GIT_DIR}"/*; do - - if [ ! -f "${repo}/git-daemon-export-ok" ]; then - echo " [ERR] $(basename ${repo})" - continue - fi - - repo=$(basename "${repo}") - repositories="${repositories} ${GIT_DIR}/${repo}" - - echo " [OK ] ${repo}" - mkdir "${repo}" 2>/dev/null - (cd "${repo}" && /usr/local/bin/stagit "${GIT_DIR}/${repo}") -done - -if [ -z "$repositories" ]; then - exit 1 -fi - -echo " [#] ${repositories}" -/usr/local/bin/stagit-index ${repositories} > index.html diff --git a/roles/cgit/files/httpd.conf b/roles/cgit/files/httpd.conf index 238acf0..313776e 100644 --- a/roles/cgit/files/httpd.conf +++ b/roles/cgit/files/httpd.conf @@ -1,9 +1,7 @@ - -# httpd ~~ /etc/httpd.conf # managed by Ansible -server "default" { - listen on * port 1234 +server "{{ cgit__domain_name }}" { + listen on * port {{ cgit__listen_port }} root "/htdocs/stagit" location match "style.css" { diff --git a/roles/cgit/meta/main.yml b/roles/cgit/meta/main.yml index 1efbc4b..9f84586 100644 --- a/roles/cgit/meta/main.yml +++ b/roles/cgit/meta/main.yml @@ -1,76 +1,53 @@ --- dependencies: - - role: git - - role: httpd__pre + - role: httpd_pre argument_specs: main: short_description: cgit main entrypoint. options: - - cgit_git_dir: + cgit__repositories_dir: type: path required: true - description: Git directory - - cgit_chroot_dir: + cgit__chroot_dir: type: path required: true - description: Chroot directory for web service - - cgit_user: + cgit__user: type: str required: true - description: Cgit web service user - - cgit_group: + cgit__group: type: str required: true - description: Cgit web service group - - cgit_domain_name: + cgit__domain_name: type: str required: true - description: Cgit domain name - - cgit_clone_urls: + cgit__title: + type: str + required: true + cgit__clone_urls: type: list elements: str requiredi: true - description: Available urls for cloning a repository - - cgit_cache_size: + cgit__cache_size: type: int required: true - description: Cgit cache size - - cgit_cache_dir: + cgit__cache_dir: type: path required: true - description: Cgit cache directory - - cgit_chroot_required_files: + cgit__chroot_required_files: type: list elements: str required: true - description: Files to be copied in cgit chroot - - cgit_favicon_url: + cgit__favicon_url: type: str - description: Favicon url - cgit_logo_url: + cgit__logo_url: type: str - description: Logo url - cgit_css_url: + cgit__css_url: type: str - description: Stylesheet url - cgit_description: + cgit__description: type: str - description: Instance description - cgit_readme_url: + cgit__readme_url: type: str - description: Instance readme url - cgit_footer_path: + cgit__footer_file: type: str - description: Footer path diff --git a/roles/cgit/tasks/main.yml b/roles/cgit/tasks/main.yml index ce9ecbe..5e0a0a3 100644 --- a/roles/cgit/tasks/main.yml +++ b/roles/cgit/tasks/main.yml @@ -2,18 +2,19 @@ - name: install cgit packages ansible.builtin.package: - name: - - cgit - - lowdown + name: "{{ cgit__packages }}" state: present -- name: create cgit cache directory +- name: create cgit data directories ansible.builtin.file: - path: "{{ cgit_chroot_dir }}/{{ cgit_cache_dir }}" - owner: "{{ cgit_user }}" - group: "{{ cgit_group }}" + path: "{{ item }}" + owner: "{{ cgit__user }}" + group: "{{ cgit__group }}" mode: "0750" state: directory + loop: + - "{{ cgit__cache_dir }}" + - "{{ cgit__repositories_dir }}" - name: generate cgit configuration files ansible.builtin.template: @@ -24,48 +25,48 @@ mode: "0644" loop: - src: cgitrc.j2 - dest: "{{ cgit_chroot_dir }}/conf/cgitrc" + dest: "{{ cgit__chroot_dir }}/conf/cgitrc" - src: footer.html.j2 - dest: "{{ cgit_chroot_dir }}/conf/footer.html" + dest: "{{ cgit__footer_file }}" - src: httpd.conf.j2 - dest: /etc/httpd.d/cgit.conf + dest: "{{ httpd_pre__configuration_dir }}/cgit.conf" - name: retrieve dependencies for lowdown ansible.builtin.shell: | set -o pipefail ldd $(command -v lowdown) | tr -s " " | grep "0 1 0" | cut -d " " -f 7 - register: cgit_result_lowdown_dependencies + register: cgit__result_lowdown_dependencies changed_when: false - name: create dependencies directories in chroot ansible.builtin.file: - path: "{{ cgit_chroot_dir }}{{ item | dirname }}" + path: "{{ cgit__chroot_dir }}{{ item | dirname }}" owner: 0 group: 0 mode: "0755" state: directory - loop: "{{ cgit_result_lowdown_dependencies.stdout_lines }}" + loop: "{{ cgit__result_lowdown_dependencies.stdout_lines }}" - name: copy dependencies for lowdown ansible.builtin.copy: src: "{{ item }}" - dest: "{{ cgit_chroot_dir }}/{{ item }}" + dest: "{{ cgit__chroot_dir }}/{{ item }}" mode: preserve remote_src: true - loop: "{{ cgit_result_lowdown_dependencies.stdout_lines }}" + loop: "{{ cgit__result_lowdown_dependencies.stdout_lines }}" - name: copy utilities in httpd chroot ansible.builtin.copy: src: "{{ item }}" - dest: "{{ cgit_chroot_dir }}/bin" + dest: "{{ cgit__chroot_dir }}/bin" mode: preserve remote_src: true - loop: "{{ cgit_chroot_required_files }}" + loop: "{{ cgit__chroot_required_files }}" - name: copy about-filter generator ansible.builtin.copy: src: about-filter.sh - dest: "{{ cgit_chroot_dir }}/bin/about-filter.sh" + dest: "{{ cgit__chroot_dir }}/bin/about-filter.sh" owner: 0 group: 0 mode: "0755" diff --git a/roles/cgit/templates/cgitrc.j2 b/roles/cgit/templates/cgitrc.j2 index 4c139d4..6e8965a 100644 --- a/roles/cgit/templates/cgitrc.j2 +++ b/roles/cgit/templates/cgitrc.j2 @@ -1,9 +1,5 @@ # managed by Ansible -# cache -cache-root={{ cgit_cache_dir }} -cache-size={{ cgit_cache_size }} - # readme readme=:README.md readme=:README.org @@ -12,6 +8,15 @@ readme=:.README.md readme=:.README about-filter=/bin/about-filter.sh +# mimetypes +mimetype.gif=image/gif +mimetype.html=text/html +mimetype.jpg=image/jpeg +mimetype.jpeg=image/jpeg +mimetype.pdf=application/pdf +mimetype.png=image/png +mimetype.svg=image/svg+xml + # features enable-commit-graph=1 enable-http-clone=1 @@ -24,19 +29,23 @@ max-stats=quarter robots=noindex, nofollow localtime=1 +# cache +cache-root={{ cgit__cache_dir | replace(cgit__chroot_dir, '') }} +cache-size={{ cgit__cache_size }} + # git -clone-url={{ cgit_clone_urls | join(' ') }} +clone-url={{ cgit__clone_urls | join(' ') }} # instance id -root-title={{ cgit_domain_name }} -root-desc={{ cgit_description }} -root-readme={{ cgit_readme_url }} +root-title={{ cgit__title }} +root-desc={{ cgit__description }} +root-readme={{ cgit__readme_url }} # visuals -css={{ cgit_css_url }} -logo={{ cgit_logo_url }} -favicon={{ cgit_favicon_url }} -footer={{ cgit_footer_path }} +css={{ cgit__css_url }} +logo={{ cgit__logo_url }} +favicon={{ cgit__favicon_url }} +footer={{ cgit__footer_file | replace(cgit__chroot_dir, '') }} # archives snapshots=tar.gz @@ -44,13 +53,4 @@ snapshots=tar.gz # sections section-from-path=1 section-sort=1 -scan-path={{ cgit_git_dir }} - -# mimetypes -mimetype.gif=image/gif -mimetype.html=text/html -mimetype.jpg=image/jpeg -mimetype.jpeg=image/jpeg -mimetype.pdf=application/pdf -mimetype.png=image/png -mimetype.svg=image/svg+xml +scan-path={{ cgit__repositories_dir | replace(cgit__chroot_dir, '') }} diff --git a/roles/cgit/templates/httpd.conf.j2 b/roles/cgit/templates/httpd.conf.j2 index 0220f90..48f840d 100644 --- a/roles/cgit/templates/httpd.conf.j2 +++ b/roles/cgit/templates/httpd.conf.j2 @@ -1,7 +1,7 @@ # managed by Ansible -server "cgit" { - listen on "{{ cgit_listen_address }}" port {{ cgit_listen_port }} +server "{{ cgit__domain_name }}" { + listen on {{ cgit__listen_address }} port {{ cgit__listen_port }} # cgit location "/cgit.*" { -- cgit v1.2.3