From 01c3cc46a2a619aceadedeb914473c6a7015cf27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=9A=D0=BE?= =?UTF-8?q?=D0=B7=D0=BB=D1=8E=D0=BA?= Date: Mon, 16 Jan 2023 23:07:39 +0300 Subject: [PATCH] =?UTF-8?q?gitea:=20=D1=80=D0=BE=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + roles/gitea/defaults/main.yml | 5 + roles/gitea/files/convert-pptx.sh | 8 + roles/gitea/files/custom/public/img/logo.svg | 4 + roles/gitea/files/custom/templates/home.tmpl | 23 +++ roles/gitea/files/fontconfig.conf | 24 +++ roles/gitea/files/gitea.service | 22 +++ roles/gitea/meta/main.yml | 11 ++ roles/gitea/tasks/gitea.yml | 157 +++++++++++++++++++ roles/gitea/tasks/main.yml | 3 + roles/gitea/tasks/pptx.yml | 39 +++++ roles/gitea/templates/gitea.ini | 55 +++++++ 12 files changed, 352 insertions(+) create mode 100644 .gitignore create mode 100644 roles/gitea/defaults/main.yml create mode 100755 roles/gitea/files/convert-pptx.sh create mode 100644 roles/gitea/files/custom/public/img/logo.svg create mode 100644 roles/gitea/files/custom/templates/home.tmpl create mode 100644 roles/gitea/files/fontconfig.conf create mode 100644 roles/gitea/files/gitea.service create mode 100644 roles/gitea/meta/main.yml create mode 100644 roles/gitea/tasks/gitea.yml create mode 100644 roles/gitea/tasks/main.yml create mode 100644 roles/gitea/tasks/pptx.yml create mode 100644 roles/gitea/templates/gitea.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..570b613 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/gitea diff --git a/roles/gitea/defaults/main.yml b/roles/gitea/defaults/main.yml new file mode 100644 index 0000000..0748fe5 --- /dev/null +++ b/roles/gitea/defaults/main.yml @@ -0,0 +1,5 @@ +--- +gitea_install_binary: 'n' +gitea_db_password: '' +gitea_dba_password: '' +gitea_conf__server__http_port: 3000 diff --git a/roles/gitea/files/convert-pptx.sh b/roles/gitea/files/convert-pptx.sh new file mode 100755 index 0000000..765e542 --- /dev/null +++ b/roles/gitea/files/convert-pptx.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -eu +file="$1" +dir=`mktemp -d` +trap "rm -rf '$dir'" EXIT +# LibreOffice logs to stdout in some distributions. +libreoffice --headless --convert-to pdf "$file" --outdir "$dir" >/dev/null 2>&1 +exec cat "$dir/$(basename $file .pptx).pdf" diff --git a/roles/gitea/files/custom/public/img/logo.svg b/roles/gitea/files/custom/public/img/logo.svg new file mode 100644 index 0000000..66646a6 --- /dev/null +++ b/roles/gitea/files/custom/public/img/logo.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/roles/gitea/files/custom/templates/home.tmpl b/roles/gitea/files/custom/templates/home.tmpl new file mode 100644 index 0000000..7f31546 --- /dev/null +++ b/roles/gitea/files/custom/templates/home.tmpl @@ -0,0 +1,23 @@ +{{template "base/head" .}} +
+
+
+
+ +
+
+

+ {{AppName}} +

+

+ Открытые материалы кафедры + Управления и интеллектуальных технологий +

+

+ Сайт кафедры +

