Skip to content

Commit

Permalink
Merge pull request #44 from i-dot-ai/feature/release-infra-workflow
Browse files Browse the repository at this point in the history
add: release command
  • Loading branch information
ghannay10 authored Mar 26, 2024
2 parents bd8e0e6 + ebff79e commit f5be293
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: build-infrastructure

on:
push:
tags:
- release-dev-**
- release-preprod-**

branches:
- main

Expand Down Expand Up @@ -33,6 +37,18 @@ jobs:
echo "environment=${ENVIRONMENT}" >> $GITHUB_OUTPUT
echo "::add-mask::${AWS_REGION}"
- id: env-var
run: |
# prod env from main branch
if [ ${{ github.ref == 'refs/heads/main' }} ]; then
export ENVIRONMENT=prod
# Otherwise get the environment from the tag
else
export ENVIRONMENT=$(echo ${{ github.ref_name }} | awk -F- '{ print $2 }')
fi
echo "environment=${ENVIRONMENT}" >> $GITHUB_OUTPUT
start-runner:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/start-runner.yml@main
needs: set-vars
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ tf_apply: ## Apply terraform
.PHONY: tf_destroy
tf_destroy: ## Destroy terraform
make tf_set_workspace && \
terraform -chdir=./infrastructure destroy -var-file=$(CONFIG_DIR)/${env}-input-params.tfvars ${tf_build_args}
terraform -chdir=./infrastructure destroy -var-file=$(CONFIG_DIR)/${env}-input-params.tfvars ${tf_build_args}


# Release commands to deploy your app to AWS
.PHONY: release
release: ## Deploy app
chmod +x ./infrastructure/scripts/release.sh && ./infrastructure/scripts/release.sh $(env)
4 changes: 2 additions & 2 deletions infrastructure/ecs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module "ecs" {
source = "../../i-ai-core-infrastructure//modules/ecs"
project_name = var.project_name
image_tag = "5586478ada171e6b4fc81c3c4142f2d125079bf3"
image_tag = var.image_tag
prefix = "i-dot-ai"
ecr_repository_uri = module.ecr.ecr_repository_url
ecr_repository_uri = module.ecr_front_end.ecr_repository_url
ecs_cluster_id = data.terraform_remote_state.platform.outputs.ecs_cluster_id
health_check = {
healthy_threshold = 3
Expand Down
33 changes: 33 additions & 0 deletions infrastructure/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Usage:
## Just pass the name of the env we want to tag and deploy.
## This will create a tag locally with a format of $$ENV-$BRANCH-$CURRENT_USER-$TIMESTAMP
## Then push it to the remote git.
ENV=$1
BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_USER=$(whoami)
TIMESTAMP=$(date +%d-%m-%y--%H%M%S)
TAG_NAME="release-$ENV-$BRANCH-$CURRENT_USER-$TIMESTAMP"

echo "Current branch name is" "$BRANCH"
echo "Current environment name is" "$ENV"
echo "Timestamp assigned will be $TIMESTAMP"
echo "New tag name will be " "$TAG_NAME"

if [ $ENV == 'prod' ]; then
echo ''
if [ $BRANCH != 'main' ]; then
echo -e "\033[0;31mYou can only deploy to prod through a PR into main\033[0m"
exit 0
fi
fi

##
echo "Removing Local tags"
git tag -d $(git tag -l)

# Command to run
echo "Applying local tag" && \
git tag "$TAG_NAME" && \
echo "Pushing tag" && \
git push origin $TAG_NAME

0 comments on commit f5be293

Please sign in to comment.