#!/bin/bash set -e # Configuration - Azure Container Registry ACR_NAME="${ACR_NAME:-zuyderlandcmdbacr}" # Pas aan naar jouw ACR naam REGISTRY="${REGISTRY:-${ACR_NAME}.azurecr.io}" REPO_NAME="${REPO_NAME:-cmdb-insight}" VERSION="${1:-latest}" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}════════════════════════════════════════${NC}" echo -e "${GREEN}🐳 Azure Container Registry Build & Push${NC}" echo -e "${BLUE}════════════════════════════════════════${NC}" echo "Registry: ${REGISTRY}" echo "Repository: ${REPO_NAME}" echo "Version: ${VERSION}" echo "" # Check if Azure CLI is installed if ! command -v az &> /dev/null; then echo -e "${RED}❌ Azure CLI is not installed${NC}" echo "Install: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli" exit 1 fi # Check if logged in to Azure if ! az account show &> /dev/null; then echo -e "${YELLOW}⚠️ Not logged in to Azure${NC}" echo "Please login first:" echo " az login" exit 1 fi # Login to ACR (if not already logged in) echo -e "${GREEN}🔐 Logging in to Azure Container Registry...${NC}" az acr login --name ${ACR_NAME} || { echo -e "${YELLOW}⚠️ Could not login to ACR. Trying docker login...${NC}" # Alternative: use Azure credentials az acr credential show --name ${ACR_NAME} --query username -o tsv > /tmp/acr_username.txt 2>/dev/null || true if [ -s /tmp/acr_username.txt ]; then ACR_USERNAME=$(cat /tmp/acr_username.txt) ACR_PASSWORD=$(az acr credential show --name ${ACR_NAME} --query passwords[0].value -o tsv) echo ${ACR_PASSWORD} | docker login ${REGISTRY} -u ${ACR_USERNAME} --password-stdin rm /tmp/acr_username.txt else echo -e "${RED}❌ Could not authenticate with ACR${NC}" exit 1 fi } # Build backend echo "" echo -e "${GREEN}📦 Building backend image...${NC}" docker build -t ${REGISTRY}/${REPO_NAME}/backend:${VERSION} \ -t ${REGISTRY}/${REPO_NAME}/backend:latest \ -f backend/Dockerfile.prod ./backend # Build frontend echo "" echo -e "${GREEN}📦 Building frontend image...${NC}" docker build -t ${REGISTRY}/${REPO_NAME}/frontend:${VERSION} \ -t ${REGISTRY}/${REPO_NAME}/frontend:latest \ -f frontend/Dockerfile.prod ./frontend # Push images echo "" echo -e "${GREEN}📤 Pushing images to Azure Container Registry...${NC}" docker push ${REGISTRY}/${REPO_NAME}/backend:${VERSION} docker push ${REGISTRY}/${REPO_NAME}/backend:latest docker push ${REGISTRY}/${REPO_NAME}/frontend:${VERSION} docker push ${REGISTRY}/${REPO_NAME}/frontend:latest echo "" echo -e "${BLUE}════════════════════════════════════════${NC}" echo -e "${GREEN}✅ Build and push complete!${NC}" echo -e "${BLUE}════════════════════════════════════════${NC}" echo "" echo "Images available at:" echo " Backend: ${REGISTRY}/${REPO_NAME}/backend:${VERSION}" echo " Frontend: ${REGISTRY}/${REPO_NAME}/frontend:${VERSION}" echo "" echo "To view images in Azure Portal:" echo " https://portal.azure.com -> Container registries -> ${ACR_NAME} -> Repositories" echo "" echo "To deploy with docker-compose, update docker-compose.prod.yml with:" echo " backend:" echo " image: ${REGISTRY}/${REPO_NAME}/backend:${VERSION}" echo " frontend:" echo " image: ${REGISTRY}/${REPO_NAME}/frontend:${VERSION}"