Skip to content

Commit a91cf41

Browse files
Move Algolia update from deploy Cloud Build job to separate one (GoogleChrome#6544)
* chore: outsource cloudbuild job to update algolia from deploy * perf: fetch algolia index from prod
1 parent 93bb559 commit a91cf41

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

.cloudbuild/deploy.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ steps:
1717
env:
1818
- 'NODE_OPTIONS="--max_old_space_size=8192"' # https://github.com/GoogleChrome/developer.chrome.com/issues/2439
1919

20-
- name: node:16.14.2
21-
entrypoint: npm
22-
args: ['run', 'algolia']
23-
2420
- name: 'gcr.io/cloud-builders/gcloud'
2521
entrypoint: 'bash'
2622
args:

.cloudbuild/updateAlgoliaIndex.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
timeout: 600s # set build timeout to 10 mins
2+
steps:
3+
- name: node:16.14.2
4+
entrypoint: npm
5+
args: ['ci']
6+
7+
- name: node:16.14.2
8+
entrypoint: npm
9+
args: ['run', 'cloud-secrets']
10+
11+
- name: node:16.14.2
12+
entrypoint: npm
13+
args: ['run', 'algolia']
14+
15+
substitutions:
16+
_EXTRA_GCLOUD_ARGS: # default empty
17+
18+
options:
19+
machineType: 'E2_HIGHCPU_32'
20+
env:
21+
- 'PROJECT_ID=$PROJECT_ID'

algolia.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
* limitations under the License.
1515
*/
1616
require('dotenv').config();
17+
1718
const {default: algoliasearch} = require('algoliasearch');
18-
const fs = require('fs');
19+
const {default: fetch} = require('node-fetch');
1920
const {sizeof} = require('sizeof');
2021

22+
const algoliaIndexSource = 'https://developers.chrome.com/algolia.json';
23+
2124
const maxChunkSizeInBytes = 10000000; // 10,000,000
2225

2326
/**
@@ -53,8 +56,14 @@ async function index() {
5356
return;
5457
}
5558

56-
const raw = fs.readFileSync('dist/algolia.json', 'utf-8');
57-
const algoliaData = JSON.parse(raw);
59+
let algoliaData = [];
60+
try {
61+
const raw = await fetch(algoliaIndexSource);
62+
algoliaData = await raw.json();
63+
} catch (err) {
64+
console.error('Could not load algolia index from prod.', err);
65+
return;
66+
}
5867

5968
// Set date of when object is being added to algolia
6069
algoliaData.map(e => {

0 commit comments

Comments
 (0)