Skip to content

trigger build 2

trigger build 2 #3

Workflow file for this run

name: Migrate database
on:
push:
branches:
- main
paths:
- prisma/**
workflow_dispatch:
inputs:
hubAddressGroupObject:
type: choice
description: 'Deploy service 🚀🚀🚀'
required: true
default: 'deploy'
options:
- 'deploy'
branches:
- main
env:
NAME_SERVICE: faucet-testnet-migrator
IMAGE_TAG_LATEST: latest
DOCKER_BUILDKIT: 1
AWS_REGION: ap-southeast-1
BRANCH_CD_REPOSITORY: master
CD_REPOSITORY: CaliberVB/argocd
ROOT_PATH_CD_REPOSITORY: argocd
jobs:
build-prod:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Pre-check step and set env dev
id: get_current_env_prod
if: ${{ github.event.ref == 'refs/heads/main' }}
run: |
if [[ ${{ github.event.ref }} == 'refs/heads/main' ]]; then
echo "CURRENT_ENV=prod" >> "$GITHUB_ENV"
echo "[INFO] PASSED pre-check. Using build automatically"
echo "[INFO] PASSED pre-check. Using build automatically"
exit 0
else
echo "[ERR] You are not allowed to run pipeline"
echo "[ERR] Your action has been reported to your admin"
exit 1
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/[email protected]
- name: Build, tag, and push image to Amazon ECR
id: build-image
timeout-minutes: 15 #####
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
IMAGE_TAG=$(echo ${{ github.sha }} | cut -c1-9)
ECR_REPOSITORY="${NAME_SERVICE}"
echo "Build image ${ECR_REPOSITORY}"
docker build --pull -t ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} -f ./migrator/Dockerfile .
docker tag ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG_LATEST}
docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}
docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG_LATEST}
deploy-prod:
if: startsWith(github.ref, 'refs/heads/main')
needs: build-prod
environment: prod
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Pre-check step and set env dev
id: get_current_env_prod
if: ${{ github.event.ref == 'refs/heads/main' }}
run: |
if [[ ${{ github.event.ref }} == 'refs/heads/main' ]]; then
echo "CURRENT_ENV=prod" >> "$GITHUB_ENV"
echo "[INFO] PASSED pre-check. Using build automatically"
echo "[INFO] PASSED pre-check. Using build automatically"
exit 0
else
echo "[ERR] You are not allowed to run pipeline"
echo "[ERR] Your action has been reported to your admin"
exit 1
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/[email protected]
- name: Checkout argocd repository
uses: actions/checkout@v3
with:
repository: ${{ env.CD_REPOSITORY }}
ref: ${{ env.BRANCH_CD_REPOSITORY }}
token: ${{ secrets.ACTION_TOKEN }}
path: ${{ env.ROOT_PATH_CD_REPOSITORY }}
- name: Update helm chart, commit files to ArgoCD
run: |
IMAGE_TAG=$(echo ${{ github.sha }} | cut -c1-9)
echo "Working dir helm chart:" $PWD
echo "Tagging:" ${IMAGE_TAG}
cd argocd/faucet-testnet-v2
sed -i -e "s/tag: .*/tag: ${IMAGE_TAG}/g" ./chart/env/${CURRENT_ENV}/${NAME_SERVICE}-values.yaml
rm -rf ./chart/env/${CURRENT_ENV}/${NAME_SERVICE}-values.yaml-e
if [[ -z $(git status -s) ]]; then
echo -e '[WARNING] Nothing commit for deployments ArgoCD, working tree clean'
exit 0
else
git config user.email "${{ env.NAME_SERVICE }}[email protected]"
git config user.name "${{ env.NAME_SERVICE }}_dev"
git add .
git commit -am "Update image tag helm chart for ${{ env.NAME_SERVICE }} on ${CURRENT_ENV}"
git push -u origin ${{ env.BRANCH_CD_REPOSITORY }}
fi