From 8c9a668a0aa82fc56933b96433e6d73172a4bc2f Mon Sep 17 00:00:00 2001 From: yaswanth-deriv <121096908+yaswanth-deriv@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:07:20 +0400 Subject: [PATCH 1/4] Create action.yml --- .../build_and_push_docker_image/action.yml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/actions/build_and_push_docker_image/action.yml diff --git a/.github/actions/build_and_push_docker_image/action.yml b/.github/actions/build_and_push_docker_image/action.yml new file mode 100644 index 00000000000..4d6b75e6ca8 --- /dev/null +++ b/.github/actions/build_and_push_docker_image/action.yml @@ -0,0 +1,66 @@ +name: build_and_push_docker_image_and_k8s +description: Build docker image and push to docker hub and K8S +inputs: + DOCKERHUB_ORGANISATION: + description: "Dockerhub Organisation" + required: true + DOCKERHUB_USERNAME: + description: "Dockerhub Username" + required: true + DOCKERHUB_PASSWORD: + description: "Dockerhub Password" + required: true + K8S_NAMESPACE: + description: "K8S namespace" + required: true + K8S_SERVICE: + description: "K8S service" + required: true + KUBE_SERVER: + description: "K8S server" + required: true + SERVICEACCOUNT_TOKEN: + description: "K8S service account token" + required: true + CA_CRT: + description: "K8S CA_CRT" + required: true + APP_VERSION: + description: "App version" + required: true +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-binary-static" >> "$GITHUB_ENV" + echo "APP_VERSION=${{ inputs.APP_VERSION }}" >> "$GITHUB_ENV" + shell: bash + - name: Build docker image 🐳 + run: docker build -t ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${APP_VERSION} -t ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }} . + shell: bash + - name: Verify nginx image + 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 🐳 + run: | + echo ${{ inputs.DOCKERHUB_PASSWORD }}| docker login -u ${{ inputs.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 🚀 + run: | + git clone https://github.com/binary-com/devops-ci-scripts + cd devops-ci-scripts/k8s-build_tools + echo $CA_CRT | base64 --decode > ca.crt + export CA="ca.crt" + ./release.sh ${APP_NAME} ${{ github.ref_name }} + shell: bash From 5970d09c37f6c7dff30168b5ae124695f9516d9b Mon Sep 17 00:00:00 2001 From: yaswanth-deriv <121096908+yaswanth-deriv@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:09:45 +0400 Subject: [PATCH 2/4] Update release_production.yml --- .github/workflows/release_production.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 38012789cc4..7ac4b3dfa60 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -52,6 +52,17 @@ jobs: with: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + - name: Build Docker image and push to Docker hub and K8S + uses: "./.github/actions/build_and_push_docker_image" + with: + DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} + K8S_NAMESPACE: binary-static-production + KUBE_SERVER: ${{ secrets.KUBE_SERVER }} + SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} + CA_CRT: ${{ secrets.CA_CRT }} + APP_VERSION: latest notify_on_slack: name: Notify on Slack From 38091fb75f26f395378256327c143d5539e45e23 Mon Sep 17 00:00:00 2001 From: yaswanth-deriv <121096908+yaswanth-deriv@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:10:19 +0400 Subject: [PATCH 3/4] Update release_production.yml --- .github/workflows/release_production.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 7ac4b3dfa60..8b9ad169345 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -55,8 +55,8 @@ jobs: - name: Build Docker image and push to Docker hub and K8S uses: "./.github/actions/build_and_push_docker_image" with: - DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} K8S_NAMESPACE: binary-static-production KUBE_SERVER: ${{ secrets.KUBE_SERVER }} From 63103bb7f8c9e907545390a66643e019cf5e2fc4 Mon Sep 17 00:00:00 2001 From: yaswanth-deriv <121096908+yaswanth-deriv@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:13:33 +0400 Subject: [PATCH 4/4] Update release_staging.yml --- .github/workflows/release_staging.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index e37cbdaa146..51824c608fa 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -54,3 +54,14 @@ jobs: with: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + - 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: binary-static-staging + KUBE_SERVER: ${{ secrets.KUBE_SERVER }} + SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} + CA_CRT: ${{ secrets.CA_CRT }} + APP_VERSION: latest-staging