From 5412594a8d72c125708f1b3942f01ca98939a013 Mon Sep 17 00:00:00 2001 From: Gerd Oberlechner Date: Fri, 25 Oct 2024 15:41:02 +0200 Subject: [PATCH] templatize only Makefile include not makefile itself Signed-off-by: Gerd Oberlechner --- backend/.gitignore | 2 +- backend/{Makefile.tmpl.mk => Makefile} | 19 ++++++---- backend/README.md | 11 ------ backend/config.tmpl.mk | 5 +++ backend/generate-makefile.sh | 12 ------- cluster-service/.gitignore | 2 +- cluster-service/Makefile | 48 +++++++++++++++++++++++++ cluster-service/Makefile.tmpl.mk | 44 ----------------------- cluster-service/config.tmpl.mk | 13 +++++++ frontend/.gitignore | 2 +- frontend/{Makefile.tmpl.mk => Makefile} | 19 ++++++---- frontend/README.md | 10 ------ frontend/config.tmpl.mk | 5 +++ frontend/generate-makefile.sh | 12 ------- 14 files changed, 98 insertions(+), 106 deletions(-) rename backend/{Makefile.tmpl.mk => Makefile} (69%) delete mode 100644 backend/README.md create mode 100644 backend/config.tmpl.mk delete mode 100755 backend/generate-makefile.sh create mode 100644 cluster-service/Makefile delete mode 100644 cluster-service/Makefile.tmpl.mk create mode 100644 cluster-service/config.tmpl.mk rename frontend/{Makefile.tmpl.mk => Makefile} (72%) create mode 100644 frontend/config.tmpl.mk delete mode 100755 frontend/generate-makefile.sh diff --git a/backend/.gitignore b/backend/.gitignore index f3c7a7c5d..aee2e4ce1 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1 +1 @@ -Makefile +config.mk diff --git a/backend/Makefile.tmpl.mk b/backend/Makefile similarity index 69% rename from backend/Makefile.tmpl.mk rename to backend/Makefile index 16c26adb7..de731f4ef 100644 --- a/backend/Makefile.tmpl.mk +++ b/backend/Makefile @@ -1,14 +1,19 @@ SHELL = /bin/bash +DEPLOY_ENV ?= personal-dev + +$(shell ../templatize.sh $(DEPLOY_ENV) config.tmpl.mk config.mk) + +include config.mk COMMIT = $(shell git rev-parse --short=7 HEAD) -ARO_HCP_BASE_IMAGE ?= {{ .acrName }}.azurecr.io +ARO_HCP_BASE_IMAGE ?= ${ARO_HCP_IMAGE_ACR}.azurecr.io ARO_HCP_BACKEND_IMAGE ?= $(ARO_HCP_BASE_IMAGE)/arohcpbackend:$(COMMIT) backend: go build -o aro-hcp-backend . run: - ./aro-hcp-backend --location {{ .region }} \ + ./aro-hcp-backend --location ${LOCATION} \ --clusters-service-url http://localhost:8000 clean: @@ -24,20 +29,20 @@ push: image deploy: BACKEND_MI_CLIENT_ID=$(shell az identity show \ - -g {{ .serviceClusterRG }} \ + -g ${RESOURCEGROUP} \ -n backend \ --query clientId);\ - ISTO_VERSION=$(shell az aks show -n {{ .aksName }} -g {{ .serviceClusterRG }} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ + ISTO_VERSION=$(shell az aks show -n ${AKS_NAME} -g ${RESOURCEGROUP} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ kubectl create namespace aro-hcp --dry-run=client -o json | kubectl apply -f - && \ kubectl label namespace aro-hcp "istio.io/rev=$${ISTO_VERSION}" --overwrite=true && \ helm upgrade --install aro-hcp-backend-dev \ deploy/helm/backend/ \ - --set configMap.databaseName={{ .frontendCosmosDBName }} \ - --set configMap.databaseUrl="https://{{ .frontendCosmosDBName }}.documents.azure.com:443/" \ + --set configMap.databaseName=${DB_NAME} \ + --set configMap.databaseUrl="https://${DB_NAME}.documents.azure.com:443/" \ --set configMap.backendMiClientId="$${BACKEND_MI_CLIENT_ID}" \ --set serviceAccount.workloadIdentityClientId="$${BACKEND_MI_CLIENT_ID}" \ --set configMap.currentVersion=${ARO_HCP_BACKEND_IMAGE} \ - --set configMap.location={{ .region }} \ + --set configMap.location=${LOCATION} \ --set deployment.imageName=${ARO_HCP_BACKEND_IMAGE} \ --namespace aro-hcp diff --git a/backend/README.md b/backend/README.md deleted file mode 100644 index e927d424c..000000000 --- a/backend/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# ARO-HCP-BACKEND - -## Prerequisite - -The `Makefile` is templated based on the ARO HCP environment to interact with. - -Run the following command to generate a `Makefile` for personal development. - -```bash -./generate-makefile.sh personal-dev -``` diff --git a/backend/config.tmpl.mk b/backend/config.tmpl.mk new file mode 100644 index 000000000..9b959270f --- /dev/null +++ b/backend/config.tmpl.mk @@ -0,0 +1,5 @@ +ARO_HCP_IMAGE_ACR ?= {{ .acrName }} +LOCATION ?= {{ .region }} +RESOURCEGROUP ?= {{ .serviceClusterRG }} +AKS_NAME ?= {{ .aksName }} +DB_NAME ?= {{ .frontendCosmosDBName }} diff --git a/backend/generate-makefile.sh b/backend/generate-makefile.sh deleted file mode 100755 index c989811cc..000000000 --- a/backend/generate-makefile.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -if [ -z "$1" ]; then - DEPLOY_ENV="personal-dev" -else - DEPLOY_ENV=$1 -fi - -cd $(dirname "$(realpath "${BASH_SOURCE[0]}")") -../templatize.sh $DEPLOY_ENV Makefile.tmpl.mk Makefile diff --git a/cluster-service/.gitignore b/cluster-service/.gitignore index 543d79940..1e48811d8 100644 --- a/cluster-service/.gitignore +++ b/cluster-service/.gitignore @@ -1,2 +1,2 @@ deploy/tmp-provisioning-shard.yml -Makefile +config.mk diff --git a/cluster-service/Makefile b/cluster-service/Makefile new file mode 100644 index 000000000..14d496910 --- /dev/null +++ b/cluster-service/Makefile @@ -0,0 +1,48 @@ +SHELL = /bin/bash +DEPLOY_ENV ?= personal-dev + +$(shell ../templatize.sh $(DEPLOY_ENV) config.tmpl.mk config.mk) + +include config.mk + +ZONE_RESOURCE_ID ?= $(shell az network dns zone show -n ${DNS_ZONE_NAME} -g ${REGIONAL_RESOURCEGROUP} --query id -o tsv) + +deploy: + sed -e "s#ZONE_RESOURCE_ID#${ZONE_RESOURCE_ID}#g" -e "s/REGION/${REGION}/g" -e "s/CONSUMER_NAME/${CONSUMER_NAME}/g" deploy/mvp-provisioning-shards.yml > deploy/tmp-provisioning-shard.yml + + ISTO_VERSION=$(shell az aks show -n ${AKS_NAME} -g ${RESOURCEGROUP} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ + oc process --local -f deploy/openshift-templates/arohcp-namespace-template.yml \ + -p ISTIO_VERSION=$${ISTO_VERSION} | oc apply -f - + kubectl apply -f deploy/istio.yml + + oc process --local -f deploy/openshift-templates/arohcp-db-template.yml | oc apply -f - + oc process --local -f deploy/openshift-templates/arohcp-secrets-template.yml \ + -p PROVISION_SHARDS_CONFIG="$$( base64 -i deploy/tmp-provisioning-shard.yml)" | oc apply -f - + + AZURE_CS_MI_CLIENT_ID=$(shell az identity show -g ${RESOURCEGROUP} -n clusters-service --query clientId -o tsv) && \ + CS_SERVICE_PRINCIPAL_CREDS_BASE64='$(shell az keyvault secret show --vault-name "${SERVICE_KV}" --name "aro-hcp-dev-sp-cs" | jq .value -r | base64 | tr -d '\n')' && \ + TENANT_ID=$(shell az account show --query tenantId --output tsv) && \ + OIDC_BLOB_SERVICE_ENDPOINT=$(shell az storage account show -n ${OIDC_STORAGE_ACCOUNT} -g ${RESOURCEGROUP} --query primaryEndpoints.blob -o tsv) && \ + OIDC_WEB_SERVICE_ENDPOINT=$(shell az storage account show -n ${OIDC_STORAGE_ACCOUNT} -g ${RESOURCEGROUP} --query primaryEndpoints.web -o tsv) && \ + oc process --local -f deploy/openshift-templates/arohcp-service-template.yml \ + -p AZURE_CS_MI_CLIENT_ID=$${AZURE_CS_MI_CLIENT_ID} \ + -p TENANT_ID=$${TENANT_ID} \ + -p REGION=${REGION} \ + -p SERVICE_KEYVAULT_NAME=${SERVICE_KV} \ + -p CS_SERVICE_PRINCIPAL_CREDS_BASE64=$${CS_SERVICE_PRINCIPAL_CREDS_BASE64} \ + -p IMAGE_REGISTRY=${ACR_NAME}.azurecr.io \ + -p IMAGE_REPOSITORY=${IMAGE_REPO} \ + -p AZURE_FIRST_PARTY_APPLICATION_CLIENT_ID=${FPA_CLIENT_ID} \ + -p FPA_CERT_NAME=${FPA_CERT_NAME} \ + -p IMAGE_TAG=${IMAGE_TAG} | oc apply -f - + +deploy-pr-env-deps: + AZURE_CS_MI_CLIENT_ID=$(shell az identity show -g ${RESOURCEGROUP} -n clusters-service --query clientId -o tsv) && \ + oc process --local -f deploy/integration/cluster-service-namespace.yaml \ + -p CLIENT_ID=${AZURE_CS_MI_CLIENT_ID} | oc apply -f - + +# for local development +provision-shard: + sed -e "s#ZONE_RESOURCE_ID#${ZONE_RESOURCE_ID}#g" -e "s/REGION/${REGION}/g" -e "s/CONSUMER_NAME/${CONSUMER_NAME}/g" deploy/dev-provisioning-shards.yml + +.PHONY: deploy deploy-integ provision-shard diff --git a/cluster-service/Makefile.tmpl.mk b/cluster-service/Makefile.tmpl.mk deleted file mode 100644 index 1b59ff3a1..000000000 --- a/cluster-service/Makefile.tmpl.mk +++ /dev/null @@ -1,44 +0,0 @@ -SHELL = /bin/bash - -TENANT_ID=$(shell az account show --query tenantId --output tsv) -ZONE_RESOURCE_ID ?= $(az network dns zone show -n {{ .regionalDNSSubdomain }}.{{ .baseDnsZoneName }} -g {{ .regionRG }} --query id -o tsv) - -FPA_CERT_NAME ?= firstPartyCert - -deploy: - sed -e "s#ZONE_RESOURCE_ID#${ZONE_RESOURCE_ID}#g" -e "s/REGION/{{ .region }}/g" -e "s/CONSUMER_NAME/{{ .maestroConsumerName }}/g" deploy/mvp-provisioning-shards.yml > deploy/tmp-provisioning-shard.yml - - ISTO_VERSION=$(shell az aks show -n {{ .aksName }} -g {{ .serviceClusterRG }} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ - oc process --local -f deploy/openshift-templates/arohcp-namespace-template.yml \ - -p ISTIO_VERSION=$${ISTO_VERSION} | oc apply -f - - kubectl apply -f deploy/istio.yml - - oc process --local -f deploy/openshift-templates/arohcp-db-template.yml | oc apply -f - - oc process --local -f deploy/openshift-templates/arohcp-secrets-template.yml \ - -p PROVISION_SHARDS_CONFIG="$$( base64 -i deploy/tmp-provisioning-shard.yml)" | oc apply -f - - - CS_MI_CLIENT_ID=$(shell az identity show -g "{{ .serviceClusterRG }}" -n clusters-service --query clientId -o tsv) && \ - CS_SERVICE_PRINCIPAL_CREDS_BASE64='$(shell az keyvault secret show --vault-name "{{ .serviceKeyVaultName }}" --name "aro-hcp-dev-sp-cs" | jq .value -r | base64 | tr -d '\n')' && \ - OIDC_BLOB_SERVICE_ENDPOINT=$(shell az storage account show -n {{ .oidcStorageAccountName }} -g {{ .serviceClusterRG }} --query primaryEndpoints.blob -o tsv) && \ - OIDC_WEB_SERVICE_ENDPOINT=$(shell az storage account show -n {{ .oidcStorageAccountName }} -g {{ .serviceClusterRG }} --query primaryEndpoints.web -o tsv) && \ - oc process --local -f deploy/openshift-templates/arohcp-service-template.yml \ - -p AZURE_CS_MI_CLIENT_ID=$${CS_MI_CLIENT_ID} \ - -p TENANT_ID=${TENANT_ID} \ - -p REGION={{ .region }} \ - -p SERVICE_KEYVAULT_NAME={{ .serviceKeyVaultName }} \ - -p CS_SERVICE_PRINCIPAL_CREDS_BASE64=$${CS_SERVICE_PRINCIPAL_CREDS_BASE64} \ - -p IMAGE_REGISTRY={{ .acrName }}.azurecr.io \ - -p IMAGE_REPOSITORY={{ .clusterServiceImageRepo }} \ - -p AZURE_FIRST_PARTY_APPLICATION_CLIENT_ID={{ .firstPartyAppClientId }} \ - -p FPA_CERT_NAME=${FPA_CERT_NAME} \ - -p IMAGE_TAG={{ .clusterServiceImageTag }} | oc apply -f - - -deploy-pr-env-deps: - oc process --local -f deploy/integration/cluster-service-namespace.yaml \ - -p CLIENT_ID=${CS_MI_CLIENT_ID} | oc apply -f - - -# for local development -provision-shard: - sed -e "s#ZONE_RESOURCE_ID#${ZONE_RESOURCE_ID}#g" -e "s/REGION/{{ .region }}/g" -e "s/CONSUMER_NAME/{{ .maestroConsumerName }}/g" deploy/dev-provisioning-shards.yml - -.PHONY: deploy deploy-integ provision-shard diff --git a/cluster-service/config.tmpl.mk b/cluster-service/config.tmpl.mk new file mode 100644 index 000000000..ccb07fd36 --- /dev/null +++ b/cluster-service/config.tmpl.mk @@ -0,0 +1,13 @@ +REGION ?= {{ .region }} +CONSUMER_NAME ?= {{ .maestroConsumerName }} +RESOURCEGROUP ?= {{ .serviceClusterRG }} +REGIONAL_RESOURCEGROUP ?= {{ .regionRG }} +AKS_NAME ?= {{ .aksName }} +SERVICE_KV ?= {{ .serviceKeyVaultName }} +OIDC_STORAGE_ACCOUNT ?= {{ .oidcStorageAccountName }} +IMAGE_REPO ?= {{ .clusterServiceImageRepo }} +IMAGE_TAG ?= {{ .clusterServiceImageTag }} +ACR_NAME ?= {{ .acrName }} +FPA_CLIENT_ID ?= {{ .firstPartyAppClientId }} +DNS_ZONE_NAME ?= {{ .regionalDNSSubdomain }}.{{ .baseDnsZoneName }} +FPA_CERT_NAME ?= firstPartyCert diff --git a/frontend/.gitignore b/frontend/.gitignore index f3c7a7c5d..aee2e4ce1 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1 +1 @@ -Makefile +config.mk diff --git a/frontend/Makefile.tmpl.mk b/frontend/Makefile similarity index 72% rename from frontend/Makefile.tmpl.mk rename to frontend/Makefile index 38969f765..42d6240b5 100644 --- a/frontend/Makefile.tmpl.mk +++ b/frontend/Makefile @@ -1,14 +1,19 @@ SHELL = /bin/bash +DEPLOY_ENV ?= personal-dev + +$(shell ../templatize.sh $(DEPLOY_ENV) config.tmpl.mk config.mk) + +include config.mk COMMIT = $(shell git rev-parse --short=7 HEAD) -ARO_HCP_BASE_IMAGE ?= {{ .acrName }}.azurecr.io +ARO_HCP_BASE_IMAGE ?= ${ARO_HCP_IMAGE_ACR}.azurecr.io ARO_HCP_FRONTEND_IMAGE ?= $(ARO_HCP_BASE_IMAGE)/arohcpfrontend:$(COMMIT) frontend: go build -o aro-hcp-frontend . run: - ./aro-hcp-frontend --use-cache --location {{ .region }} \ + ./aro-hcp-frontend --use-cache --location ${LOCATION} \ --clusters-service-url http://localhost:8000 \ --cluster-service-provision-shard 1 \ --cluster-service-noop-provision \ @@ -29,20 +34,20 @@ push: image deploy: FRONTEND_MI_CLIENT_ID=$(shell az identity show \ - -g {{ .serviceClusterRG }} \ + -g ${RESOURCEGROUP} \ -n frontend \ --query clientId);\ - ISTO_VERSION=$(shell az aks show -n {{ .aksName }} -g {{ .serviceClusterRG }} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ + ISTO_VERSION=$(shell az aks show -n ${AKS_NAME} -g ${RESOURCEGROUP} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \ kubectl create namespace aro-hcp --dry-run=client -o json | kubectl apply -f - && \ kubectl label namespace aro-hcp "istio.io/rev=$${ISTO_VERSION}" --overwrite=true && \ helm upgrade --install aro-hcp-frontend-dev \ deploy/helm/frontend/ \ - --set configMap.databaseName={{ .frontendCosmosDBName }} \ - --set configMap.databaseUrl="https://{{ .frontendCosmosDBName }}.documents.azure.com:443/" \ + --set configMap.databaseName=${DB_NAME} \ + --set configMap.databaseUrl="https://${DB_NAME}.documents.azure.com:443/" \ --set configMap.frontendMiClientId="$${FRONTEND_MI_CLIENT_ID}" \ --set serviceAccount.workloadIdentityClientId="$${FRONTEND_MI_CLIENT_ID}" \ --set configMap.currentVersion=${ARO_HCP_FRONTEND_IMAGE} \ - --set configMap.location={{ .region }} \ + --set configMap.location=${LOCATION} \ --set deployment.imageName=${ARO_HCP_FRONTEND_IMAGE} \ --namespace aro-hcp diff --git a/frontend/README.md b/frontend/README.md index 608034396..8130b3a46 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,15 +1,5 @@ # ARO-HCP-FRONTEND -## Prerequisite - -The `Makefile` is templated based on the ARO HCP environment to interact with. - -Run the following command to generate a `Makefile` for personal development. - -```bash -./generate-makefile.sh personal-dev -``` - ## Build frontend binary for local testing ``` make frontend diff --git a/frontend/config.tmpl.mk b/frontend/config.tmpl.mk new file mode 100644 index 000000000..9b959270f --- /dev/null +++ b/frontend/config.tmpl.mk @@ -0,0 +1,5 @@ +ARO_HCP_IMAGE_ACR ?= {{ .acrName }} +LOCATION ?= {{ .region }} +RESOURCEGROUP ?= {{ .serviceClusterRG }} +AKS_NAME ?= {{ .aksName }} +DB_NAME ?= {{ .frontendCosmosDBName }} diff --git a/frontend/generate-makefile.sh b/frontend/generate-makefile.sh deleted file mode 100755 index c989811cc..000000000 --- a/frontend/generate-makefile.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -if [ -z "$1" ]; then - DEPLOY_ENV="personal-dev" -else - DEPLOY_ENV=$1 -fi - -cd $(dirname "$(realpath "${BASH_SOURCE[0]}")") -../templatize.sh $DEPLOY_ENV Makefile.tmpl.mk Makefile