From df736a12dc7ca89b163f20136f3ab13634a0cb04 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 8 Apr 2024 16:04:46 +0800 Subject: [PATCH 1/3] chore: updated gh actions --- .../actions/deploy_to_kubernetes/action.yml | 22 ++++++++-------- .github/actions/notify_slack/action.yml | 12 ++++----- .github/actions/publish_to_docker/action.yml | 25 +++++++++++++++---- .github/actions/versioning/action.yml | 5 +++- .github/workflows/release_production.yml | 6 ++--- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.github/actions/deploy_to_kubernetes/action.yml b/.github/actions/deploy_to_kubernetes/action.yml index c7f904348..145ff53d1 100644 --- a/.github/actions/deploy_to_kubernetes/action.yml +++ b/.github/actions/deploy_to_kubernetes/action.yml @@ -23,20 +23,20 @@ inputs: runs: using: composite steps: - - name: Setup Environment variables - run: | - echo "NAMESPACE=${{ inputs.K8S_NAMESPACE }}" >> "$GITHUB_ENV" - echo "KUBE_SERVER=${{ inputs.KUBE_SERVER }}" >> "$GITHUB_ENV" - echo "SERVICEACCOUNT_TOKEN=${{ inputs.SERVICEACCOUNT_TOKEN }}" >> "$GITHUB_ENV" - echo "DOCKERHUB_ORGANISATION=${{ inputs.DOCKERHUB_ORGANISATION }}" >> "$GITHUB_ENV" - echo "CA_CRT=${{ inputs.CA_CRT }}" >> "$GITHUB_ENV" - echo "APP_NAME=deriv-com-api" >> "$GITHUB_ENV" - shell: bash - name: Deploying to k8s cluster for service ${{ inputs.K8S_NAMESPACE }} 🚀 + env: + K8S_VERSION: ${{ inputs.K8S_VERSION }} + NAMESPACE: ${{ inputs.K8S_NAMESPACE }} + KUBE_SERVER: ${{ inputs.KUBE_SERVER }} + SERVICEACCOUNT_TOKEN: ${{ inputs.SERVICEACCOUNT_TOKEN }} + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + CA_CRT: ${{ inputs.CA_CRT }} + APP_NAME: deriv-com-api + run: | git clone https://github.com/binary-com/devops-ci-scripts cd devops-ci-scripts/k8s-build_tools - echo ${{ inputs.CA_CRT }} | base64 --decode > ca.crt + echo $CA_CRT | base64 --decode > ca.crt export CA="ca.crt" - ./release.sh ${APP_NAME} ${{ inputs.K8S_VERSION }} + ./release.sh ${APP_NAME} $K8S_VERSION shell: bash diff --git a/.github/actions/notify_slack/action.yml b/.github/actions/notify_slack/action.yml index e8e12f0ec..ae0e64571 100644 --- a/.github/actions/notify_slack/action.yml +++ b/.github/actions/notify_slack/action.yml @@ -11,10 +11,8 @@ runs: using: composite steps: - name: Send Slack Notification - run: |- - curl -X POST -H 'Content-type: application/json' \ - --data '{ - "text": "${{ inputs.MESSAGE }}", - }' \ - ${{ inputs.SLACK_WEBHOOK_URL }} - shell: bash + uses: 'deriv-com/shared-actions/.github/actions/send_slack_notification@master' + with: + SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }} + MESSAGE: ${{ inputs.MESSAGE }} + diff --git a/.github/actions/publish_to_docker/action.yml b/.github/actions/publish_to_docker/action.yml index 5c0c4f5c7..3875c0c95 100644 --- a/.github/actions/publish_to_docker/action.yml +++ b/.github/actions/publish_to_docker/action.yml @@ -21,18 +21,33 @@ runs: using: composite steps: - name: Building docker image 🐳 + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + DOCKER_IMAGE_TAG: ${{ inputs.DOCKER_IMAGE_TAG }} + DOCKER_LATEST_IMAGE_TAG: ${{ inputs.DOCKER_LATEST_IMAGE_TAG }} run: | - docker build -t ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_IMAGE_TAG }} -t ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_LATEST_IMAGE_TAG }} . + docker build -t $DOCKERHUB_ORGANISATION/deriv-com-api:$DOCKER_IMAGE_TAG -t $DOCKERHUB_ORGANISATION/deriv-com-api:$DOCKER_LATEST_IMAGE_TAG . shell: bash + - name: Verify nginx image + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + DOCKER_LATEST_IMAGE_TAG: ${{ inputs.DOCKER_LATEST_IMAGE_TAG }} run: | set -e - docker run --rm ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_LATEST_IMAGE_TAG }} nginx -t + docker run --rm $DOCKERHUB_ORGANISATION/deriv-com-api:$DOCKER_LATEST_IMAGE_TAG nginx -t echo "docker image validated successfully" shell: bash + - name: Pushing Image to docker hub 🐳 + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + DOCKER_IMAGE_TAG: ${{ inputs.DOCKER_IMAGE_TAG }} + DOCKER_LATEST_IMAGE_TAG: ${{ inputs.DOCKER_LATEST_IMAGE_TAG }} + DOCKERHUB_PASSWORD: ${{ inputs.DOCKERHUB_PASSWORD }} + DOCKERHUB_USERNAME: ${{ inputs.DOCKERHUB_USERNAME }} run: | - echo ${{ inputs.DOCKERHUB_PASSWORD }} | docker login -u ${{ inputs.DOCKERHUB_USERNAME }} --password-stdin - docker push ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_IMAGE_TAG }} - docker push ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_LATEST_IMAGE_TAG }} + echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin + docker push $DOCKERHUB_ORGANISATION/deriv-com-api:$DOCKER_IMAGE_TAG + docker push $DOCKERHUB_ORGANISATION/deriv-com-api:$DOCKER_LATEST_IMAGE_TAG shell: bash diff --git a/.github/actions/versioning/action.yml b/.github/actions/versioning/action.yml index 405d11725..2993d55cc 100644 --- a/.github/actions/versioning/action.yml +++ b/.github/actions/versioning/action.yml @@ -12,5 +12,8 @@ runs: using: composite steps: - name: Tag build - run: echo "${{ inputs.RELEASE_TYPE }}--GITHUB_REF:${{ inputs.RELEASE_TAG }}--DATE:$(date -u +'%Y-%m-%dT%H:%M:%SZ')" > build/version.txt + env: + RELEASE_TYPE: ${{ inputs.RELEASE_TYPE }} + RELEASE_TAG: ${{ inputs.RELEASE_TAG }} + run: echo "$RELEASE_TYPE--GITHUB_REF:$RELEASE_TAG--DATE:$(date -u +'%Y-%m-%dT%H:%M:%SZ')" > build/version.txt shell: bash diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 6ba9df4bc..3bd33d8e8 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -57,10 +57,10 @@ jobs: - name: Create Slack Message id: create_slack_message run: | - if [ "${{ env.WORKFLOW_CONCLUSION }}" == "success" ]; then - echo "MESSAGE=${{ env.RELEASE_TYPE }} Release succeeded for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT + if [ "WORKFLOW_CONCLUSION" == "success" ]; then + echo "MESSAGE=$RELEASE_TYPE }} Release succeeded for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT else - echo "MESSAGE=${{ env.RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT + echo "MESSAGE=$RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT fi - name: Send Slack Notification uses: ./.github/actions/notify_slack From 4fa5c7c02af9ab17d396568cae90258387c2e3ac Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 8 Apr 2024 16:42:38 +0800 Subject: [PATCH 2/3] chore: added the $ var --- .github/workflows/release_production.yml | 2 +- .vscode/settings.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 3bd33d8e8..ceb4996d1 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -57,7 +57,7 @@ jobs: - name: Create Slack Message id: create_slack_message run: | - if [ "WORKFLOW_CONCLUSION" == "success" ]; then + if [ "$WORKFLOW_CONCLUSION" == "success" ]; then echo "MESSAGE=$RELEASE_TYPE }} Release succeeded for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT else echo "MESSAGE=$RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT diff --git a/.vscode/settings.json b/.vscode/settings.json index 8c167a488..02db64b75 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,7 @@ { - "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true } From 400e2a00435bca09671cc2e24db9de3d1c3a5e4f Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 8 Apr 2024 17:23:05 +0800 Subject: [PATCH 3/3] chore: :fire: removed redundant workflows --- .github/actions/notify_slack/action.yml | 18 ------------------ .github/workflows/release_production.yml | 8 ++++---- 2 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 .github/actions/notify_slack/action.yml diff --git a/.github/actions/notify_slack/action.yml b/.github/actions/notify_slack/action.yml deleted file mode 100644 index ae0e64571..000000000 --- a/.github/actions/notify_slack/action.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: notify_slack -description: Send Slack notification -inputs: - SLACK_WEBHOOK_URL: - description: Slack webhook URL - required: true - MESSAGE: - description: 'Status message' - required: true -runs: - using: composite - steps: - - name: Send Slack Notification - uses: 'deriv-com/shared-actions/.github/actions/send_slack_notification@master' - with: - SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }} - MESSAGE: ${{ inputs.MESSAGE }} - diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index ceb4996d1..960fc4144 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -63,7 +63,7 @@ jobs: echo "MESSAGE=$RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_OUTPUT fi - name: Send Slack Notification - uses: ./.github/actions/notify_slack + uses: 'deriv-com/shared-actions/.github/actions/send_slack_notification@master' with: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} MESSAGE: ${{ steps.create_slack_message.outputs.MESSAGE }} @@ -102,7 +102,7 @@ jobs: DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} - name: Send Slack Notification if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }} - uses: ./.github/actions/notify_slack + uses: 'deriv-com/shared-actions/.github/actions/send_slack_notification@master' with: - RELEASE_TYPE: ${{ env.RELEASE_TYPE }} - MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MESSAGE: "$RELEASE_TYPE Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" \ No newline at end of file