From 857e264c5380ecaa772c144780dfc9b414580438 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 5 Dec 2024 08:52:30 +0800 Subject: [PATCH 1/4] Feat/gh actions (#23) * Add GH actions pipelines * kubectl rollout commented for testing --- .github/workflows/mainnet-beta.yml | 66 +++++++++++++++++++++++++++++ .github/workflows/master.yml | 67 ++++++++++++++++++++++++++++++ 2 files changed, 133 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..d2e6647 --- /dev/null +++ b/.github/workflows/mainnet-beta.yml @@ -0,0 +1,66 @@ +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: 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 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 new file mode 100644 index 0000000..64a9501 --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,67 @@ +# 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: 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 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 From 9e2e25b8174a82c1fe32b03d5e7eb650aa3fdfaf Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 5 Dec 2024 09:05:08 +0800 Subject: [PATCH 2/4] Feat/gh actions (#25) * enable deploy on master/nonprod --- .github/workflows/master.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 64a9501..7a06e20 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -62,6 +62,5 @@ jobs: env: BRANCH_NAME: ${{ github.ref_name }} run: | - 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 + 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 f10c83a86a55903012e98c46e173df0c095082e5 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 5 Dec 2024 10:35:04 +0800 Subject: [PATCH 3/4] mainnet-beta deploy --- .github/workflows/mainnet-beta.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mainnet-beta.yml b/.github/workflows/mainnet-beta.yml index d2e6647..3b8855b 100644 --- a/.github/workflows/mainnet-beta.yml +++ b/.github/workflows/mainnet-beta.yml @@ -11,7 +11,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 @@ -61,6 +61,5 @@ jobs: env: BRANCH_NAME: ${{ github.ref_name }} run: | - 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 + kubectl rollout restart -n $BRANCH_NAME deployment/events-publisher-app + kubectl rollout restart -n $BRANCH_NAME deployment/events-ws-connection-manager-app From 96546070be36595752f1792b51ca7f0773a9d3ee Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 5 Dec 2024 10:43:11 +0800 Subject: [PATCH 4/4] add branch name to tag --- .github/workflows/mainnet-beta.yml | 2 +- .github/workflows/master.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mainnet-beta.yml b/.github/workflows/mainnet-beta.yml index 3b8855b..967338f 100644 --- a/.github/workflows/mainnet-beta.yml +++ b/.github/workflows/mainnet-beta.yml @@ -35,7 +35,7 @@ jobs: context: . push: true tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}-${{ env.BRANCH_NAME }}-amd64 ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest-${{ env.BRANCH_NAME }}-amd64 deploy: diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 7a06e20..f16e3d6 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -36,7 +36,7 @@ jobs: context: . push: true tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}-${{ env.BRANCH_NAME }}-amd64 ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest-${{ env.BRANCH_NAME }}-amd64 deploy: