mirror of
https://github.com/Cian-H/am-d-model.eu.git
synced 2025-12-22 21:41:57 +00:00
This reverts commita48effcdfe. Revert "Test of monolithic caddyfile" This reverts commitdb65bf7e7b. Revert "Added quick log fetch command to justfile" This reverts commit24e6305d73. Revert "Caddy config tweak for sockets and uwsgi protocol" This reverts commit40ff7a3c39.
86 lines
2.4 KiB
Makefile
86 lines
2.4 KiB
Makefile
update auto-rollback="false":
|
|
#!/usr/bin/env bash
|
|
if [ ! -f update.lock ]; then
|
|
touch update.lock
|
|
just tag-version
|
|
docker compose down
|
|
git pull
|
|
docker compose pull
|
|
docker compose build
|
|
docker compose up -d --wait
|
|
rm update.lock
|
|
if [ "{{auto-rollback}}" = "true" ]; then
|
|
just healthcheck || just rollback
|
|
else
|
|
just healthcheck || echo "Healthcheck failed. Consider rolling back by running \"just rollback\" manually if needed."
|
|
fi
|
|
else
|
|
echo "Update already in progress"
|
|
fi
|
|
|
|
merge-and-push-prod:
|
|
#!/usr/bin/env bash
|
|
git switch prod
|
|
git merge main
|
|
git switch main
|
|
git push --all
|
|
|
|
remote-update:
|
|
#!/usr/bin/env bash
|
|
just merge-and-push-prod
|
|
ssh am-d-model_eu "cd am-d-model.eu && just update auto-rollback=true"
|
|
|
|
tag-version:
|
|
#!/usr/bin/env bash
|
|
git tag backup-$(date +%Y%m%d-%H%M%S)
|
|
mkdir -p versions
|
|
docker compose images | grep -v "REPOSITORY" > versions/$(date +%Y%m%d-%H%M%S).txt
|
|
|
|
healthcheck:
|
|
#!/usr/bin/env bash
|
|
for i in 1 2 3; do
|
|
curl -f http://localhost/health && exit 0
|
|
sleep 5
|
|
done
|
|
exit 1
|
|
|
|
rollback version="":
|
|
#!/usr/bin/env bash
|
|
current_branch=$(git branch --show-current)
|
|
if [ -z "{{version}}" ]; then # Get last backup tag if no version specified
|
|
version=$(git tag | grep backup | sort -r | head -n1)
|
|
else # Or get the specified version
|
|
version="backup-{{version}}"
|
|
fi
|
|
|
|
# Find corresponding version file
|
|
version_date=${version#backup-} # Remove 'backup-' prefix
|
|
version_file="versions/$version_date.txt"
|
|
|
|
if [ ! -f "$version_file" ]; then
|
|
echo "No version file found for $version"
|
|
exit 1
|
|
fi
|
|
|
|
# Read the old image versions and pull them specifically
|
|
while read -r repo tag image_id _; do
|
|
if [ ! -z "$repo" ]; then
|
|
docker pull "$repo:$tag"
|
|
fi
|
|
done < "$version_file"
|
|
|
|
# Then check out the version and update
|
|
git checkout $version
|
|
docker compose down
|
|
docker compose build --no-cache
|
|
docker compose up -d
|
|
git switch $current_branch # Return to original branch
|
|
|
|
cleanup-versions:
|
|
#!/usr/bin/env bash
|
|
# Keep last 5 backup tags
|
|
for tag in $(git tag | grep backup | sort -r | tail -n +6); do
|
|
git tag -d $tag
|
|
rm -f "versions/${tag#backup-}.txt"
|
|
done
|