Skip to content

Commit

Permalink
poc makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Nov 20, 2024
1 parent 826de06 commit 658e250
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 67 deletions.
39 changes: 33 additions & 6 deletions backend/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,56 @@
SHELL = /bin/bash
DEPLOY_ENV ?= personal-dev
$(shell ../templatize.sh $(DEPLOY_ENV) config.tmpl.mk config.mk)
include config.mk
include Makefile.deploy
SHELLFLAGS = -eu -o pipefail -c
include ../setup-env.mk

COMMIT ?= $(shell git rev-parse --short=7 HEAD)
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 .
.PHONY: backend

run:
./aro-hcp-backend --location ${LOCATION} \
--clusters-service-url http://localhost:8000
.PHONY: run

clean:
rm -f aro-hcp-backend
.PHONY: clean

image:
pushd .. && git archive --output backend/archive.tar.gz HEAD && popd
docker build -f "./Dockerfile" -t ${ARO_HCP_BACKEND_IMAGE} .
rm -f archive.tar.gz
.PHONY: image

push: image
az acr login --name ${ARO_HCP_IMAGE_ACR}
docker push ${ARO_HCP_BACKEND_IMAGE}
.PHONY: push

deploy:
BACKEND_MI_CLIENT_ID=$$(az identity show \
-g ${RESOURCEGROUP} \
-n backend \
--query clientId);\
ISTO_VERSION=$$(az aks show -n ${AKS_NAME} -g ${RESOURCEGROUP} --query serviceMeshProfile.istio.revisions[-1] -o tsv) && \
DB_URL=$$(az cosmosdb show -n ${DB_NAME} -g ${RESOURCEGROUP} --query documentEndpoint -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=${DB_NAME} \
--set configMap.databaseUrl="$${DB_URL}" \
--set configMap.backendMiClientId="$${BACKEND_MI_CLIENT_ID}" \
--set serviceAccount.workloadIdentityClientId="$${BACKEND_MI_CLIENT_ID}" \
--set configMap.currentVersion=${ARO_HCP_BACKEND_IMAGE} \
--set configMap.location=${LOCATION} \
--set deployment.imageName=${ARO_HCP_BACKEND_IMAGE} \
--namespace aro-hcp
.PHONY: deploy

undeploy:
helm uninstall aro-hcp-backend-dev --namespace aro-hcp

.PHONY: backend run clean image push undeploy
.PHONY: undeploy
26 changes: 0 additions & 26 deletions backend/Makefile.deploy

This file was deleted.

2 changes: 2 additions & 0 deletions dev-infrastructure/region-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ resourceGroups:
action: ARM
template: modules/modules/metrics.bicep
parameters: configurations/metrics.tmpl.bicepparam
dependsOn:
- region
2 changes: 2 additions & 0 deletions dev-infrastructure/svc-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ resourceGroups:
configRef: monitoringWorkspaceName
- name: GRAFANA_NAME
configRef: grafanaName
dependsOn:
- region
19 changes: 19 additions & 0 deletions setup-env.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT_ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

DEPLOY_ENV ?= personal-dev
PIPELINE ?= pipeline.yaml
PIPELINE_STEP ?= deploy
HASH = $(shell echo -n "$(DEPLOY_ENV)$(PIPELINE)$(PIPELINE_STEP)" | md5)
ENV_VARS_FILE ?= /tmp/deploy.${HASH}.cfg

# Target to generate the environment variables file
$(ENV_VARS_FILE): ${PROJECT_ROOT_DIR}/config/config.yaml ${PIPELINE} ${PROJECT_ROOT_DIR}/templatize.sh ${MAKEFILE_LIST}
@echo "generate env vars"
@${PROJECT_ROOT_DIR}/templatize.sh ${DEPLOY_ENV} \
-p ${PIPELINE} \
-s ${PIPELINE_STEP} > $@

# Include the environment variables file if it exists
ifndef EV2
-include ${ENV_VARS_FILE}
endif
32 changes: 30 additions & 2 deletions templatize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ usage() {
echo " deploy_env Deployment environment"
echo " input Optional input file"
echo " output Optional output file"
echo " -i Set the input file same as second arg"
echo " -o Set the output file same as third arg"
echo " -c Set the cloud (default: public)"
echo " -r Set the region (default: westus3)"
echo " -x Set the cxstamp (default: 1)"
echo " -e Extra args for config interpolation"
echo " -p Pipeline to inspect"
echo " -s Pipeline step to inspect"
exit 1
}

Expand All @@ -41,7 +45,7 @@ if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then
fi

# Parse optional flags
while getopts "c:r:x:e:" opt; do
while getopts "c:r:x:e:i:o:p:s:" opt; do
case ${opt} in
c)
CLOUD=${OPTARG}
Expand All @@ -55,6 +59,18 @@ while getopts "c:r:x:e:" opt; do
e)
EXTRA_ARGS="--extra-args ${OPTARG}"
;;
i)
INPUT=${OPTARG}
;;
o)
OUTPUT=${OPTARG}
;;
p)
PIPELINE=${OPTARG}
;;
s)
PIPELINE_STEP=${OPTARG}
;;
*)
usage
;;
Expand Down Expand Up @@ -96,7 +112,8 @@ else
REGION_STAMP="${CLEAN_DEPLOY_ENV}"
fi

