From e1ac0f44fc38f7106921b45f346657f512e12b64 Mon Sep 17 00:00:00 2001 From: Jim Daniels Wasswa Date: Fri, 5 Apr 2024 13:17:54 +0800 Subject: [PATCH] ci: resolve context issues --- .../build_and_push_docker_image/action.yml | 33 +++-- .../send_slack_notifications/action.yml | 39 ------ .github/workflows/release-production.yml | 127 ++++++++++-------- 3 files changed, 90 insertions(+), 109 deletions(-) delete mode 100644 .github/actions/send_slack_notifications/action.yml diff --git a/.github/actions/build_and_push_docker_image/action.yml b/.github/actions/build_and_push_docker_image/action.yml index d1f0b015..ebd3f819 100644 --- a/.github/actions/build_and_push_docker_image/action.yml +++ b/.github/actions/build_and_push_docker_image/action.yml @@ -31,32 +31,43 @@ 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=binary-static-developers" >> "$GITHUB_ENV" - echo "APP_VERSION=${{ inputs.APP_VERSION }}" >> "$GITHUB_ENV" - shell: bash - name: Build docker image 🐳 + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + APP_NAME: binary-static-developers + APP_VERSION: ${{ inputs.APP_VERSION }} run: docker build -t ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${APP_VERSION} -t ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }} . shell: bash - name: Verify nginx image + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + APP_NAME: binary-static-developers run: | set -e docker run --rm ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }} nginx -t echo "docker image validated successfully" shell: bash - name: Pushing Image to docker hub 🐳 + env: + DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }} + APP_NAME: binary-static-developers + APP_VERSION: ${{ inputs.APP_VERSION }} + DOCKERHUB_USERNAME: ${{ inputs.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ inputs.DOCKERHUB_PASSWORD }} run: | - echo ${{ inputs.DOCKERHUB_PASSWORD }}| docker login -u ${{ inputs.DOCKERHUB_USERNAME }} --password-stdin + echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin docker push ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${APP_VERSION} docker push ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }} shell: bash - name: Deploy 🚀 + env: + 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: binary-static-developers + APP_VERSION: ${{ inputs.APP_VERSION }} run: | git clone https://github.com/binary-com/devops-ci-scripts cd devops-ci-scripts/k8s-build_tools diff --git a/.github/actions/send_slack_notifications/action.yml b/.github/actions/send_slack_notifications/action.yml deleted file mode 100644 index 183954ee..00000000 --- a/.github/actions/send_slack_notifications/action.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: send_slack_notifications -description: Send Slack notifications -inputs: - SLACK_WEBHOOK_URL: - description: 'Slack webhook URL' - required: true - status: - description: 'Job status' - required: true - RELEASE_TYPE: - description: 'Release type' - required: true - version: - description: 'Version' - required: true - default: 'N/A' -runs: - using: composite - steps: - - name: Send Slack Notification on Success - - if: inputs.status == 'success' - run: | - curl -X POST -H 'Content-type: application/json' \ - --data '{ - "text": "${{ inputs.RELEASE_TYPE }} Release succeeded for developers.binary.com with version ${{ inputs.VERSION }}" - }' \ - ${{ inputs.SLACK_WEBHOOK_URL }} - shell: bash - - - name: Send Slack Notification on Failure - if: inputs.status == 'failure' - run: | - curl -X POST -H 'Content-type: application/json' \ - --data '{ - "text": "${{ inputs.RELEASE_TYPE }} Release failed for developers.binary.com with version ${{ inputs.VERSION }}" - }' \ - ${{ inputs.SLACK_WEBHOOK_URL }} - shell: bash diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml index 31b1607f..cf055ae4 100644 --- a/.github/workflows/release-production.yml +++ b/.github/workflows/release-production.yml @@ -1,63 +1,72 @@ name: Websocket Production Workflow on: - push: - branches: - - master + push: + branches: + - master +env: + RELEASE_TYPE: Production jobs: - build_test_and_publish: - name: Build, Test and Publish to Production - runs-on: ubuntu-latest - outputs: - RELEASE_VERSION: ${{ steps.extract_version.outputs.version }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - - name: Bundle Install - uses: ./.github/actions/bundle_install - - name: Build Jekyll site - uses: ./.github/actions/build_jekyll_site - - name: invalidate master cache - uses: ./.github/actions/invalidate_master_cache - - name: Versioning - id: extract_version - uses: ./.github/actions/versioning - with: - release_type: production - - name: Publish to Cloudflare Pages Production - uses: "./.github/actions/publish_to_pages_production" - with: - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - name: Build Docker image and push to Docker hub and K8S - uses: "./.github/actions/build_and_push_docker_image" - with: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} - K8S_NAMESPACE: "developers-binary-com-production" - KUBE_SERVER: ${{ secrets.KUBE_SERVER }} - SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} - CA_CRT: ${{ secrets.CA_CRT }} - APP_VERSION: latest + build_test_and_publish: + name: Build, Test and Publish to Production + runs-on: ubuntu-latest + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + - name: Bundle Install + uses: ./.github/actions/bundle_install + - name: Build Jekyll site + uses: ./.github/actions/build_jekyll_site + - name: invalidate master cache + uses: ./.github/actions/invalidate_master_cache + - name: Versioning + id: extract_version + uses: ./.github/actions/versioning + with: + RELEASE_TYPE: production + - name: Publish to Cloudflare Pages Production + uses: "./.github/actions/publish_to_pages_production" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + - name: Build Docker image and push to Docker hub and K8S + uses: "./.github/actions/build_and_push_docker_image" + with: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} + K8S_NAMESPACE: "developers-binary-com-production" + KUBE_SERVER: ${{ secrets.KUBE_SERVER }} + SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} + CA_CRT: ${{ secrets.CA_CRT }} + APP_VERSION: latest - - send_slack_notification: - name: Send Slack notification - runs-on: ubuntu-latest - if: always() - needs: [build_test_and_publish] - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Conclusion - uses: technote-space/workflow-conclusion-action@v3 - - name: Send Slack Notification - uses: "./.github/actions/send_slack_notifications" - with: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - status: ${{ env.WORKFLOW_CONCLUSION }} - release_type: Production - version: ${{ needs.build_test_and_publish.outputs.RELEASE_VERSION }} + send_slack_notification: + name: Send Slack notification + runs-on: ubuntu-latest + if: always() + needs: [build_test_and_publish] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Conclusion + uses: technote-space/workflow-conclusion-action@v3 + - name: Create Slack Message + env: + RELEASE_VERSION: ${{ needs.build_test_and_publish.outputs.RELEASE_VERSION }} + id: create_slack_message + run: | + if [ $WORKFLOW_CONCLUSION == "success" ]; then + echo "MESSAGE=$RELEASE_TYPE Release succeeded for developers.binary.com with version $RELEASE_VERSION" >> $GITHUB_OUTPUT + else + echo "MESSAGE=$RELEASE_TYPE Release failed for developers.binary.com with version $RELEASE_VERSION" >> $GITHUB_OUTPUT + fi + - name: Send Slack Notification + 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 }}