From c0d272b6165cdcb81b8f67f27b6cf2b901fbd442 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Wed, 4 Dec 2024 13:15:27 +0800 Subject: [PATCH 1/3] Add GH actions pipelines --- .github/workflows/mainnet-beta.yml | 68 +++++++++++++++++++++++++++++ .github/workflows/master.yml | 69 ++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 .github/workflows/mainnet-beta.yml create mode 100644 .github/workflows/master.yml diff --git a/.github/workflows/mainnet-beta.yml b/.github/workflows/mainnet-beta.yml new file mode 100644 index 0000000..9b7f4b3 --- /dev/null +++ b/.github/workflows/mainnet-beta.yml @@ -0,0 +1,68 @@ +name: Build Image And Deploy + +on: + push: + branches: [mainnet-beta] + +jobs: + build: + runs-on: ubicloud + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PROD }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_PROD }} + aws-region: ${{ secrets.EKS_PROD_REGION }} + + - name: Log in to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build and push + uses: docker/build-push-action@v6 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: events-publisher + IMAGE_TAG: ${{ github.sha }} + BRANCH_NAME: ${{ github.ref_name }} + with: + context: . + push: true + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest-${{ env.BRANCH_NAME }}-amd64 + + deploy: + runs-on: ubicloud + needs: [build] + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PROD }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_PROD }} + aws-region: ${{ secrets.EKS_PROD_REGION }} + + - name: Install kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + + - name: Configure AWS EKS Credentials + run: aws eks update-kubeconfig --name ${{ secrets.EKS_PROD_CLUSTER_NAME }} --region ${{ secrets.EKS_PROD_REGION }} --role-arn ${{ secrets.EKS_PROD_DEPLOY_ROLE }} + + - name: Restart deployment + env: + BRANCH_NAME: ${{ github.ref_name }} + run: | + kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app + kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 0000000..e085f15 --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,69 @@ +# non-prod +name: Build Image And Deploy + +on: + push: + branches: [master, staging] + +jobs: + build: + runs-on: ubicloud + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_NON_PROD }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_NON_PROD }} + aws-region: ${{ secrets.EKS_NON_PROD_REGION }} + + - name: Log in to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build and push + uses: docker/build-push-action@v6 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: events-publisher + IMAGE_TAG: ${{ github.sha }} + BRANCH_NAME: ${{ github.ref_name }} + with: + context: . + push: true + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest-${{ env.BRANCH_NAME }}-amd64 + + deploy: + runs-on: ubicloud + needs: [build] + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_NON_PROD }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_NON_PROD }} + aws-region: ${{ secrets.EKS_NON_PROD_REGION }} + + - name: Install kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + + - name: Configure AWS EKS Credentials + run: aws eks update-kubeconfig --name ${{ secrets.EKS_NON_PROD_CLUSTER_NAME }} --region ${{ secrets.EKS_NON_PROD_REGION }} --role-arn ${{ secrets.EKS_NON_PROD_DEPLOY_ROLE }} + + - name: Restart deployment + env: + BRANCH_NAME: ${{ github.ref_name }} + run: | + kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app + kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file From b0b162807f85a9f310caf95ac29c8b0048beba4c Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Wed, 4 Dec 2024 13:47:30 +0800 Subject: [PATCH 2/3] tidy up --- .github/workflows/mainnet-beta.yml | 3 --- .github/workflows/master.yml | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/mainnet-beta.yml b/.github/workflows/mainnet-beta.yml index 9b7f4b3..15cef60 100644 --- a/.github/workflows/mainnet-beta.yml +++ b/.github/workflows/mainnet-beta.yml @@ -42,9 +42,6 @@ jobs: runs-on: ubicloud needs: [build] steps: - - name: Checkout Code - uses: actions/checkout@v3 - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@master with: diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index e085f15..7a06e20 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -12,7 +12,7 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 with: - submodules: 'recursive' + submodules: recursive - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@master @@ -43,9 +43,6 @@ jobs: runs-on: ubicloud needs: [build] steps: - - name: Checkout Code - uses: actions/checkout@v3 - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@master with: From ac0f168d2bb360ccf6de5c2553eb909055ac40f1 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 5 Dec 2024 08:52:02 +0800 Subject: [PATCH 3/3] comment out rollout for testing --- .github/workflows/mainnet-beta.yml | 5 +++-- .github/workflows/master.yml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mainnet-beta.yml b/.github/workflows/mainnet-beta.yml index 15cef60..d2e6647 100644 --- a/.github/workflows/mainnet-beta.yml +++ b/.github/workflows/mainnet-beta.yml @@ -61,5 +61,6 @@ jobs: env: BRANCH_NAME: ${{ github.ref_name }} run: | - kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app - kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file + kubectl get deployments -n -n $BRANCH_NAME + # kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app + # kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 7a06e20..64a9501 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -62,5 +62,6 @@ jobs: env: BRANCH_NAME: ${{ github.ref_name }} run: | - kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app - kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file + kubectl get deployments -n -n $BRANCH_NAME + # kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app + # kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app \ No newline at end of file