diff --git a/.github/actions/deploy_to_kubernetes/action.yml b/.github/actions/deploy_to_kubernetes/action.yml new file mode 100644 index 000000000..8909ef70d --- /dev/null +++ b/.github/actions/deploy_to_kubernetes/action.yml @@ -0,0 +1,27 @@ +name: k8s_deploy +description: Deploy to Kubernetes +inputs: + K8S_VERSION: + description: Kubernetes version + required: true + type: string + K8S_NAMESPACE: + description: Kubernetes namespace + required: false + type: string + default: 'deriv-com-api-staging' + CA_CRT: + description: Kubernetes CA certificate + required: true + type: string +steps: + - k8s/install-kubectl + - run: + name: Deploying to k8s cluster for service ${{ inputs.K8S_NAMESPACE }} 🚀 + command: | + export NAMESPACE=${{ inputs.K8S_NAMESPACE }} + 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 + export CA="ca.crt" + ./release.sh deriv-com-api ${{ inputs.K8S_VERSION }} diff --git a/.github/actions/publish_to_docker/action.yml b/.github/actions/publish_to_docker/action.yml new file mode 100644 index 000000000..fc493fab8 --- /dev/null +++ b/.github/actions/publish_to_docker/action.yml @@ -0,0 +1,41 @@ +name: docker_build_push +description: Build and push Docker image to Docker Hub +inputs: + DOCKER_LATEST_IMAGE_TAG: + description: Docker image tag + required: false + default: 'latest-staging' + type: string + DOCKER_IMAGE_TAG: + description: Docker image tag + required: true + type: string + DOCKERHUB_ORGANISATION: + description: Docker Hub organisation + required: true + type: string + DOCKERHUB_USERNAME: + description: Docker Hub username + required: true + type: string + DOCKERHUB_PASSWORD: + description: Docker Hub password + required: true + type: string + steps: + - setup_remote_docker + - run: + name: Building docker image 🐳 + command: | + 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 }} . + - name: Verify nginx image + run: | + set -e + docker run --rm ${{ inputs.DOCKERHUB_ORGANISATION }}/deriv-com-api:${{ inputs.DOCKER_LATEST_IMAGE_TAG }} nginx -t + echo "docker image validated successfully" + - run: + name: Pushing Image to docker hub 🐳 + command: | + 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 }} diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index dabeaae71..1add3cfce 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -33,6 +33,20 @@ jobs: with: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + - name: Publish to Docker + uses: ./.github/actions/publish_to_docker + with: + DOCKER_LATEST_IMAGE_TAG: 'latest' + DOCKER_IMAGE_TAG: ${{ secrets.SHA1 }} + DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Deploy to Kubernetes + uses: ./.github/actions/deploy_to_kubernetes + with: + K8S_VERSION: ${{ github.ref_name }} + K8S_NAMESPACE: 'deriv-com-api-production' + CA_CRT: ${{ secrets.CA_CRT }} send_slack_notification: name: Send Slack Notification environment: Production diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 249df8bd0..ec409a708 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -26,3 +26,17 @@ jobs: with: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + - name: Publish to Docker + uses: ./.github/actions/publish_to_docker + with: + DOCKER_LATEST_IMAGE_TAG: 'latest-staging' + DOCKER_IMAGE_TAG: ${{ secrets.SHA1 }} + DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Deploy to Kubernetes + uses: ./.github/actions/deploy_to_kubernetes + with: + K8S_VERSION: ${{ github.ref_name }} + K8S_NAMESPACE: 'deriv-com-api-staging' + CA_CRT: ${{ secrets.CA_CRT }}