Compare commits
1
Commits
ef4db213c7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab87001c77 |
@@ -78,8 +78,22 @@ jobs:
|
|||||||
echo "No previous deploy recorded — nothing to roll back to."
|
echo "No previous deploy recorded — nothing to roll back to."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Clean up dangling (untagged) layers only
|
- name: Clean up dangling (untagged) layers
|
||||||
run: docker image prune -f
|
run: docker image prune -f
|
||||||
# Note: this does NOT remove SHA-tagged images, so rollback targets
|
|
||||||
# stay available. Periodically clean up old SHA tags manually if
|
- name: Prune old SHA-tagged images (keep last 5)
|
||||||
# disk usage grows (e.g. keep the last 10 builds).
|
run: |
|
||||||
|
KEEP=5
|
||||||
|
CURRENT_TAG=$(grep IMAGE_TAG /opt/robot-market-front/.env 2>/dev/null | cut -d= -f2)
|
||||||
|
PREVIOUS_TAG=$(grep IMAGE_TAG /opt/robot-market-front/.env.previous 2>/dev/null | cut -d= -f2)
|
||||||
|
|
||||||
|
docker images robot-market --format '{{.Tag}} {{.CreatedAt}}' \
|
||||||
|
| sort -t" " -k2 -r \
|
||||||
|
| tail -n +$((KEEP + 1)) \
|
||||||
|
| cut -f1 \
|
||||||
|
| while read -r tag; do
|
||||||
|
if [ "$tag" != "$CURRENT_TAG" ] && [ "$tag" != "$PREVIOUS_TAG" ] && [ "$tag" != "<none>" ]; then
|
||||||
|
echo "Removing old image robot-market:$tag"
|
||||||
|
docker rmi "robot-market:$tag" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user