60 lines
No EOL
2.1 KiB
YAML
60 lines
No EOL
2.1 KiB
YAML
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: {{ include "garm.fullname" . }}-init
|
|
namespace: {{ .Release.Namespace }}
|
|
spec:
|
|
ttlSecondsAfterFinished: 100
|
|
template:
|
|
spec:
|
|
initContainers:
|
|
- name: wait-for-garm
|
|
image: {{ .Values.initJob.waitForGarm.image }}
|
|
command:
|
|
- "/bin/sh"
|
|
- "-c"
|
|
- |
|
|
echo "Waiting for Garm to be available at ${GARM_URL}"
|
|
for i in $(seq 1 {{ .Values.initJob.waitForGarm.maxRetries }}); do
|
|
status=$(curl -s -o /dev/null -w "%{http_code}" "${GARM_URL}")
|
|
if [ "$status" -eq 301 ]; then
|
|
echo "Garm is up (HTTP 301)"
|
|
exit 0
|
|
fi
|
|
echo "Got HTTP $status, retrying in {{ .Values.initJob.waitForGarm.retryInterval }}s..."
|
|
sleep {{ .Values.initJob.waitForGarm.retryInterval }}
|
|
done
|
|
echo "Garm did not return HTTP 301 after {{ .Values.initJob.waitForGarm.maxRetries }} tries"
|
|
exit 1
|
|
envFrom:
|
|
- secretRef:
|
|
name: {{ include "garm.fullname" . }}-credentials
|
|
containers:
|
|
- image: {{ .Values.initJob.image }}
|
|
name: credentials-setup
|
|
command:
|
|
- "/bin/sh"
|
|
- "-c"
|
|
- |
|
|
garm-cli init --name gitea --password ${GARM_ADMIN_PASSWORD} --username ${GARM_ADMIN_USERNAME} --email ${GARM_ADMIN_EMAIL} --url ${GARM_URL}
|
|
if [ $? -ne 0 ]; then
|
|
echo "garm maybe already initialized"
|
|
exit 0
|
|
fi
|
|
|
|
garm-cli gitea endpoint create \
|
|
--api-base-url ${GIT_URL} \
|
|
--base-url ${GIT_URL} \
|
|
--description "My first Gitea endpoint" \
|
|
--name local-gitea
|
|
|
|
garm-cli gitea credentials add \
|
|
--endpoint local-gitea \
|
|
--auth-type pat \
|
|
--pat-oauth-token $GITEA_TOKEN \
|
|
--name autotoken \
|
|
--description "Gitea token"
|
|
envFrom:
|
|
- secretRef:
|
|
name: {{ include "garm.fullname" . }}-credentials
|
|
restartPolicy: Never |