diff --git a/api/controllers/v2/cache.ts b/api/controllers/v2/cache.ts index 056d97883..052e49a33 100644 --- a/api/controllers/v2/cache.ts +++ b/api/controllers/v2/cache.ts @@ -29,10 +29,12 @@ async function runCacheRebuildJob(repos: RepoInfo[]) { const TASK_DEFINITION = process.env.TASK_DEFINITION; const CONTAINER_NAME = process.env.CONTAINER_NAME; const CLUSTER = process.env.CLUSTER; + const SUBNETS = process.env.SUBNETS; if (!TASK_DEFINITION) throw new Error('ERROR! process.env.TASK_DEFINITION is not defined'); if (!CONTAINER_NAME) throw new Error('ERROR! process.env.CONTAINER_NAME is not defined'); if (!CLUSTER) throw new Error('ERROR! process.env.CLUSTER is not defined'); + if (!SUBNETS) throw new Error('ERROR! process.env.SUBNETS is not defined'); const client = new ECSClient({ region: 'us-east-2', @@ -41,6 +43,12 @@ async function runCacheRebuildJob(repos: RepoInfo[]) { const command = new RunTaskCommand({ taskDefinition: TASK_DEFINITION, cluster: CLUSTER, + launchType: 'FARGATE', + networkConfiguration: { + awsvpcConfiguration: { + subnets: JSON.parse(SUBNETS), + }, + }, overrides: { containerOverrides: [ { diff --git a/cdk-infra/bin/cdk-infra.ts b/cdk-infra/bin/cdk-infra.ts index 979a6178c..40f4060cb 100644 --- a/cdk-infra/bin/cdk-infra.ts +++ b/cdk-infra/bin/cdk-infra.ts @@ -46,7 +46,7 @@ async function main() { env, }); - new CacheUpdaterStack(app, `${stackName}-cache`, { vpc }); + new CacheUpdaterStack(app, `${stackName}-cache`, { vpc, env }); } main(); diff --git a/cdk-infra/lib/constructs/auto-builder-vpc-construct.ts b/cdk-infra/lib/constructs/auto-builder-vpc-construct.ts index fdfe11ea8..b1b97cfdf 100644 --- a/cdk-infra/lib/constructs/auto-builder-vpc-construct.ts +++ b/cdk-infra/lib/constructs/auto-builder-vpc-construct.ts @@ -1,8 +1,8 @@ -import { Vpc, GatewayVpcEndpointAwsService, InterfaceVpcEndpointAwsService, IVpc } from 'aws-cdk-lib/aws-ec2'; +import { Vpc, GatewayVpcEndpointAwsService, InterfaceVpcEndpointAwsService } from 'aws-cdk-lib/aws-ec2'; import { Construct } from 'constructs'; export class AutoBuilderVpcConstruct extends Construct { - readonly vpc: IVpc; + readonly vpc: Vpc; constructor(scope: Construct, id: string) { super(scope, id); diff --git a/cdk-infra/lib/constructs/cache-updater/cache-updater-api-construct.ts b/cdk-infra/lib/constructs/cache-updater/cache-updater-api-construct.ts index e8884af66..cd2420a22 100644 --- a/cdk-infra/lib/constructs/cache-updater/cache-updater-api-construct.ts +++ b/cdk-infra/lib/constructs/cache-updater/cache-updater-api-construct.ts @@ -1,5 +1,6 @@ import { Duration } from 'aws-cdk-lib'; import { Cors, LambdaIntegration, LambdaRestApi } from 'aws-cdk-lib/aws-apigateway'; +import { Vpc } from 'aws-cdk-lib/aws-ec2'; import { TaskDefinition } from 'aws-cdk-lib/aws-ecs'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; @@ -10,6 +11,7 @@ interface CacheUpdaterApiConstructProps { clusterName: string; taskDefinition: TaskDefinition; containerName: string; + vpc: Vpc; } const HANDLERS_PATH = path.join(__dirname, '/../../../../api/controllers/v2'); @@ -18,7 +20,7 @@ export class CacheUpdaterApiConstruct extends Construct { constructor( scope: Construct, id: string, - { clusterName, taskDefinition, containerName }: CacheUpdaterApiConstructProps + { clusterName, taskDefinition, containerName, vpc }: CacheUpdaterApiConstructProps ) { super(scope, id); @@ -32,6 +34,7 @@ export class CacheUpdaterApiConstruct extends Construct { CLUSTER: clusterName, TASK_DEFINITION: taskDefinition.taskDefinitionArn, CONTAINER_NAME: containerName, + SUBNETS: JSON.stringify(vpc.privateSubnets.map((subnet) => subnet.subnetId)), }, }); diff --git a/cdk-infra/lib/stacks/auto-builder-vpc-stack.ts b/cdk-infra/lib/stacks/auto-builder-vpc-stack.ts index 0fe16c591..8cd4fab5c 100644 --- a/cdk-infra/lib/stacks/auto-builder-vpc-stack.ts +++ b/cdk-infra/lib/stacks/auto-builder-vpc-stack.ts @@ -1,10 +1,10 @@ import { Stack, StackProps } from 'aws-cdk-lib'; -import { IVpc } from 'aws-cdk-lib/aws-ec2'; +import { Vpc } from 'aws-cdk-lib/aws-ec2'; import { Construct } from 'constructs'; import { AutoBuilderVpcConstruct } from '../constructs/auto-builder-vpc-construct'; export class AutoBuilderVpcStack extends Stack { - readonly vpc: IVpc; + readonly vpc: Vpc; constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); diff --git a/cdk-infra/lib/stacks/cache-updater-stack.ts b/cdk-infra/lib/stacks/cache-updater-stack.ts index d7919a545..0c7255a59 100644 --- a/cdk-infra/lib/stacks/cache-updater-stack.ts +++ b/cdk-infra/lib/stacks/cache-updater-stack.ts @@ -1,15 +1,15 @@ -import { Stack } from 'aws-cdk-lib'; +import { Stack, StackProps } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import { CacheUpdaterWorkerConstruct } from '../constructs/cache-updater/cache-updater-worker-construct'; -import { IVpc } from 'aws-cdk-lib/aws-ec2'; +import { Vpc } from 'aws-cdk-lib/aws-ec2'; import { CacheUpdaterApiConstruct } from '../constructs/cache-updater/cache-updater-api-construct'; -interface CacheUpdaterStackProps { - vpc: IVpc; +interface CacheUpdaterStackProps extends StackProps { + vpc: Vpc; } export class CacheUpdaterStack extends Stack { - constructor(scope: Construct, id: string, { vpc }: CacheUpdaterStackProps) { - super(scope, id); + constructor(scope: Construct, id: string, { vpc, ...props }: CacheUpdaterStackProps) { + super(scope, id, props); const { clusterName, taskDefinition, containerName } = new CacheUpdaterWorkerConstruct( this, @@ -21,6 +21,7 @@ export class CacheUpdaterStack extends Stack { clusterName, taskDefinition, containerName, + vpc, }); } } diff --git a/src/cache-updater/Dockerfile.cacheUpdater b/src/cache-updater/Dockerfile.cacheUpdater index a22daed94..74907071d 100644 --- a/src/cache-updater/Dockerfile.cacheUpdater +++ b/src/cache-updater/Dockerfile.cacheUpdater @@ -30,12 +30,9 @@ RUN npm run build:esbuild:cacheUpdater FROM node:18-bullseye-slim WORKDIR /usr/app - ENV PATH="${PATH}:/opt/snooty" RUN apt-get -o Acquire::Check-Valid-Until=false update && apt-get -y install git - - COPY --from=python-builder /opt/ /opt/ COPY --from=builder /usr/app/dist/ .