import { Environment, Stack } from 'aws-cdk-lib'; import { InstanceType } from 'aws-cdk-lib/aws-ec2'; import { IRole } from 'aws-cdk-lib/aws-iam'; import { IBucket } from 'aws-cdk-lib/aws-s3'; import { IStringParameter } from 'aws-cdk-lib/aws-ssm'; import { Construct } from 'constructs'; /** * The GitLabRunnerProps require the VPC ID, a defined environment of account and region, optional * runner configuration and optionally the GitLab Runner Manager instance type. By default, a T3 Micro instance will be used. * For larger workloads and very active teams it is recommended to use T3 Small for the manager instead. */ export interface GitLabRunnerProps { readonly env: Environment; readonly runnersWorkerProps?: GitlabRunnerWorkerProps; readonly managerInstanceType?: InstanceType; readonly cache: IBucket; } /** * The GitlabRunnerWorkerProps interface provides a simplified GitLab Runner worker configuration * requiring a token as an SSM parameter, one of the valid gitlab URLs, instance of you choice, the desired max spot price, * whether to use spot instance or not and a default role. * It is recommended to use the RunnerRoles construct, and it's exposed default runner role. */ export interface GitlabRunnerWorkerProps { /** The SSM StringParameter with the registered runner token */ readonly token: IStringParameter; /** The GitLab instance URL, either https://gitlab.cicd.man or https://gitlab.collaborationlayer-traton.com */ readonly gitInstanceUrl: GitlabInstanceUrl; /** The instance type for the runner worker */ readonly instanceType: InstanceType; /** The desired max spot price */ readonly spotPrice: number; /** Whether to use spot instance or not, Requires ServiceLinked Role for EC2 Spot to be deployed in the account */ readonly requestSpotPrice: boolean; /** The default role for the runner worker when spawned */ readonly defaultWorkerRole: IRole; /** The maximum number of builds for an instance before it has to be decommissioned. Default 10 */ readonly maxBuilds?: number; /** The maximum number of instances to keep idle for new incoming jobs. Default 5 */ readonly maxIdleInstance?: number; /** The maximum idle time seconds for an instance. Default 900 seconds */ readonly maxIdleTime?: number; } export type GitlabInstanceUrl = 'https://gitlab.cicd.man' | 'https://gitlab.collaborationlayer-traton.com'; /** * The construct create the GitLabRunner Manager instance which will autoscale Runner instances based on the configuration. * By default, the construct will create a Runner with a manager T3 Micro instance which will be enabled to spawn T3 Large Runner * worker spot instance. The default runner Role has only the permissions to upload and download from the S3 runner cache. * * minimal configuration with runner spot instance: * ```ts * new SpotServiceLinkedRole(stack, 'SpotLinkedRole'); * const myBucket = new Bucket(stack, 'MyShareRunnerCache', { * enforceSSL: true, * publicReadAccess: false, * encryption: BucketEncryption.S3_MANAGED, * lifecycleRules: [ * { * enabled: true, * expiration: Duration.days(30), * }, * ], * }); * new GitlabRunner(stack, 'GitLabRunner', { * env: {account: '123456789012', region: 'eu-west-1'}, * cache: myBucket // use a S3 bucket without public access and a retention defined, use one cache bucket for all you runners * }); *``` * recommended: * ```ts * new SpotServiceLinkedRole(stack, 'SpotLinkedRole'); * const runnerRoles = new RunnerRoles(stack, 'RunnerRoles', {env: {account: '123456789012', region: 'eu-west-1'}}); * const myBucket = new Bucket(stack, 'MyShareRunnerCache', { * enforceSSL: true, * publicReadAccess: false, * encryption: BucketEncryption.S3_MANAGED, * lifecycleRules: [ * { * enabled: true, * expiration: Duration.days(30), * }, * ], * }); * new GitlabRunner(stack, 'GitLabRunner', { * env: {account: '123456789012', region: 'eu-west-1'}, * cache: myBucket // // use a S3 bucket without public access and a retention defined, use one cache bucket for all you runners * runnersWorkerProps: { * token: myTokenForTaggedRunner1, // with this runner we only want to run jobs that require more power * gitInstanceUrl: 'https://gitlab.cicd.man', // or the Traton GitLab * instanceType: InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.XLARGE), // exemplary larger runner * spotPrice: 0.2, // exemplary spot price * requestSpotPrice: true, * defaultWorkerRole: runnerRoles.runnerBaseRole, // use the base role * }, * }); * ``` */ export declare class GitlabRunner extends Construct { private autoscalingConfig; constructor(scope: Stack, id: string, props: GitLabRunnerProps); private createWorkerConfigurations; private getDefaultRunnerWorkerConfig; }