- Release script added to tag in both git and docker

This commit is contained in:
Josako
2024-10-17 11:22:18 +02:00
parent 6f71259822
commit a3df9360a6

View File

@@ -0,0 +1,60 @@
#!/bin/bash
# Initialize variables
RELEASE_VERSION=""
RELEASE_MESSAGE=""
DOCKER_ACCOUNT="josakola" # Your Docker account name
# Parse input arguments
while getopts r:m: flag
do
case "${flag}" in
r) RELEASE_VERSION=${OPTARG};;
m) RELEASE_MESSAGE=${OPTARG};;
*)
echo "Usage: $0 -r <release_version> -m <release_message>"
exit 1 ;;
esac
done
# Ensure both version and message are provided
if [ -z "$RELEASE_VERSION" ]; then
echo "Error: Release version not provided. Use -r <release_version>"
exit 1
fi
if [ -z "$RELEASE_MESSAGE" ]; then
echo "Error: Release message not provided. Use -m <release_message>"
exit 1
fi
# Path to your docker-compose file
DOCKER_COMPOSE_FILE="compose_dev.yaml"
# Get all the services defined in the docker-compose file
SERVICES=$(docker-compose -f $DOCKER_COMPOSE_FILE config --services)
# Tag and push images for all services that belong to your Docker account
for SERVICE in $SERVICES; do
DOCKER_IMAGE="your-docker-repo/$SERVICE"
# Check if the image starts with your Docker account name
if [[ $DOCKER_IMAGE == $DOCKER_ACCOUNT* ]]; then
echo "Tagging Docker image for service: $SERVICE with version: $RELEASE_VERSION"
# Tag the 'latest' image with the new release version
docker tag $DOCKER_IMAGE:latest $DOCKER_IMAGE:$RELEASE_VERSION
# Push the newly tagged image to Docker Hub
docker push $DOCKER_IMAGE:$RELEASE_VERSION
else
echo "Skipping service: $SERVICE (not part of Docker account $DOCKER_ACCOUNT)"
fi
done
# Step 3: Tag the Git repository with the release version
echo "Tagging Git repository with version: $RELEASE_VERSION"
git tag -a v$RELEASE_VERSION -m "Release $RELEASE_VERSION: $RELEASE_MESSAGE"
git push origin v$RELEASE_VERSION
echo "Release process completed for version: $RELEASE_VERSION"