From 2949dc13c9310fd1ea777b1606dcb0b8b61ae1d7 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 3 May 2024 20:04:43 -0700 Subject: [PATCH] short git sha character length in project config --- project.yaml | 3 +++ scripts/build-image.sh | 4 +++- scripts/print-image-tag.sh | 5 ++++- scripts/push-prod-image.sh | 3 ++- scripts/tag-dev-image.sh | 5 +++-- scripts/tag-merge-commit.sh | 3 ++- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/project.yaml b/project.yaml index 1c022bae..4cbe514c 100644 --- a/project.yaml +++ b/project.yaml @@ -319,6 +319,9 @@ scripts: SERVICES_ZIP: ssm: null default: mxfactorial.zip + SHORT_GIT_SHA_LENGTH: + ssm: null + default: 7 services: env_var: set: diff --git a/scripts/build-image.sh b/scripts/build-image.sh index 72bcee26..8bf0f302 100644 --- a/scripts/build-image.sh +++ b/scripts/build-image.sh @@ -26,7 +26,9 @@ while [[ "$#" -gt 0 ]]; do shift done -HASH=$(git rev-parse --short=7 HEAD) +PROJECT_CONF=project.yaml +SHORT_GIT_SHA_LENGTH=$(yq '.scripts.env_var.set.SHORT_GIT_SHA_LENGTH.default' $PROJECT_CONF) +HASH=$(git rev-parse --short=$SHORT_GIT_SHA_LENGTH HEAD) IMAGE_TAG="$APP_NAME:$HASH" DOCKERFILE_PATH=./docker/$APP_NAME.Dockerfile diff --git a/scripts/print-image-tag.sh b/scripts/print-image-tag.sh index 2ac7760f..aefed737 100644 --- a/scripts/print-image-tag.sh +++ b/scripts/print-image-tag.sh @@ -34,8 +34,11 @@ while [[ "$#" -gt 0 ]]; do shift done +PROJECT_CONF=project.yaml +SHORT_GIT_SHA_LENGTH=$(yq '.scripts.env_var.set.SHORT_GIT_SHA_LENGTH.default' $PROJECT_CONF) + if [[ -z $HASH ]]; then - HASH=$(git rev-parse --short=7 HEAD) + HASH=$(git rev-parse --short=$SHORT_GIT_SHA_LENGTH HEAD) fi REPO=$(source scripts/print-ecr-repo-uri.sh --app-name $APP_NAME --env $ENV --env-id $ENV_ID) diff --git a/scripts/push-prod-image.sh b/scripts/push-prod-image.sh index 0c5ec7dc..6f6ad26a 100644 --- a/scripts/push-prod-image.sh +++ b/scripts/push-prod-image.sh @@ -36,8 +36,9 @@ ID_ENV_PREFIX="$ENV_ID/$ENV" REGION=$(yq '.infrastructure.terraform.aws.modules.environment.env_var.set.REGION.default' $PROJECT_CONF) REPO_NAME="$ID_ENV_PREFIX/$APP_NAME" PROD_ENV_ID=$(yq '.infrastructure.terraform.env-id.prod.env_var.set.PROD_ENV_ID.default' $PROJECT_CONF) +SHORT_GIT_SHA_LENGTH=$(yq '.scripts.env_var.set.SHORT_GIT_SHA_LENGTH.default' $PROJECT_CONF) -MERGE_COMMIT_HASH=$(git rev-parse --short=7 HEAD) +MERGE_COMMIT_HASH=$(git rev-parse --short=$SHORT_GIT_SHA_LENGTH HEAD) TAG_COUNT=$(aws ecr batch-get-image \ --repository-name=$REPO_NAME \ diff --git a/scripts/tag-dev-image.sh b/scripts/tag-dev-image.sh index c4ce0fef..4b4a772e 100644 --- a/scripts/tag-dev-image.sh +++ b/scripts/tag-dev-image.sh @@ -22,11 +22,12 @@ while [[ "$#" -gt 0 ]]; do shift done -HASH=$(git rev-parse --short=7 HEAD) +PROJECT_CONF=project.yaml +SHORT_GIT_SHA_LENGTH=$(yq '.scripts.env_var.set.SHORT_GIT_SHA_LENGTH.default' $PROJECT_CONF) +HASH=$(git rev-parse --short=$SHORT_GIT_SHA_LENGTH HEAD) LOCAL_IMAGE_TAG="$APP_NAME:$HASH" ENV=dev -PROJECT_CONF=project.yaml ENV_ID=$(source scripts/print-env-id.sh) DEV_REPO=$(source scripts/print-ecr-repo-uri.sh --app-name $APP_NAME --env dev --env-id $ENV_ID) diff --git a/scripts/tag-merge-commit.sh b/scripts/tag-merge-commit.sh index f5e272a8..f7f8562e 100644 --- a/scripts/tag-merge-commit.sh +++ b/scripts/tag-merge-commit.sh @@ -34,6 +34,7 @@ PROJECT_CONF=project.yaml ID_ENV="$ENV_ID-$ENV" ID_ENV_PREFIX="$ENV_ID/$ENV" REGION=$(yq '.infrastructure.terraform.aws.modules.environment.env_var.set.REGION.default' $PROJECT_CONF) +SHORT_GIT_SHA_LENGTH=$(yq '.scripts.env_var.set.SHORT_GIT_SHA_LENGTH.default' $PROJECT_CONF) IMAGE_NAME="$ID_ENV_PREFIX/$APP_NAME" LAMBDA_NAME="$APP_NAME-$ID_ENV" @@ -54,7 +55,7 @@ fi LATEST_ECR_IMAGE_TAG_VERSIONS=($(aws ecr describe-images --repository-name $IMAGE_NAME --output text --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags' | xargs)) # get the commit hash after merge -MERGE_COMMIT_HASH=$(git rev-parse --short=7 HEAD) +MERGE_COMMIT_HASH=$(git rev-parse --short=$SHORT_GIT_SHA_LENGTH HEAD) for TAG_VERSION in "${LATEST_ECR_IMAGE_TAG_VERSIONS[@]}"; do if [[ "$TAG_VERSION" == "$DEPLOYED_IMAGE_TAG_VERSION" ]]; then