Files
terraform/modules/apps/fefan/lib/scripts/install-fefan.sh

44 lines
1.5 KiB
Bash

#!/bin/bash
source /opt/fefan/env.sh
# trigger manually a CI/CD pipeline
curl -X POST -H "Authorization: token $GITEA_FEFAN_APPLICATION_TOKEN" \
-H "Content-Type: application/json" \
$GITEA_INSTANCE_URL/api/v1/repos/$GITEA_FEFAN_REPOSITORY/actions/workflows/deploy.yaml/dispatches \
-d '{"ref": "main", "inputs": {"ref": "main"}}'
RUN_ID=$(curl -s -H "Authorization: token $GITEA_FEFAN_APPLICATION_TOKEN" \
$GITEA_INSTANCE_URL/api/v1/repos/$GITEA_FEFAN_REPOSITORY/actions/runs \
| jq -r '.workflow_runs | sort_by(.created_at) | .[0].id')
while true; do
STATUS=$(curl -s -H "Authorization: token $GITEA_FEFAN_APPLICATION_TOKEN" \
$GITEA_INSTANCE_URL/api/v1/repos/$GITEA_FEFAN_REPOSITORY/actions/runs/$RUN_ID \
| jq -r '.status')
if [ "$STATUS" = "completed" ]; then
CONCLUSION=$(curl -s -H "Authorization: token $GITEA_FEFAN_APPLICATION_TOKEN" \
$GITEA_INSTANCE_URL/api/v1/repos/$GITEA_FEFAN_REPOSITORY/actions/runs/$RUN_ID \
| jq -r '.conclusion')
echo "Workflow finished with status: $CONCLUSION"
break
fi
echo "Waiting 10 seconds..."
sleep 10
done
if [ "$CONCLUSION" = "success" ]; then
echo "Launching command..."
while [ "$(docker inspect -f '{{.State.Running}}' fefan-db-1 2>/dev/null)" != "true" ]; do
echo "Waiting database container status"
sleep 5
done
systemctl start restore-backup.service
else
echo "Workflow failed or was cancelled, aborting."
exit 1
fi