# # Publish to Docker Registry with default values: # user = plastichub # image = kbot # tag = latest # # Usage examples: # 1) Use all defaults: # ./publish_to_registry.sh # 2) Override user: # ./publish_to_registry.sh yourusername # 3) Override user and image: # ./publish_to_registry.sh yourusername your-image # 4) Override user, image, and tag: # ./publish_to_registry.sh yourusername your-image yourtag # # Description: # 1. Builds a Docker image from the current directory’s Dockerfile. # 2. Tags the image with the specified user, image, and tag. # 3. Logs in to Docker Hub (docker.io). # 4. Pushes the image to Docker Hub. # 5. Logs out from Docker Hub. set -e # Exit on error ############################################################################### # Set default values ############################################################################### DEFAULT_USER="plastichub" DEFAULT_IMAGE="kbot" DEFAULT_TAG="latest" ############################################################################### # Parse arguments ############################################################################### # If an argument isn’t provided, use the default. USER="${1:-$DEFAULT_USER}" IMAGE="${2:-$DEFAULT_IMAGE}" TAG="${3:-$DEFAULT_TAG}" ############################################################################### # Additional variables # - You can hard-code your Docker Hub credentials or store them # securely as environment variables / secrets in CI/CD ############################################################################### DOCKER_USERNAME="plastichub" DOCKER_PASSWORD="menMD+cwK$^t55!" ############################################################################### # Build the image ############################################################################### echo "Building Docker image: ${USER}/${IMAGE}:${TAG}" docker build -t "${USER}/${IMAGE}:${TAG}" . ############################################################################### # Docker login ############################################################################### echo "Logging in to Docker Hub as ${DOCKER_USERNAME}" echo "${DOCKER_PASSWORD}" | docker login docker.io --username "${DOCKER_USERNAME}" --password-stdin ############################################################################### # Push the image ############################################################################### echo "Pushing image to docker.io: ${USER}/${IMAGE}:${TAG}" docker push "${USER}/${IMAGE}:${TAG}" ############################################################################### # Logout ############################################################################### echo "Logging out of Docker Hub" docker logout docker.io ##################################