Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: release command #44

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-**

ghannay10 marked this conversation as resolved.
Show resolved Hide resolved
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@feature/apply-terraform
needs: set-vars
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,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)
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
Loading