2020-09-25 08:37:55 -05:00
|
|
|
apiVersion: v1
|
|
|
|
kind: Secret
|
|
|
|
metadata:
|
|
|
|
name: {{ include "gitea.fullname" . }}-init
|
|
|
|
labels:
|
|
|
|
{{- include "gitea.labels" . | nindent 4 }}
|
|
|
|
type: Opaque
|
|
|
|
stringData:
|
2021-06-29 15:09:16 -05:00
|
|
|
init_directory_structure.sh: |-
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-01-20 05:28:39 -06:00
|
|
|
{{- if .Values.initPreScript }}
|
|
|
|
# BEGIN: initPreScript
|
|
|
|
{{- with .Values.initPreScript -}}
|
|
|
|
{{ . | nindent 4}}
|
|
|
|
{{- end -}}
|
|
|
|
# END: initPreScript
|
|
|
|
{{- end }}
|
|
|
|
|
2021-06-29 15:09:16 -05:00
|
|
|
set -x
|
|
|
|
|
2021-06-09 06:42:49 -05:00
|
|
|
{{- if not .Values.image.rootless }}
|
2021-04-19 07:30:02 -05:00
|
|
|
chown 1000:1000 /data
|
2021-06-09 06:42:49 -05:00
|
|
|
{{- end }}
|
2020-09-25 08:37:55 -05:00
|
|
|
mkdir -p /data/git/.ssh
|
|
|
|
chmod -R 700 /data/git/.ssh
|
2021-08-15 07:43:51 -05:00
|
|
|
[ ! -d /data/gitea ] && mkdir -p /data/gitea/conf
|
2021-04-29 04:12:48 -05:00
|
|
|
|
2021-06-09 09:35:50 -05:00
|
|
|
# prepare temp directory structure
|
|
|
|
mkdir -p "${GITEA_TEMP}"
|
|
|
|
chown 1000:1000 "${GITEA_TEMP}"
|
|
|
|
chmod ug+rwx "${GITEA_TEMP}"
|
|
|
|
|
2021-06-29 15:09:16 -05:00
|
|
|
configure_gitea.sh: |-
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-03-04 02:43:52 -06:00
|
|
|
{{- if include "db.servicename" . }}
|
2021-06-29 15:09:16 -05:00
|
|
|
# Connection retry inspired by https://gist.github.com/dublx/e99ea94858c07d2ca6de
|
|
|
|
function test_db_connection() {
|
|
|
|
local RETRY=0
|
|
|
|
local MAX=30
|
|
|
|
|
|
|
|
echo 'Wait for database to become avialable...'
|
|
|
|
until [ "${RETRY}" -ge "${MAX}" ]; do
|
|
|
|
nc -vz -w2 {{ include "db.servicename" . }} {{ include "db.port" . }} && break
|
|
|
|
RETRY=$[${RETRY}+1]
|
|
|
|
echo "...not ready yet (${RETRY}/${MAX})"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${RETRY}" -ge "${MAX}" ]; then
|
|
|
|
echo "Database not reachable after '${MAX}' attempts!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test_db_connection
|
2021-04-29 04:12:48 -05:00
|
|
|
{{- end }}
|
2021-06-29 15:09:16 -05:00
|
|
|
|
|
|
|
echo '==== BEGIN GITEA CONFIGURATION ===='
|
|
|
|
|
|
|
|
gitea migrate
|
|
|
|
|
2021-06-21 08:28:18 -05:00
|
|
|
{{- if or .Values.gitea.admin.existingSecret (and .Values.gitea.admin.username .Values.gitea.admin.password) }}
|
2021-06-29 15:09:16 -05:00
|
|
|
function configure_admin_user() {
|
|
|
|
local ACCOUNT_ID=$(gitea admin user list --admin | grep -e "\s\+${GITEA_ADMIN_USERNAME}\s\+" | awk -F " " "{printf \$1}")
|
|
|
|
if [[ -z "${ACCOUNT_ID}" ]]; then
|
|
|
|
echo "No admin user '${GITEA_ADMIN_USERNAME}' found. Creating now..."
|
|
|
|
gitea admin user create --admin --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" --email {{ .Values.gitea.admin.email | quote }} --must-change-password=false
|
|
|
|
echo '...created.'
|
|
|
|
else
|
|
|
|
echo "Admin account '${GITEA_ADMIN_USERNAME}' already exist. Running update to sync password..."
|
|
|
|
gitea admin user change-password --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}"
|
|
|
|
echo '...password sync done.'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_admin_user
|
2020-09-25 08:37:55 -05:00
|
|
|
{{- end }}
|
2021-06-29 15:09:16 -05:00
|
|
|
|
|
|
|
function configure_ldap() {
|
2021-10-08 07:16:24 -05:00
|
|
|
{{- if .Values.gitea.ldap }}
|
|
|
|
{{- range $idx, $value := .Values.gitea.ldap }}
|
|
|
|
local LDAP_NAME={{ (printf "%s" $value.name) | squote }}
|
2021-06-29 15:09:16 -05:00
|
|
|
local GITEA_AUTH_ID=$(gitea admin auth list --vertical-bars | grep -E "\|${LDAP_NAME}\s+\|" | grep -iE '\|LDAP \(via BindDN\)\s+\|' | awk -F " " "{print \$1}")
|
|
|
|
|
|
|
|
if [[ -z "${GITEA_AUTH_ID}" ]]; then
|
|
|
|
echo "No ldap configuration found with name '${LDAP_NAME}'. Installing it now..."
|
2021-10-08 07:16:24 -05:00
|
|
|
gitea admin auth add-ldap {{- include "gitea.ldap_settings" (list $idx $value) | indent 1 }}
|
2021-06-29 15:09:16 -05:00
|
|
|
echo '...installed.'
|
|
|
|
else
|
|
|
|
echo "Existing ldap configuration with name '${LDAP_NAME}': '${GITEA_AUTH_ID}'. Running update to sync settings..."
|
2021-10-08 07:16:24 -05:00
|
|
|
gitea admin auth update-ldap --id "${GITEA_AUTH_ID}" {{- include "gitea.ldap_settings" (list $idx $value) | indent 1 }}
|
2021-06-29 15:09:16 -05:00
|
|
|
echo '...sync settings done.'
|
|
|
|
fi
|
2021-10-08 07:16:24 -05:00
|
|
|
{{- end }}
|
|
|
|
{{- else }}
|
|
|
|
echo 'no ldap configuration... skipping.'
|
|
|
|
{{- end }}
|
2021-06-29 15:09:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
configure_ldap
|
|
|
|
|
|
|
|
function configure_oauth() {
|
2021-12-20 08:43:55 -06:00
|
|
|
{{- if .Values.gitea.oauth }}
|
|
|
|
{{- range $idx, $value := .Values.gitea.oauth }}
|
|
|
|
local OAUTH_NAME={{ (printf "%s" $value.name) | squote }}
|
2021-06-29 15:09:16 -05:00
|
|
|
local AUTH_ID=$(gitea admin auth list --vertical-bars | grep -E "\|${OAUTH_NAME}\s+\|" | grep -iE '\|OAuth2\s+\|' | awk -F " " "{print \$1}")
|
|
|
|
|
|
|
|
if [[ -z "${AUTH_ID}" ]]; then
|
|
|
|
echo "No oauth configuration found with name '${OAUTH_NAME}'. Installing it now..."
|
2021-12-20 08:43:55 -06:00
|
|
|
gitea admin auth add-oauth {{- include "gitea.oauth_settings" (list $idx $value) | indent 1 }}
|
2021-06-29 15:09:16 -05:00
|
|
|
echo '...installed.'
|
|
|
|
else
|
|
|
|
echo "Existing oauth configuration with name '${OAUTH_NAME}': '${AUTH_ID}'. Running update to sync settings..."
|
2021-12-20 08:43:55 -06:00
|
|
|
gitea admin auth update-oauth --id "${AUTH_ID}" {{- include "gitea.oauth_settings" (list $idx $value) | indent 1 }}
|
2021-06-29 15:09:16 -05:00
|
|
|
echo '...sync settings done.'
|
|
|
|
fi
|
2021-12-20 08:43:55 -06:00
|
|
|
{{- end }}
|
|
|
|
{{- else }}
|
|
|
|
echo 'no oauth configuration... skipping.'
|
|
|
|
{{- end }}
|
2021-06-29 15:09:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
configure_oauth
|
|
|
|
|
|
|
|
echo '==== END GITEA CONFIGURATION ===='
|