TEMPLATIZE="go run ${PROJECT_ROOT_DIR}/tooling/templatize"
make -s -C ${PROJECT_ROOT_DIR}/tooling/templatize templatize
TEMPLATIZE="${PROJECT_ROOT_DIR}/tooling/templatize/templatize"

CONFIG_FILE=${PROJECT_ROOT_DIR}/config/config.yaml
if [ -n "$INPUT" ] && [ -n "$OUTPUT" ]; then
Expand All @@ -110,6 +127,17 @@ if [ -n "$INPUT" ] && [ -n "$OUTPUT" ]; then
--input=${INPUT} \
--output=${OUTPUT} \
${EXTRA_ARGS}
elif [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then
$TEMPLATIZE run-pipeline \
--config-file=${CONFIG_FILE} \
--cloud=${CLOUD} \
--deploy-env=${DEPLOY_ENV} \
--region=${REGION} \
--region-short=${REGION_STAMP} \
--stamp=${CXSTAMP} \
--pipeline-file=${PIPELINE} \
--step=${PIPELINE_STEP} \
--dump-step-vars
else
$TEMPLATIZE inspect \
--config-file=${CONFIG_FILE} \
Expand Down
24 changes: 0 additions & 24 deletions tooling/templatize/gerd-param.json

This file was deleted.

6 changes: 3 additions & 3 deletions tooling/templatize/pkg/aks/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func EnsureClusterAdmin(ctx context.Context, kubeconfigPath, subscriptionID, res
}

// Validate assignment
err = TestClusterAdminPermissions(ctx, kubeconfigPath)
err = CheckClusterAdminPermissions(ctx, kubeconfigPath)
if err == nil {
return nil
}
Expand All @@ -66,7 +66,7 @@ func EnsureClusterAdmin(ctx context.Context, kubeconfigPath, subscriptionID, res
case <-timeout:
return fmt.Errorf("timed out waiting for role assignment to be effective")
case <-ticker.C:
err = TestClusterAdminPermissions(ctx, kubeconfigPath)
err = CheckClusterAdminPermissions(ctx, kubeconfigPath)
if err == nil {
fmt.Println("Cluster admin permissions are now effective")
return nil
Expand All @@ -76,7 +76,7 @@ func EnsureClusterAdmin(ctx context.Context, kubeconfigPath, subscriptionID, res
}
}

func TestClusterAdminPermissions(ctx context.Context, kubeconfigPath string) error {
func CheckClusterAdminPermissions(ctx context.Context, kubeconfigPath string) error {
clientset, err := createKubeClient(kubeconfigPath)
if err != nil {
return fmt.Errorf("failed to create Kubernetes client: %w", err)
Expand Down
6 changes: 0 additions & 6 deletions tooling/templatize/test.mk

This file was deleted.

0 comments on commit 658e250

Please sign in to comment.