From 4e305953a2b46d39a109b1fa6bc34a0238cff208 Mon Sep 17 00:00:00 2001 From: branberry Date: Wed, 24 Jan 2024 14:14:40 -0600 Subject: [PATCH] [DOP-4171]: Add ability to pass snooty parser version to cdk --- .../cache-updater/cache-updater-worker-construct.ts | 6 +++++- cdk-infra/utils/env.ts | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cdk-infra/lib/constructs/cache-updater/cache-updater-worker-construct.ts b/cdk-infra/lib/constructs/cache-updater/cache-updater-worker-construct.ts index 990209978..31052e3c2 100644 --- a/cdk-infra/lib/constructs/cache-updater/cache-updater-worker-construct.ts +++ b/cdk-infra/lib/constructs/cache-updater/cache-updater-worker-construct.ts @@ -5,6 +5,7 @@ import { LogGroup } from 'aws-cdk-lib/aws-logs'; import { Bucket } from 'aws-cdk-lib/aws-s3'; import { Construct } from 'constructs'; import path from 'path'; +import { getSnootyParserVersion } from '../../../utils/env'; const SNOOTY_CACHE_BUCKET_NAME = 'snooty-parse-cache'; @@ -40,10 +41,13 @@ export class CacheUpdaterWorkerConstruct extends Construct { const containerName = 'cacheUpdaterWorkerImage'; const taskDefLogGroup = new LogGroup(this, 'cacheUpdaterWorkerLogGroup'); + + const snootyParserVersion = getSnootyParserVersion(); + taskDefinition.addContainer('cacheUpdaterWorkerImage', { image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), { file: 'src/cache-updater/Dockerfile.cacheUpdater', - buildArgs: { SNOOTY_PARSER_VERSION: '0.15.2' }, // TODO: Update this to use a context variable + buildArgs: { SNOOTY_PARSER_VERSION: snootyParserVersion }, exclude: ['tests/', 'node_modules/', 'cdk-infra/'], // adding this just in case it doesn't pick up our dockerignore }), environment: { diff --git a/cdk-infra/utils/env.ts b/cdk-infra/utils/env.ts index 27b065f8a..b12e62249 100644 --- a/cdk-infra/utils/env.ts +++ b/cdk-infra/utils/env.ts @@ -9,6 +9,7 @@ const autoBuilderContextVariables = [ 'customFeatureName', 'env', 'useCustomBuckets', + 'snootyParserVersion', ] as const; export type SnootyEnv = (typeof snootyEnvs)[number]; @@ -76,7 +77,13 @@ export function getEnv(): AutoBuilderEnv { export function isEnhanced(): boolean { return !!contextVarsMap.get('enhanced'); } +export function getSnootyParserVersion(): string { + checkContextInit(); + const snootyParserVersion = contextVarsMap.get('snootyParserVersion'); + if (!snootyParserVersion) throw new Error('Error! The context variable snootyParserVersion is not defined.'); + return snootyParserVersion; +} export function getFeatureName(): string { checkContextInit();