|
| 1 | +# Parameters |
| 2 | +SOURCE_FILES ?= $(shell find . -type f -name '*.bicep' -print) |
| 3 | +OUT_DIR ?= ./artifacts |
| 4 | +BICEP_MAIN ?= ./main.bicep |
| 5 | +BICEP_PARAMETERS ?= ./main.parameters.bicepparam |
| 6 | + |
| 7 | +# Git |
| 8 | +GIT_REVISION ?= $(shell git rev-parse --short HEAD) |
| 9 | +GIT_TAG ?= $(shell git describe --tags --abbrev=0 --always | sed -e s/v//g) |
| 10 | + |
| 11 | +# Azure |
| 12 | +SUBSCRIPTION_ID ?= $(shell az account show --query id --output tsv) |
| 13 | +SUBSCRIPTION_NAME ?= $(shell az account show --query name --output tsv) |
| 14 | +TENANT_ID ?= $(shell az account show --query tenantId --output tsv) |
| 15 | +RESOURCE_GROUP_NAME ?= rg-azure-ai-services-solutions |
| 16 | +LOCATION ?= japaneast |
| 17 | + |
| 18 | +.PHONY: help |
| 19 | +help: |
| 20 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 21 | +.DEFAULT_GOAL := help |
| 22 | + |
| 23 | +.PHONY: info |
| 24 | +info: ## show information |
| 25 | + @echo "GIT_REVISION: $(GIT_REVISION)" |
| 26 | + @echo "GIT_TAG: $(GIT_TAG)" |
| 27 | + @echo "SUBSCRIPTION_ID: $(SUBSCRIPTION_ID)" |
| 28 | + @echo "SUBSCRIPTION_NAME: $(SUBSCRIPTION_NAME)" |
| 29 | + @echo "TENANT_ID: $(TENANT_ID)" |
| 30 | + |
| 31 | +.PHONY: install-deps-dev |
| 32 | +install-deps-dev: ## install dependencies for development |
| 33 | + @which az || echo "Please install Azure CLI: https://github.com/Azure/azure-cli#installation" |
| 34 | + @az bicep upgrade |
| 35 | + |
| 36 | +.PHONY: format |
| 37 | +format: ## format codes |
| 38 | + @$(foreach file,$(SOURCE_FILES),az bicep format --file $(file) --insert-final-newline;) |
| 39 | + |
| 40 | +.PHONY: lint |
| 41 | +lint: ## lint codes |
| 42 | + @echo "lint: Skip since not implemented yet" |
| 43 | + |
| 44 | +.PHONY: build |
| 45 | +build: ## build a bicep file |
| 46 | + @mkdir -p $(OUT_DIR) |
| 47 | + @az bicep build \ |
| 48 | + --file $(BICEP_MAIN) \ |
| 49 | + --outfile $(OUT_DIR)/$(GIT_REVISION).json |
| 50 | + |
| 51 | +.PHONY: test |
| 52 | +test: deployment-what-if ## test codes |
| 53 | + |
| 54 | +.PHONY: ci-test |
| 55 | +ci-test: install-deps-dev lint build test ## ci test |
| 56 | + |
| 57 | +.PHONY: create-resource-group |
| 58 | +create-resource-group: ## create resource group |
| 59 | + az group create \ |
| 60 | + --name $(RESOURCE_GROUP_NAME) \ |
| 61 | + --location $(LOCATION) |
| 62 | + |
| 63 | +.PHONY: delete-resource-group |
| 64 | +delete-resource-group: ## delete resource group |
| 65 | + az group delete --name $(RESOURCE_GROUP_NAME) --yes --no-wait |
| 66 | + |
| 67 | +.PHONY: deployment-what-if |
| 68 | +deployment-what-if: ## execute a deployment What-If operation at resource group scope |
| 69 | + az deployment group what-if \ |
| 70 | + --resource-group $(RESOURCE_GROUP_NAME) \ |
| 71 | + --template-file $(BICEP_MAIN) \ |
| 72 | + --parameters $(BICEP_PARAMETERS) |
| 73 | + |
| 74 | +.PHONY: deployment-create |
| 75 | +deployment-create: ## start a deployment at resource group |
| 76 | + az deployment group create \ |
| 77 | + --resource-group $(RESOURCE_GROUP_NAME) \ |
| 78 | + --template-file $(BICEP_MAIN) \ |
| 79 | + --parameters $(BICEP_PARAMETERS) |
| 80 | + |
| 81 | +.PHONY: deploy |
| 82 | +deploy: create-resource-group deployment-what-if deployment-create ## deploy resources |
| 83 | + |
| 84 | +.PHONY: destroy |
| 85 | +destroy: delete-resource-group ## destroy resources |
0 commit comments