From b101fade77abc482aceae0a21ac7f5da11cbe9aa Mon Sep 17 00:00:00 2001 From: Sean Ho Date: Wed, 4 Aug 2021 11:23:28 +0800 Subject: [PATCH 1/4] cache public and cache directories during GH actions build --- .github/workflows/production.yml | 190 +++++++++++++++--------------- .github/workflows/staging.yml | 191 ++++++++++++++++--------------- 2 files changed, 191 insertions(+), 190 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 30e3316d89b..f0d414f9ba4 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -1,111 +1,109 @@ name: Release Production on: - push: - tags: - - 'production*' - paths-ignore: - - '**.md' + push: + tags: + - 'production*' + paths-ignore: + - '**.md' env: - GATSBY_CPU_COUNT: 2 - GATSBY_ENV: production + GATSBY_CPU_COUNT: 2 + GATSBY_ENV: production jobs: - lint: - timeout-minutes: 10 - runs-on: ubuntu-latest + lint: + timeout-minutes: 10 + runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 - - name: Set up Node.js - uses: actions/setup-node@v1 - with: - node-version: 12 - - name: Cache dependencies - id: cache - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ./node_modules - key: modules-${{ hashFiles('package-lock.json') }} - - name: Install Node.js dependencies - run: | - npm ci - npm test - - name: Run linters - uses: wearerequired/lint-action@v1 - with: - eslint: true + - name: Set up Node.js + uses: actions/setup-node@v1 + with: + node-version: 12 + - name: Cache dependencies + id: cache + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: | + public + .cache + ./node_modules + key: modules-${{ hashFiles('package-lock.json') }} + - name: Install Node.js dependencies + run: | + npm ci + npm test - release-production: - needs: lint - timeout-minutes: 30 - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 - - - name: Setup Node - uses: actions/setup-node@v2.1.2 - with: - node-version: '12.x' + release-production: + needs: lint + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - run: npm ci - - run: npm run format - - run: npm run test - - run: npm run build - - uses: olegtarasov/get-tag@v2.1 - id: tagName - # For using same tag for staging and production we need to uncomment these two below lines: - # with: - # tagRegex: "production(.*)" - - name: Building docker image 🐳 - run: docker build -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GIT_TAG_NAME . + - name: Setup Node + uses: actions/setup-node@v2.1.2 + with: + node-version: '12.x' - - name: Pushing Image to docker hub 🐳 - run: | - echo ${{ secrets.DOCKERHUB_PASSWORD }}| docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest - docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GIT_TAG_NAME + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- - - name: Deploy 🚀 - run: | - export NAMESPACE="deriv-com-production" - export SERVICEACCOUNT_TOKEN=${{ secrets.SERVICEACCOUNT_TOKEN }} - export DOCKERHUB_ORGANISATION=${{ secrets.DOCKERHUB_ORGANISATION }} - export KUBE_SERVER=${{ secrets.KUBE_SERVER }} - export CA=${{ secrets.CA }} - git clone https://github.com/binary-com/devops-ci-scripts - cd devops-ci-scripts/k8s-build_tools - echo ${{ secrets.CA_CRT}} | base64 --decode > ca.crt - ./release.sh deriv-com $GIT_TAG_NAME + - run: npm ci + - run: npm run format + - run: npm run test + - run: npm run build + - uses: olegtarasov/get-tag@v2.1 + id: tagName + # For using same tag for staging and production we need to uncomment these two below lines: + # with: + # tagRegex: "production(.*)" + - name: Building docker image 🐳 + run: docker build -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GIT_TAG_NAME . - - name: Slack Notification 📣 - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: workflow,repo - if_mention: failure,cancelled - custom_payload: | - { - attachments: [{ - color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', - text: `Release for *Deriv.com* with version *$GIT_TAG_NAME*` - }] - } - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - if: always() + - name: Pushing Image to docker hub 🐳 + run: | + echo ${{ secrets.DOCKERHUB_PASSWORD }}| docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest + docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GIT_TAG_NAME + - name: Deploy 🚀 + run: | + export NAMESPACE="deriv-com-production" + export SERVICEACCOUNT_TOKEN=${{ secrets.SERVICEACCOUNT_TOKEN }} + export DOCKERHUB_ORGANISATION=${{ secrets.DOCKERHUB_ORGANISATION }} + export KUBE_SERVER=${{ secrets.KUBE_SERVER }} + export CA=${{ secrets.CA }} + git clone https://github.com/binary-com/devops-ci-scripts + cd devops-ci-scripts/k8s-build_tools + echo ${{ secrets.CA_CRT}} | base64 --decode > ca.crt + ./release.sh deriv-com $GIT_TAG_NAME + + - name: Slack Notification 📣 + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,repo + if_mention: failure,cancelled + custom_payload: | + { + attachments: [{ + color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', + text: `Release for *Deriv.com* with version *$GIT_TAG_NAME*` + }] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + if: always() diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index d76e2a3f6a3..5f00cf54e34 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,108 +1,111 @@ name: Release Staging on: - push: - branches: - - master - paths-ignore: - - '**.md' - repository_dispatch: - types: [publish_blog] + push: + branches: + - master + paths-ignore: + - '**.md' + repository_dispatch: + types: [publish_blog] env: - GATSBY_CPU_COUNT: 2 - GATSBY_ENV: staging + GATSBY_CPU_COUNT: 2 + GATSBY_ENV: staging jobs: - lint: - timeout-minutes: 10 - runs-on: ubuntu-latest + lint: + timeout-minutes: 10 + runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 - - name: Set up Node.js - uses: actions/setup-node@v1 - with: - node-version: 12 - - name: Cache dependencies - id: cache - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ./node_modules - key: modules-${{ hashFiles('package-lock.json') }} - - name: Install Node.js dependencies - run: | - npm ci - npm test + - name: Set up Node.js + uses: actions/setup-node@v1 + with: + node-version: 12 + - name: Cache dependencies + id: cache + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: | + public + .cache + ./node_modules + key: modules-${{ hashFiles('package-lock.json') }} + - name: Install Node.js dependencies + run: | + npm ci + npm test - release-staging: - needs: lint - timeout-minutes: 30 - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 - - - name: Setup Node - uses: actions/setup-node@v2.1.2 - with: - node-version: '12.x' + release-staging: + needs: lint + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - run: npm ci - - run: npm run format - - run: npm run test - - run: npm run build - - uses: olegtarasov/get-tag@v2.1 - id: tagName - # For using same tag for staging and production we need to uncomment these two below lines: - # with: - # tagRegex: "staging(.*)" - - name: Building docker image 🐳 - run: docker build -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest-staging -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GITHUB_SHA . + - name: Setup Node + uses: actions/setup-node@v2.1.2 + with: + node-version: '12.x' - - name: Pushing Image to docker hub 🐳 - run: | - echo ${{ secrets.DOCKERHUB_PASSWORD }}| docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest-staging - docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GITHUB_SHA + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- - - name: Deploy 🚀 - run: | - export NAMESPACE="deriv-com-staging" - export SERVICEACCOUNT_TOKEN=${{ secrets.SERVICEACCOUNT_TOKEN }} - export DOCKERHUB_ORGANISATION=${{ secrets.DOCKERHUB_ORGANISATION }} - export KUBE_SERVER=${{ secrets.KUBE_SERVER }} - export CA=${{ secrets.CA }} - git clone https://github.com/binary-com/devops-ci-scripts - cd devops-ci-scripts/k8s-build_tools - echo ${{ secrets.CA_CRT}} | base64 --decode > ca.crt - ./release.sh deriv-com $GITHUB_SHA + - run: npm ci + - run: npm run format + - run: npm run test + - run: npm run build + - uses: olegtarasov/get-tag@v2.1 + id: tagName + # For using same tag for staging and production we need to uncomment these two below lines: + # with: + # tagRegex: "staging(.*)" + - name: Building docker image 🐳 + run: docker build -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest-staging -t ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GITHUB_SHA . - - name: Slack Notification 📣 - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: workflow,repo - if_mention: failure,cancelled - custom_payload: | - { - attachments: [{ - color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', - text: `Release for *Deriv.com* with version *$GITHUB_SHA*` - }] - } - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - if: always() + - name: Pushing Image to docker hub 🐳 + run: | + echo ${{ secrets.DOCKERHUB_PASSWORD }}| docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:latest-staging + docker push ${{ secrets.DOCKHUB_ORGANISATION }}/deriv-com:$GITHUB_SHA + + - name: Deploy 🚀 + run: | + export NAMESPACE="deriv-com-staging" + export SERVICEACCOUNT_TOKEN=${{ secrets.SERVICEACCOUNT_TOKEN }} + export DOCKERHUB_ORGANISATION=${{ secrets.DOCKERHUB_ORGANISATION }} + export KUBE_SERVER=${{ secrets.KUBE_SERVER }} + export CA=${{ secrets.CA }} + git clone https://github.com/binary-com/devops-ci-scripts + cd devops-ci-scripts/k8s-build_tools + echo ${{ secrets.CA_CRT}} | base64 --decode > ca.crt + ./release.sh deriv-com $GITHUB_SHA + + - name: Slack Notification 📣 + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: workflow,repo + if_mention: failure,cancelled + custom_payload: | + { + attachments: [{ + color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', + text: `Release for *Deriv.com* with version *$GITHUB_SHA*` + }] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + if: always() From 849251cafed10a510695fe5418d025b16278ae04 Mon Sep 17 00:00:00 2001 From: Sean Ho Date: Mon, 9 Aug 2021 13:58:52 +0800 Subject: [PATCH 2/4] cache public and cache directories during GH actions build --- .github/workflows/staging.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 5f00cf54e34..e0ae194bf97 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -32,11 +32,8 @@ jobs: env: cache-name: cache-node-modules with: - path: | - public - .cache - ./node_modules - key: modules-${{ hashFiles('package-lock.json') }} + path: ./node_modules + key: modules-${{ hashFiles('package-lock.json') }} - name: Install Node.js dependencies run: | npm ci @@ -63,6 +60,17 @@ jobs: restore-keys: | ${{ runner.os }}-node- + - name: Caching Gatsby + id: gatsby-cache-build + uses: actions/cache@v2 + with: + path: | + public + .cache + key: ${{ runner.os }}-gatsby-build-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-gatsby-build- + - run: npm ci - run: npm run format - run: npm run test From d833b906a9d94e13b7cbe799557aacc5cd074ab3 Mon Sep 17 00:00:00 2001 From: Sean Ho Date: Mon, 9 Aug 2021 14:02:59 +0800 Subject: [PATCH 3/4] cache public and cache directories during GH actions build --- .github/workflows/production.yml | 18 +++++++++++++----- .github/workflows/staging.yml | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index f0d414f9ba4..53052229720 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -30,11 +30,8 @@ jobs: env: cache-name: cache-node-modules with: - path: | - public - .cache - ./node_modules - key: modules-${{ hashFiles('package-lock.json') }} + path: ./node_modules + key: modules-${{ hashFiles('package-lock.json') }} - name: Install Node.js dependencies run: | npm ci @@ -61,6 +58,17 @@ jobs: restore-keys: | ${{ runner.os }}-node- + - name: Cache Gatsby + id: gatsby-cache-build + uses: actions/cache@v2 + with: + path: | + public + .cache + key: ${{ runner.os }}-gatsby-build-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-gatsby-build- + - run: npm ci - run: npm run format - run: npm run test diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index e0ae194bf97..439b2f247b9 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -60,7 +60,7 @@ jobs: restore-keys: | ${{ runner.os }}-node- - - name: Caching Gatsby + - name: Cache Gatsby id: gatsby-cache-build uses: actions/cache@v2 with: From f38a8afd0180e416c65b0819c6b822bd6543398f Mon Sep 17 00:00:00 2001 From: Sean Ho Date: Wed, 11 Aug 2021 11:36:32 +0800 Subject: [PATCH 4/4] script: log built pages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73b848258b4..26ca740e3fb 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ ], "license": "Apache License 2.0", "scripts": { - "build": "gatsby build", + "build": "gatsby build --log-pages", "develop": "gatsby develop -o", "format": "prettier --write '**/*.js' '*.js'", "stylelint": "stylelint 'src/**/*.js' --formatter verbose",