+
+
+
+
+{{template "base/footer" .}} diff --git a/roles/gitea/files/fontconfig.conf b/roles/gitea/files/fontconfig.conf new file mode 100644 index 0000000..9b74b96 --- /dev/null +++ b/roles/gitea/files/fontconfig.conf @@ -0,0 +1,24 @@ + + + + + sans-serif + + PT Sans + + + + + serif + + PT Serif + + + + + monospace + + PT Mono + + + diff --git a/roles/gitea/files/gitea.service b/roles/gitea/files/gitea.service new file mode 100644 index 0000000..3845322 --- /dev/null +++ b/roles/gitea/files/gitea.service @@ -0,0 +1,22 @@ +# DO NOT EDIT: this file is generated by Ansible. + +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target +After=network.target +Wants=postgresql.service +After=postgresql.service + +[Service] +RestartSec=2s +Type=simple +User=git +Group=git +WorkingDirectory=/var/lib/gitea/ +RuntimeDirectory=gitea +ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=git HOME=/var/lib/git GITEA_WORK_DIR=/var/lib/gitea + +[Install] +WantedBy=multi-user.target diff --git a/roles/gitea/meta/main.yml b/roles/gitea/meta/main.yml new file mode 100644 index 0000000..a61ca52 --- /dev/null +++ b/roles/gitea/meta/main.yml @@ -0,0 +1,11 @@ +galaxy_info: + author: Dmitry Kozlyuk + description: Gitea + company: MPEI + license: BSD-3-Clause + min_ansible_version: 2.9 + platforms: + - name: Ubuntu + versions: + - 19.10 + - 22.04 diff --git a/roles/gitea/tasks/gitea.yml b/roles/gitea/tasks/gitea.yml new file mode 100644 index 0000000..ed06d2d --- /dev/null +++ b/roles/gitea/tasks/gitea.yml @@ -0,0 +1,157 @@ +--- +- name: install software + package: + name: + # Gitea operation + - git + # PostgreSQL + - postgresql + - python3-psycopg2 + +- name: ensure ru_RU.UTF-8 locale + locale_gen: + name: 'ru_RU.UTF-8' + +- name: ensure Postgres user exists + become: true + become_user: 'postgres' + postgresql_user: + name: 'gitea' + password: '{{ gitea_db_password }}' + login_password: '{{ gitea_dba_password }}' + +- name: ensure Postgres database exists + become: true + become_user: 'postgres' + postgresql_db: + name: 'gitea' + owner: 'gitea' + encoding: 'UTF-8' + lc_collate: 'ru_RU.UTF-8' + lc_ctype: 'ru_RU.UTF-8' + template: 'template0' + login_password: '{{ gitea_dba_password }}' + +- name: setup git user + user: + name: 'git' + comment: 'Git Version Control' + home: '/var/lib/git' + shell: '/bin/bash' + password: '*' # disabled + system: true + +- name: ensure git user home permissions + file: + path: '/var/lib/git' + owner: 'git' + group: 'git' + +- name: install binary + copy: + src: 'gitea' + dest: '/usr/local/bin/gitea' + mode: 0755 + when: gitea_install_binary == 'y' + register: gitea_binary + + +- name: ensure state directory structure + file: + path: '/var/lib/gitea/{{ item }}' + state: directory + mode: 0750 + owner: 'git' + group: 'git' + with_items: + - '' + - 'custom' + - 'data' + - 'log' + +- name: ensure configuration directory structure + file: + path: '/etc/gitea' + state: directory + owner: 'root' + group: 'git' + mode: 0750 + +- name: configure + template: + src: 'gitea.ini' + dest: '/etc/gitea/app.ini' + owner: 'root' + group: 'git' + mode: 0640 + register: gitea_conf + +- name: deploy custom files + become: true + become_user: 'git' + copy: + src: 'custom/' + dest: '/var/lib/gitea/custom/' + register: gitea_custom + +- name: configure service + copy: + src: 'gitea.service' + dest: '/etc/systemd/system/gitea.service' + register: service_conf + +- name: load service configuration + systemd: + daemon_reload: true + when: service_conf.changed + +- name: apply service configuration + service: + name: 'gitea' + state: restarted + when: gitea_binary.changed or gitea_conf.changed or gitea_custom.changed or service_conf.changed + +- name: ensure the service is started + service: + name: 'gitea' + state: started + +- name: configure Nginx + blockinfile: + path: '{{ gitea_nginx_conf_path }}' + block: | + location /git/ { + proxy_pass http://localhost:{{ gitea_conf__server__http_port }}/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + client_max_body_size 32M; + } + insertbefore: 'location' + marker: '# {mark} ANSIBLE MANAGED BLOCK: Gitea' + register: nginx_conf + +- name: apply Nginx configuration + service: + name: 'nginx' + state: reloaded + when: nginx_conf.changed + +- become: true + become_user: git + block: + + - name: 'list Gitea admin users' + command: 'gitea --config /etc/gitea/app.ini admin user list' + register: gitea_user + + - name: 'configure Gitea {{ gitea_user_username }} user' + when: gitea_user_username not in gitea_user.stdout + command: >- + gitea --config /etc/gitea/app.ini admin user create + --username '{{ gitea_user_username }}' + --password '{{ gitea_user_password }}' + --email '{{ gitea_user_email }}' + --must-change-password + --admin diff --git a/roles/gitea/tasks/main.yml b/roles/gitea/tasks/main.yml new file mode 100644 index 0000000..9084abd --- /dev/null +++ b/roles/gitea/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- include_tasks: 'gitea.yml' +- include_tasks: 'pptx.yml' diff --git a/roles/gitea/tasks/pptx.yml b/roles/gitea/tasks/pptx.yml new file mode 100644 index 0000000..930c021 --- /dev/null +++ b/roles/gitea/tasks/pptx.yml @@ -0,0 +1,39 @@ +--- +- name: install PPTX conversion script + copy: + src: 'convert-pptx.sh' + dest: '/usr/local/bin/convert-pptx' + mode: 0755 + +- name: install software + package: + name: + - libreoffice-impress-nogui + +- name: install fonts + package: + name: + - fonts-noto-core # Math + - fonts-paratype # Cyrillic + register: fonts + +- name: ensure font configuration directory + become: true + become_user: 'git' + file: + path: '/var/lib/git/.local/share/fonts' + state: directory + +- name: configure fonts + become: true + become_user: 'git' + copy: + src: 'fontconfig.conf' + dest: '/var/lib/git/.local/share/fonts/local.conf' + register: fontconfig + +- name: update font cache + when: fonts.changed or fontconfig.changed + become: true + become_user: 'git' + command: 'fc-cache' diff --git a/roles/gitea/templates/gitea.ini b/roles/gitea/templates/gitea.ini new file mode 100644 index 0000000..7f7828a --- /dev/null +++ b/roles/gitea/templates/gitea.ini @@ -0,0 +1,55 @@ +APP_NAME = Git УИТ +RUN_MODE = prod + +[database] +DB_TYPE = postgres +HOST = localhost +NAME = gitea +USER = gitea +PASSWD = {{ gitea_db_password }} +SSL_MODE = disable +CHARSET = utf8 +LOG_SQL = false + +[server] +DOMAIN = {{ gitea_conf__server__domain }} +ROOT_URL = {{ gitea_conf__server__root_url }} +HTTP_PORT = {{ gitea_conf__server__http_port }} +LFS_START_SERVER = true +LFS_JWT_SECRET = {{ gitea_conf__server__lfs_jwt_secret }} +OFFLINE_MODE = true + +[service] +DISABLE_REGISTRATION = true +DEFAULT_ALLOW_CREATE_ORGANIZATION = false + +[openid] +ENABLE_OPENID_SIGNIN = false +ENABLE_OPENID_SIGNUP = false + +[session] +PROVIDER = db + +[log] +MODE = console +LEVEL = info + +[security] +INSTALL_LOCK = true +INTERNAL_TOKEN = {{ gitea_conf__security__internal_token }} +PASSWORD_HASH_ALGO = pbkdf2 +SECRET_KEY = {{ gitea_conf__security__secret_key }} + +[i18n] +LANGS = ru-RU,en-US +NAMES = Русский,English + +[repository] +ROOT = /var/lib/gitea/data/gitea-repositories + +[markup.pptx] +ENABLED = true +FILE_EXTENSIONS = .pptx +RENDER_COMMAND = /usr/local/bin/convert-pptx +IS_INPUT_FILE = true +RENDER_CONTENT_MODE = pdf