mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-30 23:45:25 +02:00
fixup! ♻️ migration externalsecrets
This commit is contained in:
87
kubernetes/apps/default/gitea/app/externalbackup.yaml
Normal file
87
kubernetes/apps/default/gitea/app/externalbackup.yaml
Normal file
@@ -0,0 +1,87 @@
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: &app gitea-external-backup
|
||||
namespace: default
|
||||
spec:
|
||||
schedule: "@daily"
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
name: *app
|
||||
spec:
|
||||
containers:
|
||||
- name: *app
|
||||
image: ghcr.io/auricom/kubectl:1.27.3@sha256:402cbd1a404bdae3db854252054e4160b5746067e6f462d4a48236c46f6ad28a
|
||||
imagePullPolicy: IfNotPresent
|
||||
command:
|
||||
- "/bin/bash"
|
||||
- "-c"
|
||||
- |
|
||||
#!/bin/bash
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
mkdir -p ~/.ssh
|
||||
cp /opt/id_rsa ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
|
||||
ssh -o StrictHostKeyChecking=no homelab@${LOCAL_LAN_TRUENAS} << 'EOF'
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
WORK_DIR="/mnt/storage/backups/apps/gitea"
|
||||
|
||||
ORGANISATIONS=$(curl --silent --location --request GET "https://gitea.${SECRET_CLUSTER_DOMAIN}/api/v1/orgs" --header "Authorization: Bearer ${SECRET_GITEA_API_TOKEN}" | jq --raw-output .[].username)
|
||||
ORGANISATIONS+=" auricom"
|
||||
|
||||
for org in $ORGANISATIONS
|
||||
do
|
||||
mkdir -p $WORK_DIR/$org
|
||||
if [ $org == "auricom" ]; then
|
||||
keyword="users"
|
||||
else
|
||||
keyword="orgs"
|
||||
fi
|
||||
REPOSITORIES=$(curl --silent --location --request GET "https://gitea.${SECRET_CLUSTER_DOMAIN}/api/v1/$keyword/$org/repos?limit=1000" --header "Authorization: Bearer ${SECRET_GITEA_API_TOKEN}" | jq --raw-output .[].name)
|
||||
for repo in $REPOSITORIES
|
||||
do
|
||||
if [ -d "$WORK_DIR/$org/$repo" ]; then
|
||||
echo "INFO: pull $org/$repo..."
|
||||
cd $WORK_DIR/$org/$repo
|
||||
git remote show origin -n | grep -c main &> /dev/null && MAIN_BRANCH="main" || MAIN_BRANCH="master"
|
||||
git fetch --all
|
||||
test $? -ne 0 && exit 1
|
||||
git reset --hard origin/$MAIN_BRANCH
|
||||
test $? -ne 0 && exit 1
|
||||
git pull origin $MAIN_BRANCH
|
||||
test $? -ne 0 && exit 1
|
||||
echo "INFO: clean $org/$repo..."
|
||||
git fetch --prune
|
||||
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}')
|
||||
do
|
||||
git branch -D $branch
|
||||
done
|
||||
else
|
||||
echo "INFO: clone $org/$repo..."
|
||||
cd $WORK_DIR/$org
|
||||
git clone git@gitea.${SECRET_DOMAIN}:$org/$repo.git
|
||||
test $? -ne 0 && exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
echo "INFO: Backup done"
|
||||
EOF
|
||||
volumeMounts:
|
||||
- name: secret
|
||||
mountPath: /opt/id_rsa
|
||||
subPath: GITEA_DEPLOYMENT_PRIVATE_KEY
|
||||
volumes:
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: gitea-secret
|
||||
restartPolicy: Never
|
Reference in New Issue
Block a user