Skip to content

Commit

Permalink
short git sha character length in project config
Browse files Browse the repository at this point in the history
  • Loading branch information
mxfactorial committed May 4, 2024
1 parent 48c5e63 commit 2949dc1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ scripts:
SERVICES_ZIP:
ssm: null
default: mxfactorial.zip
SHORT_GIT_SHA_LENGTH:
ssm: null
default: 7
services:
env_var:
set:
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion scripts/print-image-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion scripts/push-prod-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions scripts/tag-dev-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion scripts/tag-merge-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 2949dc1

Please sign in to comment.