in packages/aws-rfdk/lib/deadline/lib/repository.ts [810:873]
public configureClientECS(props: ECSDirectConnectProps): IContainerDirectRepositoryConnection {
const hostMountPoint = props.containerInstances.filesystemMountPoint ?? '/mnt/repo';
const majorVersion = Token.isUnresolved(this.version.majorVersion) ?
Token.asString(this.version.majorVersion) : this.version.majorVersion.toString();
const containerMountPoint = props.containers.filesystemMountPoint ?? `/opt/Thinkbox/DeadlineRepository${majorVersion}`;
// Note: pathToFileURL messes up CDK Tokens like the one in majorVersion
const containerMountPointURL = props.containers.filesystemMountPoint ?
pathToFileURL(props.containers.filesystemMountPoint).toString() :
`file:///opt/Thinkbox/DeadlineRepository${majorVersion}`;
// Set up a direct connection on the host machine. This:
// - grants IAM permissions to the role associated with the instance profile access to
// - the file-system
// - the DB secret containing the credentials
// - adds a security group ingress rule to the DB cluster and file-system
// - adds userdata commands to mount the repository file-system on the host
props.containerInstances.hosts.forEach(host => {
this.setupDirectConnect(host, hostMountPoint);
});
// Build up a mapping of environment variables that are used to configure the container's direct connection to the
// repository
const containerEnvironment: { [name: string]: string } = {
REPO_URI: containerMountPointURL,
};
// The role associated with the task definition needs access to connect to the database
this.databaseConnection.grantRead(props.containers.taskDefinition.taskRole);
// Add any environment variables specified by the connection
Object.entries(this.databaseConnection.containerEnvironment).forEach((entry: [string, string]) => {
const [envVarName, envVarValue] = entry;
containerEnvironment[envVarName] = envVarValue;
});
// Add an explicit dependency on the Repository. This ensures that deployments of the Repository construct precede
// deployments of the client and the repository is fully setup.
props.containers.taskDefinition.node.addDependency(this.installerGroup);
// Configure a named volume in the task-definition that points to the container host's mount-point of the repository
// file-system
props.containers.taskDefinition.addVolume({
name: Repository.ECS_VOLUME_NAME,
host: {
sourcePath: path.posix.normalize(path.posix.join(hostMountPoint, this.rootPrefix)),
},
});
// Return the container connection. This data structure contains all the pieces needed to create containers
// that can directly connect to the repository.
return {
containerEnvironment,
readOnlyMountPoint: {
containerPath: containerMountPoint,
readOnly: true,
sourceVolume: Repository.ECS_VOLUME_NAME,
},
readWriteMountPoint: {
containerPath: containerMountPoint,
readOnly: false,
sourceVolume: Repository.ECS_VOLUME_NAME,
},
};
}