#!/usr/bin/env bash # # A script to build and push the Docker image to a Gitea container registry. # # Usage: # export GITEA_REPO_URL="https://git.example.com/user/repo" # ./scripts/deploy.sh # # Example: # ./scripts/deploy.sh v1.0.1 # set -euo pipefail # Check that the required GITEA_REPO_URL is set. if [ -z "${GITEA_REPO_URL:-}" ]; then echo "Error: GITEA_REPO_URL environment variable is not set." echo "Please set it to your full repository URL (e.g., https://gitea.com/user/repo)" exit 1 fi # Get the image tag from the first script argument, or default to "latest". readonly IMAGE_TAG="${1:-latest}" echo "--- Preparing for deployment ---" # Extract the registry and repository path from the Gitea URL. readonly GITEA_REGISTRY=$(echo "$GITEA_REPO_URL" | sed -e 's|https://||' -e 's|/.*$||') readonly REPO_PATH=$(echo "$GITEA_REPO_URL" | sed -e 's|https://[^/]*\/||' -e 's|\.git$||') # Construct the full Docker image name and tag. readonly FULL_IMAGE_NAME="${GITEA_REGISTRY}/${REPO_PATH}:${IMAGE_TAG}" # --- Print Summary --- echo "Registry URL: ${GITEA_REGISTRY}" echo "Repository Path: ${REPO_PATH}" echo "Image Tag: ${IMAGE_TAG}" echo "Full Image Name: ${FULL_IMAGE_NAME}" echo "--------------------------------" # --- Execution --- # 1. Log in to the Gitea Docker registry. echo "--> Logging in to Docker registry at ${GITEA_REGISTRY}..." docker login "${GITEA_REGISTRY}" # 2. Build the Docker image with the full name and tag. # We pass the root of the repo as the build context. echo "--> Building image: ${FULL_IMAGE_NAME}..." docker build -t "${FULL_IMAGE_NAME}" -f ./docker/Dockerfile . # 3. Push the built image to the Gitea registry. echo "--> Pushing image to registry..." docker push "${FULL_IMAGE_NAME}" # --- Success Message --- echo echo "> Success! Image has been pushed." echo " You can now pull it using: docker pull ${FULL_IMAGE_NAME}"