Skip to content

Commit

Permalink
Merge branch 'deriv-com:master' into kate/DTRA-1014/add_check_for_hea…
Browse files Browse the repository at this point in the history
…der_hash
  • Loading branch information
kate-deriv authored Jun 3, 2024
2 parents 9671c39 + 797c787 commit c01a48a
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 279 deletions.
12 changes: 7 additions & 5 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Build
description: Build dist
description: Build dist
inputs:
target:
description: 'Target Environment'
description: "Target Environment"
required: true
default: staging
runs:
using: composite
steps:
- name: Building dist for ${{ inputs.target }}
run: node_modules/grunt/bin/grunt releaseci --${{ inputs.target }}
shell: bash
- name: Building dist for ${{ inputs.target }}
env:
TARGET_ENV: ${{ inputs.target }}
run: node_modules/grunt/bin/grunt releaseci --$TARGET_ENV
shell: bash
43 changes: 27 additions & 16 deletions .github/actions/build_and_push_docker_image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,47 @@ 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=smarttrader-deriv-app" >> "$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 }} .
env:
DOCKERHUB_ORGANISATION: ${{ inputs.DOCKERHUB_ORGANISATION }}
APP_NAME: smarttrader-deriv-app
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: smarttrader-deriv-app
run: |
set -e
docker run --rm ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }} nginx -t
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: smarttrader-deriv-app
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
docker push ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${APP_VERSION}
docker push ${DOCKERHUB_ORGANISATION}/${APP_NAME}:${{ github.ref_name }}
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: smarttrader-deriv-app
APP_VERSION: ${{ inputs.APP_VERSION }}
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 }}
./release.sh $APP_NAME ${{ github.ref_name }}
shell: bash
40 changes: 0 additions & 40 deletions .github/actions/notify_slack/action.yml

This file was deleted.

10 changes: 6 additions & 4 deletions .github/actions/versioning/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: versioning
description: Tag build
inputs:
target_branch:
description: 'Target branch'
description: "Target branch"
required: false
runs:
using: composite
steps:
- name: Tag build
run: echo "${{ inputs.target_branch }} $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > dist/version.txt
shell: bash
- name: Tag build
env:
TARGET_BRANCH: ${{ inputs.target_branch }}
run: echo "$TARGET_BRANCH $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > dist/version.txt
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/generate_preview_link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
node-version: 18.x

- name: Install dependencies
uses: "deriv-com/shared-actions/.github/actions/npm_install@v1"
uses: "deriv-com/shared-actions/.github/actions/npm_install@master"

- name: Build
uses: "./.github/actions/build"
Expand Down
31 changes: 24 additions & 7 deletions .github/workflows/release_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
env:
RELEASE_TYPE: Production
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
Expand Down Expand Up @@ -34,6 +36,8 @@ jobs:
publish_cloudflare_production:
name: Publish to Cloudflare Production
runs-on: ubuntu-latest
env:
RELEASE_TYPE: Production
needs: [build_and_test]
steps:
- name: Checkout
Expand All @@ -53,6 +57,7 @@ jobs:
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
id: build_and_push_docker_image
uses: "./.github/actions/build_and_push_docker_image"
with:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -63,12 +68,19 @@ jobs:
SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }}
CA_CRT: ${{ secrets.CA_CRT }}
APP_VERSION: latest

- name: Send Slack Notification on Docker Publish and Kubernetes Deployment Failure
if: ${{ steps.build_and_push_docker_image.outcome != 'success' }}
uses: "deriv-com/shared-actions/.github/actions/send_slack_notification@master"
with:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
MESSAGE: "$RELEASE_TYPE Docker Publish and Kubernetes Deployment for smarttrader.deriv.com with version ${{ needs.build_and_test.outputs.RELEASE_VERSION }} has Failed"
notify_on_slack:
name: Notify on Slack
if: always()
runs-on: ubuntu-latest

env:
RELEASE_TYPE: Production
APP_NAME: smarttrader-deriv-app
needs: [publish_cloudflare_production, build_and_test]
steps:
- name: Checkout
Expand All @@ -79,7 +91,6 @@ jobs:
node-version: 20
- name: Conclusion
uses: technote-space/workflow-conclusion-action@45ce8e0eb155657ab8ccf346ade734257fd196a5

- name: Download Artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a
with:
Expand All @@ -88,10 +99,16 @@ jobs:
- name: Grab Version Name
id: extract_version
run: echo "RELEASE_VERSION=$(cat dist/version.txt)" >> $GITHUB_ENV
- name: Create Slack Message
id: create_slack_message
run: |
if [ $WORKFLOW_CONCLUSION == "success" ]; then
echo "MESSAGE=$RELEASE_TYPE Release succeeded for $APP_NAME with version ${{ needs.build_and_test.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
else
echo "MESSAGE=$RELEASE_TYPE Release failed for $APP_NAME with version ${{ needs.build_and_test.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 }}
status: ${{ env.WORKFLOW_CONCLUSION }}
release_type: Production
version: ${{ steps.extract_version.outputs.RELEASE_VERSION }}
MESSAGE: ${{ steps.create_slack_message.outputs.MESSAGE }}
1 change: 1 addition & 0 deletions build/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ release:
releaseci:
- 'default'
- 'shell:compile_production'
- 'hashres'
3 changes: 0 additions & 3 deletions build/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ module.exports = function (grunt) {
{ expand: true, cwd: 'src/download/fonts', src: ['binary_symbols.woff'], dest: `${global.dist}/download/fonts/` },

{ expand: true, src: ['favicon.ico'], dest: global.dist },

// Serve pushwoosh SDKs
{ expand: true, cwd: 'src/javascript/_common/lib/pushwooshSDK/', src: ['**'], dest: global.dist },
{ expand: true, cwd: 'src/root_files/app', src: ['**', '!index.html'], dest: 'dist' }, // top level
{ expand: true, cwd: 'src/root_files/app', src: ['index.html'], dest: global.dist },

Expand Down
17 changes: 17 additions & 0 deletions build/hashres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
options: {
encoding: "utf8",
length: 8,
algorithm: "md5",
renameFiles: false,
fileNameFormat: "${name}.${ext}?${hash}",
},
main: {
src: [
"dist/css/*.css",
"dist/js/**/*.js",
"dist/images/**/*.{png,jpg,jpeg,gif,webp,svg}",
],
dest: "dist/**/*.html",
},
};
8 changes: 7 additions & 1 deletion build/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ module.exports = function (grunt) {
return {
options: {
processors: [
require('autoprefixer')()
require('autoprefixer')(),
require('postcss-cachebuster')({
supportedProps: [
'background',
'background-image',
],
}),
],
},
dist: {
Expand Down
9 changes: 8 additions & 1 deletion build/webpack/plugins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const CircularDependencyPlugin = require('circular-dependency-plugin');
const CryptoJS = require('crypto-js');
const path = require('path');
const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
Expand Down Expand Up @@ -47,7 +48,8 @@ const getPlugins = (app, grunt) => ([

new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
BUILD_HASH: JSON.stringify(CryptoJS.MD5(Date.now().toString()).toString()),
NODE_ENV : JSON.stringify('production'),
},
}),
]
Expand All @@ -60,6 +62,11 @@ const getPlugins = (app, grunt) => ([
openAnalyzer : false,
}),
]),
new webpack.DefinePlugin({
'process.env': {
BUILD_HASH: JSON.stringify(CryptoJS.MD5(Date.now().toString()).toString()),
},
}),
]
),
]);
Expand Down
Binary file modified favicon.ico
Binary file not shown.
Loading

0 comments on commit c01a48a

Please sign in to comment.