gitea-webhook-listener/build.sh

46 lines
1.5 KiB
Bash
Raw Normal View History

2024-05-05 22:54:06 +02:00
#!/bin/bash
# Define variables
IMAGE_NAME="gitea-webhook-listener"
DOCKERFILE_PATH="./"
VERSION_FILE="version.txt"
REGISTRY="registry.fungimail.llc"
NAMESPACE="urko"
# Version management
if [ ! -f "$VERSION_FILE" ]; then
echo "Version file not found, creating one with version 1..."
echo "1" > $VERSION_FILE
fi
VERSION=$(cat $VERSION_FILE)
echo "Current version is $VERSION."
# Increment the version
VERSION=$((VERSION+1))
echo "Incrementing to new version $VERSION..."
echo $VERSION > $VERSION_FILE
# Step 1: Build the Docker image with the new version tag
echo "Building Docker image $IMAGE_NAME:$VERSION..."
docker build -t $IMAGE_NAME:$VERSION $DOCKERFILE_PATH
# Step 1b: Tag the image for the registry with version
FULL_IMAGE_NAME_VERSION="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${VERSION}"
echo "Tagging image for registry as $FULL_IMAGE_NAME_VERSION..."
docker tag $IMAGE_NAME:$VERSION $FULL_IMAGE_NAME_VERSION
# Step 1c: Tag the image for the registry with 'latest'
FULL_IMAGE_NAME_LATEST="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:latest"
echo "Tagging image for registry as $FULL_IMAGE_NAME_LATEST..."
docker tag $IMAGE_NAME:$VERSION $FULL_IMAGE_NAME_LATEST
# Step 1d: Push the versioned image to the Docker registry
echo "Pushing $FULL_IMAGE_NAME_VERSION to the Docker registry..."
docker push $FULL_IMAGE_NAME_VERSION
# Step 1e: Push the latest image to the Docker registry
echo "Pushing $FULL_IMAGE_NAME_LATEST to the Docker registry..."
docker push $FULL_IMAGE_NAME_LATEST