This commit is contained in:
2023-09-26 18:14:36 -06:00
commit fb5a0fc542
443 changed files with 21892 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
---
kind: pipeline
type: docker
name: trigger
steps:
- name: trigger
image: plugins/downstream
settings:
server: https://drone.alexlebens.net
token:
from_secret: drone_token
fork: true
repositories:
- alexlebens/DroneImage
- name: Nofification > Discord | Trigger - Success
image: appleboy/drone-discord
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token
username: DroneCI - ps03fd
message: Trigger executed from Deployment Scripts to DroneImage
when:
status:
- sucess
- name: Nofification > Discord | Trigger - Failure
image: appleboy/drone-discord
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token
username: DroneCI - ps03fd
message: Trigger failed from Deployment Scripts to DroneImage
when:
status:
- failure

View File

@@ -0,0 +1,111 @@
#!/usr/bin/env bash
#set -e
echo ">>>> Configuration"
WORKINGDIR=$(pwd)
echo ">>> Apply"
echo ">> Storage"
PATH_FAILURE=true
PATHS=$(yq '.volumes[].driver_opts.device | select(. > "/var*")' docker-compose.yml)
for dir in $PATHS; do
if ! ssh -q drone@$HOST_IP "sudo test -d $dir"; then
echo "Missing path: $dir"
ssh -q drone@$HOST_IP "sudo test -d $dir"
ssh drone@$HOST_IP "sudo mkdir -p $dir"
ssh drone@$HOST_IP "sudo chown alexlebens:alexlebens $dir"
if ! ssh -q drone@$HOST_IP "sudo test -d $dir"; then
echo "Failed to create path: $dir"
ssh -q drone@$HOST_IP "sudo test -d $dir"
else
echo "Path created: $dir"
PATH_FAILURE=false
fi
else
echo "Path found: $dir"
PATH_FAILURE=false
fi
done
echo ">>> Checks"
echo ">> DNS"
URL_CHECK=true
URL_FAILURE=false
if [ -n "$URL" ]; then
for i in $URL; do
if [ "$(dig +short -t a $i)" ]; then
echo "URL found: $i"
URL_CHECK=false
else
echo "URL not found: $i"
URL_FAILURE=true
fi
done
else
echo "No URL set"
URL_CHECK=false
fi
echo ">> Uptime"
cd UptimeKuma
UPTIME_CHECK=true
UPTIME_FAILURE=false
TOKEN=$(curl -X 'POST' "${UPTIMEKUMA_URL}/login/access-token" -H 'accept: application/json' -H 'Content-Type: application/x-www-form-urlencoded' -d "grant_type=&username=${UPTIMEKUMA_NAME}&password=${UPTIMEKUMA_PASSWORD}&scope=&client_id=&client_secret=" | jq -r ".access_token")
MONITORS=$(curl -X 'GET' "${UPTIMEKUMA_URL}/monitors" -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -s | jq --arg PACKAGE $PACKAGE '[ .monitors[] | select( .name | contains($PACKAGE))]')
echo "Found the following monitors:"
echo "$MONITORS" | jq -r '.[].name'
for file in *; do
IFS_HOLD=$IFS
IFS=$'\n'
for type in $(echo "$MONITORS" | jq -r '.[].name'); do
MONITOR_NAME=$(cat $file | jq -r '.name')
echo "Comparing '$MONITOR_NAME' and '$type'"
if [ "$MONITOR_NAME" == $type ]; then
echo "Found monitor for $file"
UPTIME_CHECK=false
continue 2
fi
done
IFS=$IFS_HOLD
echo "Missing monitor for $file"
RESPONSE=$(curl -X POST "${UPTIMEKUMA_URL}/monitors" -H 'accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H 'Content-Type: application/json' -d "$(cat $file)" -s)
RESPONSE_MESSAGE=$(echo $RESPONSE | jq -r '.msg')
if [ "$RESPONSE_MESSAGE" == "Added Successfully." ]; then
echo "Created monitor for $file"
UPTIME_CHECK=false
else
echo "Failed creating monitor for $file: $RESPONSE_MESSAGE"
echo "$RESPONSE"
UPTIME_FAILURE=true
fi
done
cd $WORKINGDIR
echo ">>> Exit"
if $URL_CHECK || $URL_FAILURE || $UPTIME_CHECK || $UPTIME_FAILURE; then
echo "Exiting with Errors"
echo "URL_CHECK: $URL_CHECK || URL_FAILURE: $URL_FAILURE || UPTIME_CHECK: $UPTIME_CHECK || UPTIME_FAILURE: $UPTIME_FAILURE"
fi

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -e
sleep 5
echo ">>>> Deploy"
WORKINGDIR=$(pwd)
echo ">>> Files"
if test -d "Files"; then
echo "Found files to copy"
cd Files
for dir in *; do
echo "Copying files for $dir"
FILE_PATH="/var/lib/docker/volumes/partition/"
echo "Copying directory '$dir' to $FILE_PATH"
rsync --rsync-path="sudo rsync" --progress -aiv $dir drone@$HOST_IP:$FILE_PATH
ssh drone@$HOST_IP "sudo chown -R alexlebens:alexlebens $FILE_PATH/$dir"
# ssh drone@$HOST_IP "sudo chmod -R 600 $FILE_PATH/$dir"
done
echo "Finished copying files"
cd $WORKINGDIR
else
echo "No files to copy"
fi
echo ">>> Compose"
if ! test -f "./docker-compose.yml"
then
echo ">> ERROR: No docker-compose.yml in directory"
continue
fi
echo ">> Deploy"
docker compose --project-name $(echo $PACKAGE | tr "[:upper:]" "[:lower:]") stop
sleep 10
docker compose --project-name $(echo $PACKAGE | tr "[:upper:]" "[:lower:]") up --wait
sleep 1

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
sleep 5
echo ">>>> Tests"
echo ">>> Syntax Check"
if ! test -f "./docker-compose.yml"
then
echo ">> ERROR: No docker-compose.yml in directory"
continue
fi
echo ">> Syntax check"
docker compose convert -q
echo "Passed syntax check"