{"id":15470495,"url":"https://github.com/pepperize/cdk-autoscaling-gitlab-runner","last_synced_at":"2025-03-29T19:01:36.278Z","repository":{"id":36981743,"uuid":"417125268","full_name":"pepperize/cdk-autoscaling-gitlab-runner","owner":"pepperize","description":"Execute Gitlab jobs on auto-scaled EC2 instances using the Docker Machine executor.","archived":false,"fork":false,"pushed_at":"2025-03-27T02:21:39.000Z","size":7227,"stargazers_count":31,"open_issues_count":8,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T03:32:12.415Z","etag":null,"topics":["autoscaling","aws","cdk","dind","docker","docker-in-docker","docker-machine","ec2","executor","gitlab","gitlab-ci","runner","s3","shared-cache","spot-instances"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pepperize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-14T12:40:24.000Z","updated_at":"2025-03-27T02:16:25.000Z","dependencies_parsed_at":"2023-12-18T03:30:27.236Z","dependency_job_id":"df6d35dd-f201-422f-b9b7-bd8164c566da","html_url":"https://github.com/pepperize/cdk-autoscaling-gitlab-runner","commit_stats":{"total_commits":1270,"total_committers":10,"mean_commits":127.0,"dds":"0.46929133858267713","last_synced_commit":"c0bb4cf366b42207923a7fbd0086ff7514fdd880"},"previous_names":[],"tags_count":903,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperize%2Fcdk-autoscaling-gitlab-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperize%2Fcdk-autoscaling-gitlab-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperize%2Fcdk-autoscaling-gitlab-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepperize%2Fcdk-autoscaling-gitlab-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pepperize","download_url":"https://codeload.github.com/pepperize/cdk-autoscaling-gitlab-runner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246230504,"owners_count":20744347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoscaling","aws","cdk","dind","docker","docker-in-docker","docker-machine","ec2","executor","gitlab","gitlab-ci","runner","s3","shared-cache","spot-instances"],"created_at":"2024-10-02T02:05:06.561Z","updated_at":"2025-03-29T19:01:36.233Z","avatar_url":"https://github.com/pepperize.png","language":"TypeScript","readme":"[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n[![GitHub](https://img.shields.io/github/license/pepperize/cdk-autoscaling-gitlab-runner?style=flat-square)](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/LICENSE)\n[![npm (scoped)](https://img.shields.io/npm/v/@pepperize/cdk-autoscaling-gitlab-runner?style=flat-square)](https://www.npmjs.com/package/@pepperize/cdk-autoscaling-gitlab-runner)\n[![PyPI](https://img.shields.io/pypi/v/pepperize.cdk-autoscaling-gitlab-runner?style=flat-square)](https://pypi.org/project/pepperize.cdk-autoscaling-gitlab-runner/)\n[![Nuget](https://img.shields.io/nuget/v/Pepperize.CDK.AutoscalingGitlabRunner?style=flat-square)](https://www.nuget.org/packages/Pepperize.CDK.AutoscalingGitlabRunner/)\n[![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/com.pepperize/cdk-autoscaling-gitlab-runner?server=https%3A%2F%2Fs01.oss.sonatype.org%2F\u0026style=flat-square)](https://s01.oss.sonatype.org/content/repositories/releases/com/pepperize/cdk-autoscaling-gitlab-runner/)\n[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/pepperize/cdk-autoscaling-gitlab-runner/release.yml?bracnh=main\u0026label=release\u0026style=flat-square)](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/actions/workflows/release.yml)\n[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/pepperize/cdk-autoscaling-gitlab-runner?sort=semver\u0026style=flat-square)](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/releases)\n\n# AWS CDK GitLab Runner autoscaling on EC2\n\nThis project provides a CDK construct to [execute jobs on auto-scaled EC2 instances](https://docs.gitlab.com/runner/configuration/runner_autoscale_aws/index.html) using the [Docker Machine](https://docs.gitlab.com/runner/executors/docker_machine.html) executor.\n\n\u003e Running out of [Runner minutes](https://about.gitlab.com/pricing/),\n\u003e using [Docker-in-Docker (dind)](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html),\n\u003e speed up jobs with [shared S3 Cache](https://docs.gitlab.com/runner/configuration/autoscale.html#distributed-runners-caching),\n\u003e cross compiling/building environment [multiarch](https://hub.docker.com/r/multiarch/qemu-user-static/),\n\u003e cost effective [autoscaling on EC2](https://docs.gitlab.com/runner/configuration/runner_autoscale_aws/#the-runnersmachine-section),\n\u003e deploy directly from AWS accounts (without [AWS Access Key](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)),\n\u003e running on [Spot instances](https://aws.amazon.com/ec2/spot/),\n\u003e having a bigger [build log size](https://docs.gitlab.com/runner/configuration/advanced-configuration.html)\n\n[![View on Construct Hub](https://constructs.dev/badge?package=%40pepperize%2Fcdk-autoscaling-gitlab-runner)](https://constructs.dev/packages/@pepperize/cdk-autoscaling-gitlab-runner)\n\n## Install\n\n### TypeScript\n\n```shell\nnpm install @pepperize/cdk-autoscaling-gitlab-runner\n```\n\nor\n\n```shell\nyarn add @pepperize/cdk-autoscaling-gitlab-runner\n```\n\n### Python\n\n```shell\npip install pepperize.cdk-autoscaling-gitlab-runner\n```\n\n### C# / .Net\n\n```\ndotnet add package Pepperize.CDK.AutoscalingGitlabRunner\n```\n\n### Java\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.pepperize\u003c/groupId\u003e\n  \u003cartifactId\u003ecdk-autoscaling-gitlab-runner\u003c/artifactId\u003e\n  \u003cversion\u003e${cdkAutoscalingGitlabRunner.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Quickstart\n\n1. **Create a new AWS CDK App** in TypeScript with [projen](https://github.com/projen/projen)\n\n   ```shell\n   mkdir gitlab-runner\n   cd gitlab-runner\n   git init\n   npx projen new awscdk-app-ts\n   ```\n\n2. **Configure your project in `.projenrc.js`**\n\n   - Add `deps: [\"@pepperize/cdk-autoscaling-gitlab-runner\"],`\n\n3. **Update project files and install dependencies**\n\n   ```shell\n   npx projen\n   ```\n\n4. **Register a new runner**\n\n   [Registering runners](https://docs.gitlab.com/runner/register/):\n\n   - For a [shared runner](https://docs.gitlab.com/ee/ci/runners/#shared-runners), go to the GitLab Admin Area and click **Overview \u003e Runners**\n   - For a [group runner](https://docs.gitlab.com/ee/ci/runners/index.html#group-runners), go to **Settings \u003e CI/CD** and expand the **Runners** section\n   - For a [project runner](https://docs.gitlab.com/ee/ci/runners/index.html#specific-runners), go to **Settings \u003e CI/CD** and expand the **Runners** section\n\n   _Optionally enable: **Run untagged jobs** [x]\n   Indicates whether this runner can pick jobs without tags_\n\n   See also _[Registration token vs. Authentication token](https://docs.gitlab.com/ee/api/runners.html#registration-and-authentication-tokens)_\n\n5. **Retrieve a new runner authentication token**\n\n   [Register a new runner](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner)\n\n   ```shell\n   curl --request POST \"https://gitlab.com/api/v4/runners\" --form \"token=\u003cyour register token\u003e\" --form \"description=gitlab-runner\" --form \"tag_list=pepperize,docker,production\"\n   ```\n\n6. **Store runner authentication token in SSM ParameterStore**\n\n   [Create a String parameter](https://docs.aws.amazon.com/systems-manager/latest/userguide/param-create-cli.html#param-create-cli-string)\n\n   ```shell\n   aws ssm put-parameter --name \"/gitlab-runner/token\" --value \"\u003cyour runner authentication token\u003e\" --type \"String\"\n   ```\n\n7. **Add to your `main.ts`**\n\n   ```typescript\n   import { Vpc } from \"@aws-cdk/aws-ec2\";\n   import { App, Stack } from \"@aws-cdk/core\";\n   import { GitlabRunnerAutoscaling } from \"@pepperize/cdk-autoscaling-gitlab-runner\";\n\n   const app = new App();\n   const stack = new Stack(app, \"GitLabRunnerStack\");\n   const vpc = Vpc.fromLookup(app, \"ExistingVpc\", {\n     vpcId: \"\u003cyour vpc id\u003e\",\n   });\n   const token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n     parameterName: \"/gitlab-runner/token\",\n   });\n   new GitlabRunnerAutoscaling(stack, \"GitlabRunner\", {\n     network: {\n       vpc: vpc,\n     },\n     runners: [\n       {\n         token: token,\n         configuration: {\n           // optionally configure your runner\n         },\n       },\n     ],\n   });\n   ```\n\n8. **Create service linked role**\n\n   _(If requesting spot instances, default: true)_\n\n   ```sh\n   aws iam create-service-linked-role --aws-service-name spot.amazonaws.com\n   ```\n\n9. **Configure the AWS CLI**\n\n   - [AWSume](https://awsu.me/)\n   - [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)\n   - [AWS Single Sign-On](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html)\n\n10. **Deploy the GitLab Runner**\n\n    ```shell\n    npm run deploy\n    ```\n\n## Example\n\n### Custom cache bucket\n\nBy default, an AWS S3 Bucket is created as GitLab Runner's distributed cache.\nIt's encrypted and public access is blocked.\nA custom S3 Bucket can be configured:\n\n```typescript\nconst cache = new Bucket(this, \"Cache\", {\n  // Your custom bucket\n});\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n    },\n  ],\n  cache: { bucket: cache },\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/cache.ts),\n[GitlabRunnerAutoscalingCacheProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#gitlabrunnerautoscalingcacheprops-)\n\n### Custom EC2 key pair\n\nBy default, the [amazonec2](https://gitlab.com/gitlab-org/ci-cd/docker-machine/-/blob/main/drivers/amazonec2/amazonec2.go) driver will create an EC2 key pair for each runner. To use custom ssh credentials provide a SecretsManager Secret with the private and public key file:\n\n1. [Create a key pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html), download the private key file and remember the created key pair name\n2. Generate the public key file\n   ```\n   ssh-keygen -f \u003cthe downloaded private key file\u003e -y\n   ```\n3. Create an AWS SecretsManager Secret from the key pair\n   ```shell\n   aws secretsmanager create-secret --name \u003cthe secret name\u003e --secret-string \"{\\\"\u003cthe key pair name\u003e\\\":\\\"\u003cthe private key\u003e\\\",\\\"\u003cthe key pair name\u003e.pub\\\":\\\"\u003cthe public key\u003e\\\"}\"\n   ```\n4. Configure the job runner\n\n   ```typescript\n   const keyPair = Secret.fromSecretNameV2(stack, \"Secret\", \"CustomEC2KeyPair\");\n\n   new GitlabRunnerAutoscaling(this, \"Runner\", {\n     runners: [\n       {\n         keyPair: keyPair,\n         configuration: {\n           machine: {\n             machineOptions: {\n               keypairName: \"\u003cthe key pair name\u003e\",\n             },\n           },\n         },\n       },\n     ],\n     cache: { bucket: cache },\n   });\n   ```\n\n### Configure Docker Machine\n\nBy default, docker machine is configured to run privileged with `CAP_SYS_ADMIN` to support [Docker-in-Docker using the OverlayFS driver](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-the-overlayfs-driver)\nand cross compiling/building with [multiarch](https://hub.docker.com/r/multiarch/qemu-user-static/).\n\nSee [runners.docker section](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersdocker-section)\nin [Advanced configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html)\n\n```typescript\nimport { GitlabRunnerAutoscaling } from \"@pepperize/cdk-autoscaling-gitlab-runner\";\nimport { StringParameter } from \"aws-cdk-lib/aws-ssm\";\n\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        environment: [], // Reset the OverlayFS driver for every project\n        docker: {\n          capAdd: [], // Remove the CAP_SYS_ADMIN\n          privileged: false, // Run unprivileged\n        },\n        machine: {\n          idleCount: 2, // Number of idle machine\n          idleTime: 3000, // Waiting time in idle state\n          maxBuilds: 1, // Max builds before instance is removed\n        },\n      },\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/docker-machine.ts),\n[DockerConfiguration](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#dockerconfiguration-)\n\n### Bigger instance type\n\nBy default, t3.nano is used for the manager/coordinator and t3.micro instances will be spawned.\nFor bigger projects, for example with [webpack](https://webpack.js.org/), this won't be enough memory.\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  manager: {\n    instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.SMALL),\n  },\n  runners: [\n    {\n      instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),\n      token: token,\n      configuration: {\n        // optionally configure your runner\n      },\n    },\n  ],\n});\n```\n\n\u003e You may have to disable or configure [Spot instances](#spot-instances)\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/instance-type.ts),\n[GitlabRunnerAutoscalingManagerProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#gitlabrunnerautoscalingmanagerprops-),\n[GitlabRunnerAutoscalingJobRunnerProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#gitlabrunnerautoscalingjobrunnerprops-)\n\n### Different machine image\n\nBy default, the latest [Amazon 2 Linux](https://aws.amazon.com/amazon-linux-2/) will be used for the manager/coordinator.\nThe manager/coordinator instance's cloud init scripts requires [yum](https://access.redhat.com/solutions/9934) is installed, any RHEL flavor should work.\nThe requested runner instances by default using Ubuntu 20.04, any OS implemented by the [Docker Machine provisioner](https://gitlab.com/gitlab-org/ci-cd/docker-machine/-/tree/main/libmachine/provision) should work.\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  manager: {\n    machineImage: MachineImage.genericLinux(managerAmiMap),\n  },\n  runners: [\n    {\n      machineImage: MachineImage.genericLinux(runnerAmiMap),\n      token: token,\n      configuration: {\n        // optionally configure your runner\n      },\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/machine-image.ts),\n[GitlabRunnerAutoscalingManagerProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#gitlabrunnerautoscalingmanagerprops-),\n[GitlabRunnerAutoscalingJobRunnerProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#gitlabrunnerautoscalingjobrunnerprops-)\n\n### Multiple runners configuration\n\nEach runner defines one `[[runners]]` section in the [configuration file](https://docs.gitlab.com/runner/configuration/).\nUse [Specific runners](https://docs.gitlab.com/ee/ci/runners/runners_scope.html#specific-runners) when you want to use runners for specific projects.\n\n```typescript\nconst privilegedRole = new Role(this, \"PrivilegedRunnersRole\", {\n  // role 1\n});\n\nconst restrictedRole = new Role(this, \"RestrictedRunnersRole\", {\n  // role 2\n});\n\nconst token1 = StringParameter.fromStringParameterAttributes(stack, \"Token1\", {\n  parameterName: \"/gitlab-runner/token1\",\n});\n\nconst token2 = StringParameter.fromStringParameterAttributes(stack, \"Token2\", {\n  parameterName: \"/gitlab-runner/token2\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token1,\n      configuration: {\n        name: \"privileged-runner\",\n      },\n      role: privilegedRole,\n    },\n    {\n      token: token2,\n      configuration: {\n        name: \"restricted-runner\",\n        docker: {\n          privileged: false, // Run unprivileged\n        },\n      },\n      role: restrictedRole,\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/machine-image.ts),\n[GitlabRunnerAutoscalingProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#@pepperize/cdk-autoscaling-gitlab-runner.GitlabRunnerAutoscalingProps)\n\n### Spot instances\n\nBy default, EC2 Spot Instances are requested.\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        machine: {\n          machineOptions: {\n            requestSpotInstance: false,\n            spotPrice: 0.5,\n          },\n        },\n      },\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/on-demand-instances.ts),\n[EC2 spot price](https://aws.amazon.com/de/ec2/spot/pricing/),\n[MachineConfiguration](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#machineconfiguration-),\n[MachineOptions](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#machineoptions-),\n[Advanced configuration - runners.machine.autoscaling](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersmachineautoscaling-sections)\n\n### Cross-Compile with Multiarch\n\nTo build binaries of different architectures can also use [Multiarch](https://wiki.debian.org/Multiarch)\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        docker: {\n          privileged: true,\n        },\n      },\n    },\n  ],\n});\n```\n\nConfigure your [.gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/) file\n\n```yaml\nbuild:\n  image: multiarch/debian-debootstrap:armhf-buster\n  services:\n    - docker:stable-dind\n    - name: multiarch/qemu-user-static:register\n      command:\n        - \"--reset\"\n  script:\n    - make build\n```\n\nSee [multiarch/qemu-user-static](https://hub.docker.com/r/multiarch/qemu-user-static)\n\n### Running on AWS Graviton\n\nTo run your jobs on [AWS Graviton](https://aws.amazon.com/ec2/graviton/) you have to provide an AMI for arm64 architecture.\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        instanceType: InstanceType.of(InstanceClass.M6G, InstanceSize.LARGE),\n        machineImage: MachineImage.genericLinux({\n          [this.region]: new LookupMachineImage({\n            name: \"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-*-server-*\",\n            owners: [\"099720109477\"],\n            filters: {\n              architecture: [InstanceArchitecture.ARM_64],\n              \"image-type\": [\"machine\"],\n              state: [\"available\"],\n              \"root-device-type\": [\"ebs\"],\n              \"virtualization-type\": [\"hvm\"],\n            },\n          }).getImage(this).imageId,\n        }),\n      },\n    },\n  ],\n});\n```\n\nSee [Ubuntu Amazon EC2 AMI Locator](https://cloud-images.ubuntu.com/locator/ec2/)\n\n### Custom runner's role\n\nTo deploy from within your GitLab Runner Instances, you may pass a Role with the IAM Policies attached.\n\n```typescript\nconst role = new Role(this, \"RunnersRole\", {\n  assumedBy: new ServicePrincipal(\"ec2.amazonaws.com\", {}),\n  inlinePolicies: {},\n});\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      role: role,\n      token: token,\n      configuration: {\n        // optionally configure your runner\n      },\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/runner-role.ts),\n[GitlabRunnerAutoscalingProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#@pepperize/cdk-autoscaling-gitlab-runner.GitlabRunnerAutoscalingProps)\n\n### Vpc\n\nIf no existing Vpc is passed, a cheap [VPC](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Vpc.html) with a NatInstance (t3.nano) and a single AZ will be created.\n\n```typescript\nconst natInstanceProvider = aws_ec2.NatProvider.instance({\n  instanceType: aws_ec2.InstanceType.of(InstanceClass.T3, InstanceSize.NANO), // using a cheaper gateway (not scalable)\n});\nconst vpc = new Vpc(this, \"Vpc\", {\n  // Your custom vpc, i.e.:\n  natGatewayProvider: natInstanceProvider,\n  maxAzs: 1,\n});\n\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        // optionally configure your runner\n      },\n    },\n  ],\n  network: { vpc: vpc },\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/vpc.ts),\n[GitlabRunnerAutoscalingProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#@pepperize/cdk-autoscaling-gitlab-runner.GitlabRunnerAutoscalingProps)\n\n### Zero config\n\nDeploys the [Autoscaling GitLab Runner on AWS EC2](https://docs.gitlab.com/runner/configuration/runner_autoscale_aws/) with the default settings mentioned above.\n\nHappy with the presets?\n\n```typescript\nconst token = StringParameter.fromStringParameterAttributes(stack, \"Token\", {\n  parameterName: \"/gitlab-runner/token\",\n});\n\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      token: token,\n      configuration: {\n        // optionally configure your runner\n      },\n    },\n  ],\n});\n```\n\nSee [example](https://github.com/pepperize/cdk-autoscaling-gitlab-runner-example/blob/main/src/zero-config.ts),\n[GitlabRunnerAutoscalingProps](https://github.com/pepperize/cdk-autoscaling-gitlab-runner/blob/main/API.md#@pepperize/cdk-autoscaling-gitlab-runner.GitlabRunnerAutoscalingProps)\n\n### ECR Credentials Helper\n\nBy default, the GitLab [amzonec2 driver](https://gitlab.com/gitlab-org/ci-cd/docker-machine/-/blob/main/drivers/amazonec2/amazonec2.go) will be configured to install the\n[amazon-ecr-credential-helper](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html#registry-auth-credential-helper)\non the runner's instances.\n\nTo configure, override the default job runners environment:\n\n```typescript\nnew GitlabRunnerAutoscaling(this, \"Runner\", {\n  runners: [\n    {\n      // ...\n      environment: [\n        \"DOCKER_DRIVER=overlay2\",\n        \"DOCKER_TLS_CERTDIR=/certs\",\n        'DOCKER_AUTH_CONFIG={\"credHelpers\": { \"public.ecr.aws\": \"ecr-login\", \"\u003caws_account_id\u003e.dkr.ecr.\u003cregion\u003e.amazonaws.com\": \"ecr-login\" } }',\n      ],\n    },\n  ],\n});\n```\n\n## Projen\n\nThis project uses [projen](https://github.com/projen/projen) to maintain project configuration through code. Thus, the synthesized files with projen should never be manually edited (in fact, projen enforces that).\n\nTo modify the project setup, you should interact with rich strongly-typed\nclass [AwsCdkTypeScriptApp](https://github.com/projen/projen/blob/master/API.md#projen-awscdktypescriptapp) and\nexecute `npx projen` to update project configuration files.\n\n\u003e In simple words, developers can only modify `.projenrc.js` file for configuration/maintenance and files under `/src` directory for development.\n\nSee also [Create and Publish CDK Constructs Using projen and jsii](https://github.com/seeebiii/projen-test).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepperize%2Fcdk-autoscaling-gitlab-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpepperize%2Fcdk-autoscaling-gitlab-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepperize%2Fcdk-autoscaling-gitlab-runner/lists"}