diff --git a/Makefile b/Makefile index b83eae268..eae920615 100644 --- a/Makefile +++ b/Makefile @@ -127,12 +127,12 @@ services_all = $(join services_svc,services_mgmt) services_svc_pipelines = frontend %.deploy: $(eval export dirname=$(subst .,/,$(basename $@))) - ./run_pipeline.sh $(DEPLOY_ENV) ./$(dirname)/pipeline.yaml deploy -c public + ./templatize.sh $(DEPLOY_ENV) -p ./$(dirname)/pipeline.yaml -s deploy -P run -c public services_svc_pipelines = frontend %.dry_run: $(eval export dirname=$(subst .,/,$(basename $@))) - ./run_pipeline.sh $(DEPLOY_ENV) ./$(dirname)/pipeline.yaml deploy -c public -d + ./templatize.sh $(DEPLOY_ENV) ./$(dirname)/pipeline.yaml -s deploy -P run -c public -d services_svc_all = $(join services_svc, services_svc_pipelines) diff --git a/run_pipeline.sh b/run_pipeline.sh deleted file mode 100755 index b0354dd48..000000000 --- a/run_pipeline.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash - -PROJECT_ROOT_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") - -# Default values -CLOUD="${CLOUD:-public}" -REGION="${REGION:-westus3}" -CXSTAMP="${CXSTAMP:-1}" -EXTRA_ARGS="" - -# Function to display usage -usage() { - echo "Usage: $0 deploy_env pipeline pipeline_step [-c cloud] [-d] [-r region] [-x cxstamp] [-e]" - echo " deploy_env Deployment environment" - echo " pipeline Pipeline file" - echo " pipeline_step Pipeline step" - echo " -c Set the cloud (default: public)" - echo " -d Dry run" - 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 -} - -# Check if at least one positional argument is provided -if [ "$#" -lt 1 ]; then - usage -fi - -# Positional arguments -DEPLOY_ENV=$1 -shift - -if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then - PIPELINE=$1 - shift -fi - -if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then - PIPELINE_STEP=$1 - shift -fi - - -# Parse optional flags -while getopts "c:dr:x:e:i:o:p:s:" opt; do - case ${opt} in - c) - CLOUD=${OPTARG} - ;; - d) - DRY_RUN="--dry-run" - ;; - r) - REGION=${OPTARG} - ;; - x) - CXSTAMP=${OPTARG} - ;; - e) - EXTRA_ARGS="--extra-args ${OPTARG}" - ;; - p) - PIPELINE=${OPTARG} - ;; - s) - PIPELINE_STEP=${OPTARG} - ;; - *) - usage - ;; - esac -done - -# short names from EV2 prod ServiceConfig -case ${REGION} in - eastus) - REGION_SHORT="use" - ;; - westus) - REGION_SHORT="usw" - ;; - centralus) - REGION_SHORT="usc" - ;; - northcentralus) - REGION_SHORT="usnc" - ;; - southcentralus) - REGION_SHORT="ussc" - ;; - westus2) - REGION_SHORT="usw2" - ;; - westus3) - REGION_SHORT="usw3" - ;; - *) - echo "unsupported region: ${REGION}" - exit 1 -esac - -if [ "$DEPLOY_ENV" == "personal-dev" ]; then - REGION_STAMP="${REGION_SHORT}${USER:0:4}" -else - CLEAN_DEPLOY_ENV=$(echo "${DEPLOY_ENV}" | tr -cd '[:alnum:]') - REGION_STAMP="${CLEAN_DEPLOY_ENV}" -fi - -make -s -C ${PROJECT_ROOT_DIR}/tooling/templatize templatize -TEMPLATIZE="${PROJECT_ROOT_DIR}/tooling/templatize/templatize" - -CONFIG_FILE=${CONFIG_FILE:-${PROJECT_ROOT_DIR}/config/config.yaml} -$TEMPLATIZE pipeline run \ - --config-file=${CONFIG_FILE} \ - --cloud=${CLOUD} \ - --deploy-env=${DEPLOY_ENV} \ - --region=${REGION} \ - --region-short=${REGION_STAMP} \ - --stamp=${CXSTAMP} \ - --pipeline-file=${PIPELINE} \ - --step=${PIPELINE_STEP} \ - ${DRY_RUN} \ No newline at end of file diff --git a/templatize.sh b/templatize.sh index ebc2a8591..c9babd30b 100755 --- a/templatize.sh +++ b/templatize.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -x PROJECT_ROOT_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") # Default values @@ -7,6 +7,8 @@ CLOUD="${CLOUD:-public}" REGION="${REGION:-westus3}" CXSTAMP="${CXSTAMP:-1}" EXTRA_ARGS="" +PIPELINE_MODE="inspect" +DRY_RUN="" # Function to display usage usage() { @@ -14,6 +16,7 @@ usage() { echo " deploy_env Deployment environment" echo " input Optional input file" echo " output Optional output file" + echo " -d Dry run" 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)" @@ -45,11 +48,14 @@ if [ "$#" -ge 1 ] && [[ ! "$1" =~ ^- ]]; then fi # Parse optional flags -while getopts "c:r:x:e:i:o:p:s:" opt; do +while getopts "c:dr:x:e:i:o:p:P:s:" opt; do case ${opt} in c) CLOUD=${OPTARG} ;; + d) + DRY_RUN="--dry-run" + ;; r) REGION=${OPTARG} ;; @@ -68,6 +74,9 @@ while getopts "c:r:x:e:i:o:p:s:" opt; do p) PIPELINE=${OPTARG} ;; + P) + PIPELINE_MODE=${OPTARG} + ;; s) PIPELINE_STEP=${OPTARG} ;; @@ -127,7 +136,7 @@ if [ -n "$INPUT" ] && [ -n "$OUTPUT" ]; then --input=${INPUT} \ --output=${OUTPUT} \ ${EXTRA_ARGS} -elif [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then +elif [ $PIPELINE_MODE == "inspect" ] && [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then $TEMPLATIZE pipeline inspect \ --config-file=${CONFIG_FILE} \ --cloud=${CLOUD} \ @@ -139,6 +148,17 @@ elif [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then --step=${PIPELINE_STEP} \ --scope vars \ --format makefile +elif [ $PIPELINE_MODE == "run" ] && [ -n "$PIPELINE" ] && [ -n "$PIPELINE_STEP" ]; then + $TEMPLATIZE pipeline run \ + --config-file=${CONFIG_FILE} \ + --cloud=${CLOUD} \ + --deploy-env=${DEPLOY_ENV} \ + --region=${REGION} \ + --region-short=${REGION_STAMP} \ + --stamp=${CXSTAMP} \ + --pipeline-file=${PIPELINE} \ + --step=${PIPELINE_STEP} \ + ${DRY_RUN} else $TEMPLATIZE inspect \ --config-file=${CONFIG_FILE} \