Add script to update Restic and rebuild Docker image
This commit is contained in:
parent
bed20ae9d5
commit
7358e2814a
48
update-restic.sh
Normal file
48
update-restic.sh
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Set variables
|
||||||
|
GIT_REPO="https://git.lehouerou.net/laurent/restic-docker"
|
||||||
|
DOCKER_REGISTRY="registry.lehouerou.net/restic-backup"
|
||||||
|
DOCKERFILE="Dockerfile"
|
||||||
|
EMAIL_RECIPIENT="laurent@lehouerou.net"
|
||||||
|
EMAIL_SUBJECT="Restic Docker image updated"
|
||||||
|
POSTFIX_CONFIG="/etc/postfix/main.cf"
|
||||||
|
|
||||||
|
# Install necessary packages
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git curl jq postfix
|
||||||
|
|
||||||
|
# Configure Postfix if not already configured
|
||||||
|
if ! grep -q "^relayhost" $POSTFIX_CONFIG; then
|
||||||
|
echo "Please configure Postfix and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clone the repository
|
||||||
|
git clone $GIT_REPO
|
||||||
|
cd restic-docker
|
||||||
|
|
||||||
|
# Get the latest version of Restic
|
||||||
|
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/restic/restic/releases/latest" | jq -r .tag_name | tr -d v)
|
||||||
|
|
||||||
|
# Get the current Restic version from the Dockerfile
|
||||||
|
CURRENT_VERSION=$(grep -oP 'ENV RESTIC_VERSION=\K[^"]+' $DOCKERFILE)
|
||||||
|
|
||||||
|
# Compare versions and update Dockerfile if needed
|
||||||
|
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
|
||||||
|
sed -i "s/ENV RESTIC_VERSION=$CURRENT_VERSION/ENV RESTIC_VERSION=$LATEST_VERSION/" $DOCKERFILE
|
||||||
|
|
||||||
|
# Commit the change and push to the repository
|
||||||
|
git add $DOCKERFILE
|
||||||
|
git commit -m "Update Restic to version $LATEST_VERSION"
|
||||||
|
git push
|
||||||
|
|
||||||
|
# Build the new Docker image and push it to the registry
|
||||||
|
docker build -t $DOCKER_REGISTRY:$LATEST_VERSION .
|
||||||
|
docker push $DOCKER_REGISTRY:$LATEST_VERSION
|
||||||
|
|
||||||
|
# Send email notification
|
||||||
|
echo "The Restic Docker image has been updated to version $LATEST_VERSION and pushed to $DOCKER_REGISTRY" | mail -s "$EMAIL_SUBJECT" $EMAIL_RECIPIENT
|
||||||
|
else
|
||||||
|
echo "The Restic Docker image is already up to date (version $CURRENT_VERSION)."
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user