Skip to content

feat: add VariablesButton component to workflow layout (#1837) #1

feat: add VariablesButton component to workflow layout (#1837)

feat: add VariablesButton component to workflow layout (#1837) #1

name: Kubetest Main Backend CI
on:
push:
branches:
- main
- dev
- kubetest
paths:
- "apps/main-backend/**"
- "packages/**"
pull_request:
branches:
- main
- dev
- kubetest
paths:
- "apps/main-backend/**"
- "packages/**"
workflow_dispatch:
inputs:
environment:
description: "Select environment to deploy"
required: true
type: choice
options:
- dev
- prod
default: "dev"
jobs:
deploy:
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev')) ||
(github.ref == 'refs/heads/main' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'prod'))) ||
(github.ref == 'refs/heads/kubetest' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev')))
environment: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_CD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_CD_SECRET_ACCESS_KEY }}
aws-region: ap-south-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set environment variables
id: set-env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "ENV_NAME=prod" >> $GITHUB_OUTPUT
echo "CONTAINER_NAME=atoms-backend-prod" >> $GITHUB_OUTPUT
echo "ECR_REPOSITORY=atoms-backend-prod" >> $GITHUB_OUTPUT
else
echo "ENV_NAME=dev" >> $GITHUB_OUTPUT
echo "CONTAINER_NAME=atoms-backend-dev" >> $GITHUB_OUTPUT
echo "ECR_REPOSITORY=atoms-backend-dev" >> $GITHUB_OUTPUT
fi
- name: Set image tag
id: set-image-tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "IMAGE_TAG=atoms-backend-${{ steps.set-env.outputs.ENV_NAME }}-manual-${{ github.sha }}" >> $GITHUB_OUTPUT
else
echo "IMAGE_TAG=atoms-backend-${{ steps.set-env.outputs.ENV_NAME }}-${{ github.sha }}" >> $GITHUB_OUTPUT
fi
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ steps.set-env.outputs.ECR_REPOSITORY }}
IMAGE_TAG: ${{ steps.set-image-tag.outputs.IMAGE_TAG }}
run: |
docker build \
--build-arg GITHUB_TOKEN="${{ secrets.REPO_TOKEN }}" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
.
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Debug image reference
run: |
echo "Full image reference: ${{ steps.login-ecr.outputs.registry }}/${{ steps.set-env.outputs.ECR_REPOSITORY }}:${{ steps.set-image-tag.outputs.IMAGE_TAG }}"
- name: Set Helm branch and values file
id: set-helm-config
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "HELM_BRANCH=main" >> $GITHUB_OUTPUT
echo "VALUES_FILE=values-prod.yaml" >> $GITHUB_OUTPUT
else
echo "HELM_BRANCH=dev" >> $GITHUB_OUTPUT
echo "VALUES_FILE=values-dev.yaml" >> $GITHUB_OUTPUT
fi
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: smallest-inc
repositories: atoms-helm
- name: Checkout Helm repository
uses: actions/checkout@v3
with:
repository: smallest-inc/atoms-helm
token: ${{ steps.app-token.outputs.token }}
path: atoms-helm
ref: ${{ steps.set-helm-config.outputs.HELM_BRANCH }}
- name: Update Helm values
run: |
cd atoms-helm
# Install yq
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
# Update the values
yq e ".mainbackend.image.repository = \"${{ steps.login-ecr.outputs.registry }}/${{ steps.set-env.outputs.ECR_REPOSITORY }}\"" -i ${{ steps.set-helm-config.outputs.VALUES_FILE }}
yq e ".mainbackend.image.tag = \"${{ steps.set-image-tag.outputs.IMAGE_TAG }}\"" -i ${{ steps.set-helm-config.outputs.VALUES_FILE }}
- name: Commit and push changes
run: |
cd atoms-helm
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add ${{ steps.set-helm-config.outputs.VALUES_FILE }}
git commit -m "Update main-backend image to ${{ steps.set-image-tag.outputs.IMAGE_TAG }} [skip ci]"
git push origin ${{ steps.set-helm-config.outputs.HELM_BRANCH }}