Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental build PoC using EFS #961

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions cdk-infra/lib/constructs/worker/worker-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
FargateTaskDefinition,
LogDrivers,
} from 'aws-cdk-lib/aws-ecs';
import { Effect, IRole, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { AnyPrincipal, Effect, IRole, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { LogGroup } from 'aws-cdk-lib/aws-logs';
import { IQueue } from 'aws-cdk-lib/aws-sqs';
import { Construct } from 'constructs';
import path from 'path';
import { getEnv, isEnhanced } from '../../../utils/env';
import { FileSystem } from 'aws-cdk-lib/aws-efs';

interface WorkerConstructProps {
dockerEnvironment: Record<string, string>;
Expand Down Expand Up @@ -72,12 +73,43 @@ export class WorkerConstruct extends Construct {
},
};

const fileSystem = new FileSystem(this, 'snootyCacheFileSystem', {
vpc,
});

fileSystem.addAccessPoint('cache/', {
path: '/cache',
});

fileSystem.addToResourcePolicy(
new PolicyStatement({
actions: ['elasticfilesystem:ClientMount'],
principals: [new AnyPrincipal()],
conditions: {
Bool: {
'elasticfilesystem:AccessedViaMountTarget': 'true',
},
},
})
);

fileSystem.grantReadWrite(taskRole);

const VOLUME_NAME = 'efsVolume';
const taskDefLogGroup = new LogGroup(this, 'workerLogGroup');
const taskDefinition = new FargateTaskDefinition(this, 'workerTaskDefinition', {
cpu: 4096,
memoryLimitMiB: 8192,
taskRole,
executionRole,
volumes: [
{
name: VOLUME_NAME,
efsVolumeConfiguration: {
fileSystemId: fileSystem.fileSystemId,
},
},
],
});

const updateTaskProtectionPolicy = new PolicyStatement({
Expand All @@ -93,14 +125,20 @@ export class WorkerConstruct extends Construct {

taskRole.addToPolicy(updateTaskProtectionPolicy);

taskDefinition.addContainer('workerImage', {
image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), containerProps),
environment: dockerEnvironment,
logging: LogDrivers.awsLogs({
streamPrefix: 'autobuilderworker',
logGroup: taskDefLogGroup,
}),
});
taskDefinition
.addContainer('workerImage', {
image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), containerProps),
environment: dockerEnvironment,
logging: LogDrivers.awsLogs({
streamPrefix: 'autobuilderworker',
logGroup: taskDefLogGroup,
}),
})
.addMountPoints({
sourceVolume: VOLUME_NAME,
containerPath: '/cache',
readOnly: false,
});

const env = getEnv();

Expand Down
73 changes: 32 additions & 41 deletions cdk-infra/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cdk-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@swc/helpers": "^0.5.1",
"@types/jest": "^29.4.0",
"@types/node": "18.14.6",
"aws-cdk": "2.73.0",
"aws-cdk": "2.121.1",
"esbuild": "^0.18.3",
"jest": "^29.5.0",
"regenerator-runtime": "^0.13.11",
Expand All @@ -31,7 +31,7 @@
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.342.0",
"aws-cdk-lib": "2.73.0",
"aws-cdk-lib": "2.121.1",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
Expand Down
Loading