diff --git a/script/prerender/constants.ts b/script/prerender/constants.ts new file mode 100644 index 00000000000..2f989a8fe36 --- /dev/null +++ b/script/prerender/constants.ts @@ -0,0 +1,8 @@ +import config from '../../src/config'; +import { assertDefined } from '../../src/app/utils'; + +export const RELEASE_ID = assertDefined(config.RELEASE_ID, 'REACT_APP_RELEASE_ID environment variable must be set'); +export const BUCKET_NAME = process.env.BUCKET_NAME || 'sandbox-unified-web-primary'; +export const BUCKET_REGION = process.env.BUCKET_REGION || 'us-east-1'; +export const PUBLIC_URL = process.env.PUBLIC_URL || `/rex/releases/${RELEASE_ID}`; +export const WORK_REGION = process.env.WORK_REGION || 'us-east-2'; diff --git a/script/prerender/fileUtils.ts b/script/prerender/fileUtils.ts index 5f6b8805f99..2844abd4ee0 100644 --- a/script/prerender/fileUtils.ts +++ b/script/prerender/fileUtils.ts @@ -5,9 +5,9 @@ import { fromContainerMetadata } from '@aws-sdk/credential-providers'; import flow from 'lodash/fp/flow'; import once from 'lodash/once'; import path from 'path'; -import { assertDefined } from '../../src/app/utils'; import createCache, { Cache } from '../../src/helpers/createCache'; import { directoryExists, readFile, writeFile } from '../../src/helpers/fileUtils'; +import { BUCKET_REGION, PUBLIC_URL, BUCKET_NAME } from './constants'; const ASSET_DIR = path.resolve(__dirname, '../../build'); const CACHE_DIR = path.resolve(__dirname, '../../cache'); @@ -51,7 +51,7 @@ export const createDiskCache = (prefix: string): Cache { const credentials = await fromContainerMetadata(); console.log('Initializing S3 client'); - return new S3Client({ credentials, region: process.env.BUCKET_REGION }); + return new S3Client({ credentials, region: BUCKET_REGION }); }); async function writeS3File(key: string, contents: string, contentType: string) { @@ -70,7 +70,7 @@ async function writeS3File(key: string, contents: string, contentType: string) { console.log(`Writing s3 file: /${key}`); return s3Client.send(new PutObjectCommand({ Body: contents, - Bucket: process.env.BUCKET_NAME, + Bucket: BUCKET_NAME, CacheControl: 'max-age=0', ContentType: contentType, Key: key, diff --git a/script/prerender/fleet.ts b/script/prerender/fleet.ts index 9e5173110c9..03412ac1a76 100644 --- a/script/prerender/fleet.ts +++ b/script/prerender/fleet.ts @@ -36,7 +36,6 @@ import path from 'path'; import asyncPool from 'tiny-async-pool'; import { makeUnifiedBookLoader } from '../../src/app/content/utils'; import { assertDefined } from '../../src/app/utils'; -import config from '../../src/config'; import BOOKS from '../../src/config.books'; import createArchiveLoader from '../../src/gateways/createArchiveLoader'; import { getBooksConfigSync } from '../../src/gateways/createBookConfigLoader'; @@ -50,16 +49,8 @@ import renderManifest from './renderManifest'; import { SitemapPayload, renderAndSaveSitemapIndex } from './sitemap'; import { writeS3ReleaseXmlFile } from './fileUtils'; import { renderAndSaveContentManifest } from './contentManifest'; - -const { - ARCHIVE_URL, - CODE_VERSION, - OS_WEB_URL, - REACT_APP_OS_WEB_API_URL, - RELEASE_ID, -} = config; - -assertDefined(RELEASE_ID, 'REACT_APP_RELEASE_ID environment variable must be set'); +import { ARCHIVE_URL, OS_WEB_URL, REACT_APP_OS_WEB_API_URL, CODE_VERSION } from '../../src/config'; +import { RELEASE_ID, WORK_REGION, BUCKET_NAME, BUCKET_REGION, PUBLIC_URL } from './constants'; // Increasing this too much can lead to connection issues and greater memory usage in the manager const MAX_CONCURRENT_BOOKS = 5; @@ -75,11 +66,6 @@ const PRERENDER_TIMEOUT_SECONDS = 3600; const WORKERS_STACK_CREATE_TIMEOUT_SECONDS = 300; const WORKERS_STACK_DELETE_TIMEOUT_SECONDS = WORKERS_STACK_CREATE_TIMEOUT_SECONDS; -const BUCKET_NAME = process.env.BUCKET_NAME || 'sandbox-unified-web-primary'; -const BUCKET_REGION = process.env.BUCKET_REGION || 'us-east-1'; -const PUBLIC_URL = process.env.PUBLIC_URL || `/rex/releases/${RELEASE_ID}`; -const WORK_REGION = process.env.WORK_REGION || 'us-east-2'; - // Docker does not accept forward slashes in the image tag const IMAGE_TAG = process.env.IMAGE_TAG || `${RELEASE_ID.replace(/\//g, '-')}`; @@ -367,8 +353,10 @@ async function queueWork(workQueueUrl: string) { `All ${stats.pages} page prerendering jobs and all ${stats.sitemaps} sitemap jobs queued` ); - renderAndSaveSitemapIndex(writeS3ReleaseXmlFile, books); - renderAndSaveContentManifest(writeS3ReleaseXmlFile, books); + await Promise.all([ + renderAndSaveSitemapIndex(writeS3ReleaseXmlFile, books), + renderAndSaveContentManifest(writeS3ReleaseXmlFile, books), + ]); return stats; }