From fa1b76d14a39d7e28ccbdcf178d7b76a58f8299e Mon Sep 17 00:00:00 2001 From: sergey filyanin Date: Wed, 4 Sep 2024 11:53:39 +0200 Subject: [PATCH] Create k8s-deploy.yml --- .github/workflows/k8s-deploy.yml | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/k8s-deploy.yml diff --git a/.github/workflows/k8s-deploy.yml b/.github/workflows/k8s-deploy.yml new file mode 100644 index 00000000..9c81eafb --- /dev/null +++ b/.github/workflows/k8s-deploy.yml @@ -0,0 +1,118 @@ +name: Build and Deploy ZK Bridge +on: + workflow_dispatch: + push: + branches: ['master', 'main', 'staging'] + paths: + - frontend/** + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + ENVIRONMENT: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} + KUBECTL_VERSION: 'v1.22.17' + KUBE_NAMESPACE: zk-bridge + KUBE_DEPLOYMENT_PREFIX: zk-bridge + REGISTRY: ghcr.io/${{ github.repository }} + +jobs: + prepair: + runs-on: ubuntu-latest + outputs: + image_name: ${{ steps.image.outputs.image_name }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get branch + id: branch + run: | + branch_name=${GITHUB_REF#refs/heads/} + echo "branch_name=$branch_name" >> $GITHUB_ENV + + - name: Get short SHA + id: sha + run: | + sha_short=$(git rev-parse --short HEAD) + echo "sha_short=$sha_short" >> $GITHUB_ENV + + - name: Set IMAGE_NAME + id: image + run: | + image_name=${{ env.REGISTRY }}-${{ env.KUBE_DEPLOYMENT_PREFIX }}:${{ env.branch_name }}-${{ env.sha_short }} + echo "image_name=$image_name" >> $GITHUB_OUTPUT + + build-and-push-image: + needs: [prepair] + runs-on: ubuntu-latest + environment: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the github container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v5 + with: + context: frontend + file: frontend/Dockerfile + push: true + tags: ${{ needs.prepair.outputs.image_name }} + build-args: | + VITE_VARA_NODE_ADDRESS=${{ secrets.VITE_VARA_NODE_ADDRESS }} + VITE_ETH_NODE_ADDRESS=${{ secrets.VITE_ETH_NODE_ADDRESS }} + VITE_ETH_CHAIN_ID=${{ secrets.VITE_ETH_CHAIN_ID }} + VITE_WALLET_CONNECT_PROJECT_ID=${{ secrets.VITE_WALLET_CONNECT_PROJECT_ID }} + VITE_INDEXER_ADDRESS=${{ secrets.VITE_INDEXER_ADDRESS }} + VITE_BRIDGING_PAYMENT_CONTRACT_ADDRESS=${{ secrets.VITE_BRIDGING_PAYMENT_CONTRACT_ADDRESS }} + VITE_ERC20_TREASURY_CONTRACT_ADDRESS=${{ secrets.VITE_ERC20_TREASURY_CONTRACT_ADDRESS }} + + deploy-to-k8s: + needs: [prepair, build-and-push-image] + runs-on: ubuntu-latest + environment: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Update deployment image + uses: kodermax/kubectl-aws-eks@main + with: + args: | + set image deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ + ${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }}=${{ needs.prepair.outputs.image_name }} \ + -n ${{ env.KUBE_NAMESPACE }} + + - name: Restart deployment + uses: kodermax/kubectl-aws-eks@main + with: + args: | + rollout restart deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ + -n ${{ env.KUBE_NAMESPACE }} + + - name: Check deployment + uses: kodermax/kubectl-aws-eks@main + with: + args: | + rollout status deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ + --timeout=240s \ + -n ${{ env.KUBE_NAMESPACE }}