Skip to content

Commit

Permalink
Merge pull request #188 from yaswanth-deriv/yaswanth/FEQ-1233_Websock…
Browse files Browse the repository at this point in the history
…ets-CircleCi-Migration-to-github-actions

[FEQ]Yaswanth/FEQ-1233/Migration from circle-ci to github work actions
  • Loading branch information
ali-hosseini-deriv authored Jan 8, 2024
2 parents f6e7983 + 592a8fc commit c724502
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/actions/build_and_push_docker_image/action.yml
Original file line number Diff line number Diff line change
@@ -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=binary-static-developers" >> "$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
20 changes: 20 additions & 0 deletions .github/actions/build_jekyll_site/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: build
description: "Build Jekyll site"
runs:
using: composite
steps:
- restore_cache:
name: "Build cache restore"
keys:
- _site-v1-{{ .Revision }}
- _site-v1-
- build_site:
name: Building Jekyll site
run: |
bundle exec jekyll build --incremental
- save_cache:
name: Build cache save
key: _site-v1-{{ .Revision }}
with:
paths:
- _site
20 changes: 20 additions & 0 deletions .github/actions/bundle_install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: bundle_install
description: Bundle Install
runs:
using: composite
steps:
- restore_cache:
name: Bundle modules cache restore
keys:
- bundle-v1-{{ checksum "Gemfile" }}
- bundle-v1-
- bundle_install:
name: Bundle install
run: |
bundle install --path ./modules
- save_cache:
name: Bundle modules cache save
key: bundle-v1-{{ checksum "Gemfile" }}
with:
paths:
- "modules"
10 changes: 10 additions & 0 deletions .github/actions/invalidate_master_cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: invalidate_npm_cache
description: Invalidate the Master NPM cache
runs:
using: composite
steps:
- name: save_cache
uses: actions/cache/save@v3
with:
path: ./node_modules
key: v1-deps-{{ checksum "Gemfile" }}
21 changes: 21 additions & 0 deletions .github/actions/publish_to_pages_production/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: publish_to_pages_production
description: Publish to cloudflare pages (production)
inputs:
CLOUDFLARE_ACCOUNT_ID:
description: 'Cloudflare account id'
required: true
CLOUDFLARE_API_TOKEN:
description: 'Cloudflare token'
required: true
runs:
using: composite
steps:
- name: Publish to cloudflare pages (production)
env:
CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }}
run: |
cd _site
npx wrangler pages publish . --project-name=websockets-pages --branch=main
echo "New website - http://cf-pages-websockets.binary.com"
shell: bash
21 changes: 21 additions & 0 deletions .github/actions/publish_to_pages_staging/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: publish_to_pages_staging
description: Publish to cloudflare pages (staging)
inputs:
CLOUDFLARE_ACCOUNT_ID:
description: 'Cloudflare account id'
required: true
CLOUDFLARE_API_TOKEN:
description: 'Cloudflare token'
required: true
runs:
using: composite
steps:
- name: Publish to cloudflare pages (staging)
env:
CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }}
run: |
cd _site
npx wrangler pages publish . --project-name=websockets-pages --branch=staging
echo "New staging website - http://staging.cf-pages-websockets.binary.com"
shell: bash
39 changes: 39 additions & 0 deletions .github/actions/send_slack_notifications/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 dsmarttrader.deriv.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 dsmarttrader.deriv.com with version ${{ inputs.VERSION }}"
}' \
${{ inputs.SLACK_WEBHOOK_URL }}
shell: bash
9 changes: 9 additions & 0 deletions .github/actions/setup_node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Setup Node
description: Setup Node.js environment
runs:
using: composite
steps:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
16 changes: 16 additions & 0 deletions .github/actions/versioning/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: versioning
description: Versioning
inputs:
RELEASE_TYPE:
description: Release Type
required: false
outputs:
version:
description: Version
runs:
using: composite
steps:
- run:
name: Tag build
run: echo "${GITHUB_REF#refs/heads/} $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > _site/version
shell: bash
55 changes: 55 additions & 0 deletions .github/workflows/release-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Websocket Production Workflow
on:
push:
tags:
- production_*
jobs:
build_test_and_publish:
name: Build, Test and Publish to Production
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Bundle Install
uses: ./.github/actions/bundle_install
- name: Build Jekyll site
uses: ./.github/actions/build
- name: Versioning
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
environment: Production
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: $GITHUB_REF_NAME
36 changes: 36 additions & 0 deletions .github/workflows/release-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Websocket Staging Workflow
on:
push:
branches:
- master
jobs:
build_test_and_publish:
name: Build, Test and Publish to Staging
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Bundle Install
uses: ./.github/actions/bundle_install
- name: Build Jekyll site
uses: ./.github/actions/build
- name: Versioning
uses: ./.github/actions/versioning
with:
release_type: staging
- name: Publish to Cloudflare Pages Staging
uses: "./.github/actions/publish_to_pages_staging"
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-staging"
KUBE_SERVER: ${{ secrets.KUBE_SERVER }}
SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }}
CA_CRT: ${{ secrets.CA_CRT }}
APP_VERSION: latest-staging

0 comments on commit c724502

Please sign in to comment.