[Close #1117] feat: support rebuilding app.ini
Bash / bash-unittest (push) Successful in 18s
Bash / shellcheck (push) Successful in 21s
changelog / changelog (push) Successful in 12s
Helm / helm-lint (push) Successful in 14s
Helm / helm-unittest (push) Successful in 19s
Markdown linter / markdown-lint (push) Successful in 14s
Markdown linter / markdown-link-checker (push) Successful in 51s

Allow stale settings to be removed on startup while preserving existing Gitea secret keys.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
volker.raschekandCopilot committed 2026-12-04 21:41:59 +01:00
1 parent 1779e3b525
commit ffd2ba1d77
7 files changed
+91 -5

No files matched your search

+8
View File
@@ -214,6 +214,13 @@ INSTALL_LOCK is always set to true, since we want to configure Gitea with this h
_All default settings are made directly in the generated `app.ini`, not in the Values._ _All default settings are made directly in the generated `app.ini`, not in the Values._
#### Rebuilding app.ini
By default, removed settings remain in an existing `app.ini`.
Set `deployment.initAppIni.config.rebuild` to `true` to rebuild it on startup from the current configuration sources.
The existing `security.SECRET_KEY`, `security.INTERNAL_TOKEN`, `oauth2.JWT_SECRET`, and `server.LFS_JWT_SECRET` are preserved.
All other settings that are present only in `app.ini`, including manually managed secrets, are removed.
#### Database defaults #### Database defaults
If a builtIn database is enabled the database configuration is set automatically. If a builtIn database is enabled the database configuration is set automatically.
@@ -1052,6 +1059,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo
| `deployment.initDirectories.resources` | Compute Resources required by the initDirectories container. Defaults to `initContainers.resources`. Cannot be updated. | `nil` | | `deployment.initDirectories.resources` | Compute Resources required by the initDirectories container. Defaults to `initContainers.resources`. Cannot be updated. | `nil` |
| `deployment.initDirectories.securityContext` | Security context of the initDirectories container. Defaults to `deployment.gitea.securityContext`. | `{}` | | `deployment.initDirectories.securityContext` | Security context of the initDirectories container. Defaults to `deployment.gitea.securityContext`. | `{}` |
| `deployment.initDirectories.volumeMounts` | Additional volume mounts. | `[]` | | `deployment.initDirectories.volumeMounts` | Additional volume mounts. | `[]` |
| `deployment.initAppIni.config.rebuild` | Rebuild app.ini on startup, preserving Gitea secret keys but removing unmanaged settings. | `false` |
| `deployment.initAppIni.env` | Additional environment variables to pass to the init container. | `[]` | | `deployment.initAppIni.env` | Additional environment variables to pass to the init container. | `[]` |
| `deployment.initAppIni.envFrom` | List of environment variables mounted from configMaps or secrets for the initAppIni container. | `[]` | | `deployment.initAppIni.envFrom` | List of environment variables mounted from configMaps or secrets for the initAppIni container. | `[]` |
| `deployment.initAppIni.image.registry` | image registry, e.g. gcr.io,docker.io. | `docker.gitea.com` | | `deployment.initAppIni.image.registry` | image registry, e.g. gcr.io,docker.io. | `docker.gitea.com` |
@@ -158,4 +158,11 @@ if [ -f "${GITEA_APP_INI}" ]; then
unset GITEA__SERVER__LFS_JWT_SECRET unset GITEA__SERVER__LFS_JWT_SECRET
fi fi
gitea config edit-ini --apply-env --config "$GITEA_APP_INI" --out "$GITEA_APP_INI" if [[ "${GITEA_REBUILD_APP_INI:-false}" == "true" && -f "${GITEA_APP_INI}" ]]; then
keep_keys_file="$(mktemp)"
trap 'rm -f "${keep_keys_file}"' EXIT
printf '%s\n' '[security]' 'SECRET_KEY=' 'INTERNAL_TOKEN=' '[oauth2]' 'JWT_SECRET=' '[server]' 'LFS_JWT_SECRET=' > "${keep_keys_file}"
gitea config edit-ini --apply-env --config "$GITEA_APP_INI" --config-keep-keys "${keep_keys_file}" --out "$GITEA_APP_INI"
else
gitea config edit-ini --apply-env --config "$GITEA_APP_INI" --out "$GITEA_APP_INI"
fi
+2
View File
@@ -84,6 +84,8 @@
value: /tmp/existing-envs value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT - name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts value: /env-to-ini-mounts
- name: GITEA_REBUILD_APP_INI
value: {{ $config.config.rebuild | quote }}
{{- if .Values.cloudnativePG.enabled }} {{- if .Values.cloudnativePG.enabled }}
- name: GITEA__database__PASSWD - name: GITEA__database__PASSWD
valueFrom: valueFrom:
@@ -30,6 +30,11 @@ case "$*" in
'generate secret LFS_JWT_SECRET') 'generate secret LFS_JWT_SECRET')
echo 'mocked-lfs-jwt-secret' echo 'mocked-lfs-jwt-secret'
;; ;;
"config edit-ini --apply-env --config $GITEA_APP_INI --config-keep-keys "*" --out $GITEA_APP_INI")
test "$GITEA_EDIT_INI_EXPECTED" -eq 1
cat "$7"
echo 'Stubbed gitea config edit-ini rebuild was called!'
;;
"config edit-ini --apply-env --config $GITEA_APP_INI --out $GITEA_APP_INI") "config edit-ini --apply-env --config $GITEA_APP_INI --out $GITEA_APP_INI")
if [ "$GITEA_EDIT_INI_EXPECTED" -eq 1 ]; then if [ "$GITEA_EDIT_INI_EXPECTED" -eq 1 ]; then
echo 'Stubbed gitea config edit-ini was called!' echo 'Stubbed gitea config edit-ini was called!'
@@ -115,6 +120,34 @@ function write_mounted_file() {
refute_line '+GITEA__SERVER__LFS_JWT_SECRET=mocked-lfs-jwt-secret' refute_line '+GITEA__SERVER__LFS_JWT_SECRET=mocked-lfs-jwt-secret'
} }
@test "rebuilds an existing app.ini while preserving secret keys" {
expect_gitea_config_edit_ini_call
export GITEA_REBUILD_APP_INI=true
touch "$GITEA_APP_INI"
run "$PROJECT_ROOT/scripts/init-containers/config/config_environment.sh"
assert_success
assert_line '[security]'
assert_line 'SECRET_KEY='
assert_line 'INTERNAL_TOKEN='
assert_line '[oauth2]'
assert_line 'JWT_SECRET='
assert_line '[server]'
assert_line 'LFS_JWT_SECRET='
assert_line 'Stubbed gitea config edit-ini rebuild was called!'
}
@test "uses normal initialization when rebuild is enabled for a new app.ini" {
expect_gitea_config_edit_ini_call
export GITEA_REBUILD_APP_INI=true
run "$PROJECT_ROOT/scripts/init-containers/config/config_environment.sh"
assert_success
assert_line 'Stubbed gitea config edit-ini was called!'
}
@test "ensures that preset environment variables take precedence over auto-generated ones" { @test "ensures that preset environment variables take precedence over auto-generated ones" {
expect_gitea_config_edit_ini_call expect_gitea_config_edit_ini_call
export GITEA__OAUTH2__JWT_SECRET="pre-defined-jwt-secret" export GITEA__OAUTH2__JWT_SECRET="pre-defined-jwt-secret"
@@ -31,7 +31,7 @@ tests:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
- lengthEqual: - lengthEqual:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
count: 6 count: 7
- isSubset: - isSubset:
path: spec.template.spec.initContainers[1] path: spec.template.spec.initContainers[1]
content: content:
@@ -48,6 +48,8 @@ tests:
value: /tmp/existing-envs value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT - name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts value: /env-to-ini-mounts
- name: GITEA_REBUILD_APP_INI
value: "false"
- it: "Render the Deployment with standard additionalConfigFromEnvs" - it: "Render the Deployment with standard additionalConfigFromEnvs"
template: templates/deployment.yaml template: templates/deployment.yaml
set: set:
@@ -59,7 +61,7 @@ tests:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
- lengthEqual: - lengthEqual:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
count: 8 count: 9
- isSubset: - isSubset:
path: spec.template.spec.initContainers[1] path: spec.template.spec.initContainers[1]
content: content:
@@ -76,6 +78,8 @@ tests:
value: /tmp/existing-envs value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT - name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts value: /env-to-ini-mounts
- name: GITEA_REBUILD_APP_INI
value: "false"
- name: GITEA_database_HOST - name: GITEA_database_HOST
value: my-db:123 value: my-db:123
- name: GITEA_database_USER - name: GITEA_database_USER
@@ -93,7 +97,7 @@ tests:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
- lengthEqual: - lengthEqual:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
count: 8 count: 9
- isSubset: - isSubset:
path: spec.template.spec.initContainers[1] path: spec.template.spec.initContainers[1]
content: content:
@@ -110,6 +114,8 @@ tests:
value: /tmp/existing-envs value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT - name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts value: /env-to-ini-mounts
- name: GITEA_REBUILD_APP_INI
value: "false"
- name: GITEA_database_HOST - name: GITEA_database_HOST
value: my-db-host:321 value: my-db-host:321
- name: GITEA_database_USER - name: GITEA_database_USER
@@ -131,7 +137,7 @@ tests:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
- lengthEqual: - lengthEqual:
path: spec.template.spec.initContainers[1].env path: spec.template.spec.initContainers[1].env
count: 7 count: 8
- isSubset: - isSubset:
path: spec.template.spec.initContainers[1] path: spec.template.spec.initContainers[1]
content: content:
@@ -148,6 +154,8 @@ tests:
value: /tmp/existing-envs value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT - name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts value: /env-to-ini-mounts
- name: GITEA_REBUILD_APP_INI
value: "false"
- name: GITEA_database_HOST - name: GITEA_database_HOST
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
@@ -0,0 +1,24 @@
suite: Test deployment app.ini rebuild
release:
name: gitea-unittests
namespace: testing
templates:
- templates/deployment.yaml
tests:
- it: Disable app.ini rebuild by default
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: GITEA_REBUILD_APP_INI
value: "false"
- it: Enable app.ini rebuild when configured
set:
deployment.initAppIni.config.rebuild: true
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: GITEA_REBUILD_APP_INI
value: "true"
+4
View File
@@ -220,6 +220,10 @@ deployment:
# readOnly: true # readOnly: true
initAppIni: initAppIni:
## @param deployment.initAppIni.config.rebuild Rebuild app.ini on startup, preserving Gitea secret keys but removing unmanaged settings.
config:
rebuild: false
## @param deployment.initAppIni.env Additional environment variables to pass to the init container. ## @param deployment.initAppIni.env Additional environment variables to pass to the init container.
env: [] env: []
# - name: VARIABLE # - name: VARIABLE