Skip to content

Commit

Permalink
[DOP-4171]: Add necessary info to start task
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Jan 23, 2024
1 parent 7fa3cbc commit f595925
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
8 changes: 8 additions & 0 deletions api/controllers/v2/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion cdk-infra/bin/cdk-infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function main() {
env,
});

new CacheUpdaterStack(app, `${stackName}-cache`, { vpc });
new CacheUpdaterStack(app, `${stackName}-cache`, { vpc, env });
}

main();
4 changes: 2 additions & 2 deletions cdk-infra/lib/constructs/auto-builder-vpc-construct.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +11,7 @@ interface CacheUpdaterApiConstructProps {
clusterName: string;
taskDefinition: TaskDefinition;
containerName: string;
vpc: Vpc;
}

const HANDLERS_PATH = path.join(__dirname, '/../../../../api/controllers/v2');
Expand All @@ -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);

Expand All @@ -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)),
},
});

Expand Down
4 changes: 2 additions & 2 deletions cdk-infra/lib/stacks/auto-builder-vpc-stack.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
13 changes: 7 additions & 6 deletions cdk-infra/lib/stacks/cache-updater-stack.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,6 +21,7 @@ export class CacheUpdaterStack extends Stack {
clusterName,
taskDefinition,
containerName,
vpc,
});
}
}
3 changes: 0 additions & 3 deletions src/cache-updater/Dockerfile.cacheUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -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/ .

Expand Down

0 comments on commit f595925

Please sign in to comment.