{#- -*- coding: utf-8 -*- #} {#- vim: ft=jinja #} {#- If latest was specified, query the official download server for the latest version. -#} {%- if 'latest' == mapdata.version -%} {%- set latest = salt['http.query']( mapdata.lookup.pkg.latest, decode=True, decode_type='json' )['dict']['latest']['version'] -%} {%- do mapdata.update({'version': latest}) -%} {%- endif -%} {#- If paths are different than default, they need to be specified in the config and the service needs to grant read/write permissions. CUSTOM_PATH and WORKDIR are environment variables. I'm not sure about `log` tbh. Per the official docs, the default is empty. This might cause duplicate entries if the user did not specify in all-lowercase. Also, it will not overwrite custom configuration, which might make the installation fail. -#} {%- do mapdata.update({"_rw": []}) -%} {%- for path in [ ('app_data_path', 'server', mapdata.lookup.paths.data, mapdata.lookup.paths.work | path_join('data')), ('root_path', 'log', mapdata.lookup.paths.log, mapdata.lookup.paths.work | path_join('log')), ('root', 'repository', mapdata.lookup.paths.repos, mapdata.lookup.paths.data | path_join('gitea-repositories')), ] -%} {%- set var, topic, current, default = path -%} {%- if current != default -%} {%- do mapdata | update_dict_key_value('config:' ~ topic, {var: current}) -%} {#- log directory is handled in service template -#} {%- if topic != 'log' -%} {%- do mapdata._rw.append(current) -%} {%- endif -%} {%- endif -%} {%- endfor -%} {#- If the secrets were not provided, get them from a grain/generate and save them there. This avoids a) calling the gitea binary in the app.ini template (`gitea generate secret SECRET_KEY`) b) and special-casing to avoid regenerating those secrets every run. The INTERNAL_TOKEN has a special format, but it can be configured to be read from a separate file. "." is used in place of ":" to avoid libmapstack automap. @TODO sensible to indulge in that magic? -#} {%- if not mapdata.config | traverse("security:secret_key", "") -%} {%- set secret_key = salt['grains.get_or_set_hash']( 'gitea.config.security.secret_key', length=64, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', ) -%} {%- do mapdata.config | update_dict_key_value("security", {"secret_key": secret_key}) -%} {%- endif -%} {%- for jwt in ['oauth2:jwt_secret', 'server:lfs_jwt_secret'] -%} {%- if not mapdata.config | traverse(jwt, "") -%} {%- set secret = salt['grains.get_or_set_hash']( 'gitea.config.' ~ jwt | replace(":", "."), length=43, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-', ) -%} {%- do mapdata.config | update_dict_key_value(jwt.split(":")[0], {jwt.split(":")[1]: secret}) -%} {%- endif -%} {%- endfor -%} {%- do mapdata.update({"_generate_token": false}) -%} {%- if not mapdata.config | traverse("security:internal_token") -%} {%- do mapdata.config | update_dict_key_value("security", {"internal_token_uri": mapdata.lookup.paths.internal_token_uri}) -%} {%- if 'file://' == mapdata.lookup.paths.internal_token_uri[:7] -%} {%- do mapdata.update({"_generate_token": true}) -%} {%- endif %} {%- endif -%} {%- do mapdata.config | update_dict_key_value("security", {"install_lock": true}) -%} {#- Automatically configure the socket path to use the one provided by Systemd. -#} {%- if "unix" in mapdata.config | traverse("server:protocol", "") -%} {%- do mapdata.config.server.update({"http_addr": "/run/gitea/gitea.socket"}) -%} {%- endif -%} {#- Automatically configure basic service dependencies. Memcached/Redis are not as easy to discover (multiple settings) and therefore need to be provided manually. -#} {%- if mapdata.config | traverse("database:db_type", "mysql") in ["mysql", "postgres", "mssql"] -%} {%- set db_type = mapdata.config | traverse("database:db_type", "mysql") -%} {%- if db_type not in mapdata.service.wants -%} {#- MariaDB usually provides `mysql.service` as well. -#} {%- do mapdata.service.wants.append(db_type) -%} {%- endif -%} {%- endif -%}