From 01b2cd685887a73109407af88528bbb02d24fdbf Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 29 May 2023 11:54:19 +0200 Subject: [PATCH 1/3] remove existing `app.ini` before creating it --- templates/gitea/config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/gitea/config.yaml b/templates/gitea/config.yaml index bcc7c4d..78d95a6 100644 --- a/templates/gitea/config.yaml +++ b/templates/gitea/config.yaml @@ -20,6 +20,9 @@ stringData: #!/usr/bin/env bash set -euo pipefail + # ensure a clean start + rm $GITEA_APP_INI + function env2ini::log() { printf "${1}\n" } -- 2.40.1 From b663ab88a28c9c572ac62d54d6479bc671cf9022 Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 29 May 2023 12:07:24 +0200 Subject: [PATCH 2/3] condition on existence --- templates/gitea/config.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/gitea/config.yaml b/templates/gitea/config.yaml index 78d95a6..a5ccd05 100644 --- a/templates/gitea/config.yaml +++ b/templates/gitea/config.yaml @@ -21,7 +21,9 @@ stringData: set -euo pipefail # ensure a clean start - rm $GITEA_APP_INI + if [ -f ${GITEA_APP_INI} ]; then + rm $GITEA_APP_INI + fi function env2ini::log() { printf "${1}\n" -- 2.40.1 From abf6e2c8a92026ef5b8b395718892b766df27f98 Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 29 May 2023 20:13:00 +0200 Subject: [PATCH 3/3] create initial secrets before app.ini removal --- templates/gitea/config.yaml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/templates/gitea/config.yaml b/templates/gitea/config.yaml index a5ccd05..108b5fa 100644 --- a/templates/gitea/config.yaml +++ b/templates/gitea/config.yaml @@ -20,6 +20,23 @@ stringData: #!/usr/bin/env bash set -euo pipefail + ### initial creation of persistent secrets + if ![ -f ${GITEA_APP_INI} ]; then + function env2ini::generate_initial_secrets() { + # These environment variables will either be + # - overwritten with user defined values, + # - initially used to set up Gitea + # Anyway, they won't harm existing app.ini files + + export ENV_TO_INI__SECURITY__INTERNAL_TOKEN=$(gitea generate secret INTERNAL_TOKEN) + export ENV_TO_INI__SECURITY__SECRET_KEY=$(gitea generate secret SECRET_KEY) + export ENV_TO_INI__OAUTH2__JWT_SECRET=$(gitea generate secret JWT_SECRET) + export ENV_TO_INI__SERVER__LFS_JWT_SECRET=$(gitea generate secret LFS_JWT_SECRET) + + env2ini::log "...Initial secrets generated\n" + } + fi + # ensure a clean start if [ -f ${GITEA_APP_INI} ]; then rm $GITEA_APP_INI @@ -133,20 +150,6 @@ stringData: fi } - function env2ini::generate_initial_secrets() { - # These environment variables will either be - # - overwritten with user defined values, - # - initially used to set up Gitea - # Anyway, they won't harm existing app.ini files - - export ENV_TO_INI__SECURITY__INTERNAL_TOKEN=$(gitea generate secret INTERNAL_TOKEN) - export ENV_TO_INI__SECURITY__SECRET_KEY=$(gitea generate secret SECRET_KEY) - export ENV_TO_INI__OAUTH2__JWT_SECRET=$(gitea generate secret JWT_SECRET) - export ENV_TO_INI__SERVER__LFS_JWT_SECRET=$(gitea generate secret LFS_JWT_SECRET) - - env2ini::log "...Initial secrets generated\n" - } - env | (grep ENV_TO_INI || [[ $? == 1 ]]) > /tmp/existing-envs # MUST BE CALLED BEFORE OTHER CONFIGURATION -- 2.40.1