This commit is contained in:
ansgarz 2021-12-15 13:05:55 +01:00
parent 663a460875
commit b3a5895897

View file

@ -4,70 +4,57 @@ set -x
function main() function main()
{ {
date # enable tls for k3s with cert-manager
local bucket_name="${1:-mybucket}"; shift
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.4/cert-manager.yaml kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.4/cert-manager.yaml
kubectl apply -f localstack.yaml kubectl apply -f localstack.yaml
date
until kubectl apply -f certificate.yaml until kubectl apply -f certificate.yaml
do do
echo "[INFO] Waiting for certificate ..." echo "[INFO] Waiting for certificate ..."
sleep 30 sleep 30
done done
echo # wait for ingress to be ready
bash -c 'external_ip=""; while [ -z $external_ip ]; do echo "[INFO] Waiting for end point..."; external_ip=$(kubectl get ingress -o jsonpath="{$.items[*].status.loadBalancer.ingress[*].ip}"); [ -z "$external_ip" ] && sleep 10; done; echo "End point ready - $external_ip";' bash -c 'external_ip=""; while [ -z $external_ip ]; do echo "[INFO] Waiting for end point..."; external_ip=$(kubectl get ingress -o jsonpath="{$.items[*].status.loadBalancer.ingress[*].ip}"); [ -z "$external_ip" ] && sleep 10; done; echo "End point ready - $external_ip";'
date export INGRESS_IP=$(kubectl get ingress ingress-localstack -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")
echo
export ENDPOINT=$(kubectl get ingress ingress-localstack -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")
sudo bash -c "echo \"$ENDPOINT k3stesthost cloudhost\" >> /etc/hosts" # Remove this, works for testing, but fills your /etc/hosts
cd ../../../../ # c4k-nextcloud project root cd ../../../../ # c4k-nextcloud project root
lein uberjar lein uberjar
java -jar target/uberjar/c4k-nextcloud-standalone.jar config-local.edn auth-local.edn | kubectl apply -f - java -jar target/uberjar/c4k-nextcloud-standalone.jar config-local.edn auth-local.edn | kubectl apply -f -
POD=$(kubectl get pod -l app=cloud-app -o name)
kubectl wait $POD --for=condition=Ready --timeout=240s CLOUD_POD=$(kubectl get pod -l app=cloud-app -o name)
kubectl wait $CLOUD_POD --for=condition=Ready --timeout=240s
# wait for nextcloud config file available # wait for nextcloud config file available
timeout 180 bash -c "kubectl exec -t $POD -- bash -c \"until [ -f /var/www/html/config/config.php ]; do sleep 10; done\"" timeout 180 bash -c "kubectl exec -t $POD -- bash -c \"until [ -f /var/www/html/config/config.php ]; do sleep 10; done\""
# ensure an instance of pod backup-restore
kubectl scale deployment backup-restore --replicas 1 kubectl scale deployment backup-restore --replicas 1
date # wait for localstack health endpoint
echo echo "$INGRESS_IP k3stesthost cloudhost" >> /etc/hosts
until curl --fail --silent k3stesthost/health | grep -oe '"s3": "available"' -oe '"s3": "running"' until curl --fail --silent k3stesthost/health | grep -oe '"s3": "available"' -oe '"s3": "running"'
do do
curl --fail k3stesthost/health curl --fail k3stesthost/health
echo "[INFO] Waiting for s3 running" echo "[INFO] Waiting for s3 running"
sleep 10 sleep 10
done done
echo
POD=$(kubectl get pod -l app=backup-restore -o name) BACKUP_POD=$(kubectl get pod -l app=backup-restore -o name)
kubectl wait $BACKUP_POD --for=condition=Ready --timeout=240s
kubectl wait $POD --for=condition=Ready --timeout=240s kubectl exec -t $BACKUP_POD -- bash -c "echo \"$INGRESS_IP k3stesthost cloudhost\" >> /etc/hosts"
kubectl exec -t $BACKUP_POD -- /usr/local/bin/init.sh
kubectl exec -t $POD -- bash -c "echo \"$ENDPOINT k3stesthost cloudhost\" >> /etc/hosts"
kubectl exec -t $POD -- /usr/local/bin/init.sh
echo ================= BACKUP ================= echo ================= BACKUP =================
kubectl exec -t $POD -- ls -l /var/backups/config kubectl exec -t $BACKUP_POD -- /usr/local/bin/backup.sh
kubectl exec -t $POD -- /usr/local/bin/backup.sh
date
sleep 10 # avoid race conditions sleep 10 # avoid race conditions
echo ================= RESTORE ================= echo ================= RESTORE =================
kubectl exec -t $BACKUP_POD -- /usr/local/bin/restore.sh
kubectl exec -t $POD -- ls -l /var/backups/config
kubectl exec -t $POD -- /usr/local/bin/restore.sh
} }
main "$@" main "$@"