[](https://badge.fury.io/js/cdk-gitlab-runner)
[](https://badge.fury.io/py/cdk-gitlab-runner)








# Welcome to `cdk-gitlab-runner`
This repository template helps you create gitlab runner on your aws account via AWS CDK one line.
## Note
### Default will help you generate below services:
* VPC
* Public Subnet (2)
* EC2 (1 T3.micro)
## Before start you need gitlab runner token in your `gitlab project` or `gitlab group`
### In Group
Group > Settings > CI/CD

### In Group
Project > Settings > CI/CD > Runners

## Usage
Replace your gitlab runner token in `$GITLABTOKEN`
### Instance Type
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner
# If want change instance type to t3.large .
GitlabContainerRunner(self, "runner-instance", gitlabtoken="$GITLABTOKEN", ec2type="t3.large")
# OR
# Just create a gitlab runner , by default instance type is t3.micro .
from cdk_gitlab_runner import GitlabContainerRunner
GitlabContainerRunner(self, "runner-instance", gitlabtoken="$GITLABTOKEN")
```
### Gitlab Server Customize Url .
If you want change what you want tag name .
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# If you want change what your self Gitlab Server Url .
from cdk_gitlab_runner import GitlabContainerRunner
GitlabContainerRunner(self, "runner-instance-change-tag",
gitlabtoken="$GITLABTOKEN",
gitlaburl="https://gitlab.my.com/"
)
```
### Tags
If you want change what you want tag name .
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# If you want change what you want tag name .
from cdk_gitlab_runner import GitlabContainerRunner
GitlabContainerRunner(self, "runner-instance-change-tag",
gitlabtoken="$GITLABTOKEN",
tags=["aa", "bb", "cc"]
)
```
### IAM Policy
If you want add runner other IAM Policy like s3-readonly-access.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# If you want add runner other IAM Policy like s3-readonly-access.
from cdk_gitlab_runner import GitlabContainerRunner
from aws_cdk.aws_iam import ManagedPolicy
runner = GitlabContainerRunner(self, "runner-instance-add-policy",
gitlabtoken="$GITLABTOKEN",
tags=["aa", "bb", "cc"]
)
runner.runner_role.add_managed_policy(
ManagedPolicy.from_aws_managed_policy_name("AmazonS3ReadOnlyAccess"))
```
### Security Group
If you want add runner other SG Ingress .
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# If you want add runner other SG Ingress .
from cdk_gitlab_runner import GitlabContainerRunner
from aws_cdk.aws_ec2 import Port, Peer
runner = GitlabContainerRunner(self, "runner-add-SG-ingress",
gitlabtoken="GITLABTOKEN",
tags=["aa", "bb", "cc"]
)
# you can add ingress in your runner SG .
runner.default_runner_sG.connections.allow_from(
Peer.ipv4("0.0.0.0/0"),
Port.tcp(80))
```
### Use self VPC
> 2020/06/27 , you can use your self exist VPC or new VPC , but please check your `vpc public Subnet` Auto-assign public IPv4 address must be Yes ,or `vpc private Subnet` route table associated `nat gateway` .
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner
from aws_cdk.aws_ec2 import Port, Peer, Vpc, SubnetType
from aws_cdk.aws_iam import ManagedPolicy
newvpc = Vpc(stack, "VPC",
cidr="10.1.0.0/16",
max_azs=2,
subnet_configuration=[SubnetConfiguration(
cidr_mask=26,
name="RunnerVPC",
subnet_type=SubnetType.PUBLIC
)
],
nat_gateways=0
)
runner = GitlabContainerRunner(self, "testing",
gitlabtoken="$GITLABTOKEN",
ec2type="t3.small",
selfvpc=newvpc
)
```
### Use your self exist role
> 2020/06/27 , you can use your self exist role assign to runner
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner
from aws_cdk.aws_ec2 import Port, Peer
from aws_cdk.aws_iam import ManagedPolicy, Role, ServicePrincipal
role = Role(self, "runner-role",
assumed_by=ServicePrincipal("ec2.amazonaws.com"),
description="For Gitlab EC2 Runner Test Role",
role_name="TestRole"
)
runner = GitlabContainerRunner(stack, "testing",
gitlabtoken="$GITLAB_TOKEN",
ec2iamrole=role
)
runner.runner_role.add_managed_policy(
ManagedPolicy.from_aws_managed_policy_name("AmazonS3ReadOnlyAccess"))
```
### Custom Gitlab Runner EBS szie
> 2020/08/22 , you can change you want ebs size.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner
GitlabContainerRunner(stack, "testing",
gitlabtoken="$GITLAB_TOKEN",
ebs_size=50
)
```
### Control the number of runners with AutoScalingGroup
> 2020/11/25 , you can set the number of runners.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabRunnerAutoscaling
GitlabRunnerAutoscaling(stack, "testing",
gitlab_token="$GITLAB_TOKEN",
min_capacity=2,
max_capacity=2
)
```
### Support Spotfleet Gitlab Runner
> 2020/08/27 , you can use spotfleet instance be your gitlab runner,
> after create spotfleet instance will auto output instance id .thank [@pahud](https://github.com/pahud/cdk-spot-one) again ~~~
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner, BlockDuration
runner = GitlabContainerRunner(stack, "testing",
gitlabtoken="GITLAB_TOKEN",
ec2type="t3.large",
block_duration=BlockDuration.ONE_HOUR,
spot_fleet=True
)
# configure the expiration after 1 hours
runner.expire_after(Duration.hours(1))
```
> 2020/11/19, you setting job runtime bind host volumes.
> see more https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersdocker-section
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner, BlockDuration
runner = GitlabContainerRunner(stack, "testing",
gitlabtoken="GITLAB_TOKEN",
ec2type="t3.large",
docker_volumes=[{
"host_path": "/tmp/cahce",
"container_path": "/tmp/cahce"
}
]
)
```
> 2020/11/19, support runner auto unregister runner when cdk app destroy.
# Note
 vs 
> About change instance type
This is before  ( included  )
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from aws_cdk.aws_ec2 import InstanceType, InstanceClass, InstanceSize
from cdk_gitlab_runner import GitlabContainerRunner
# If want change instance type to t3.large .
GitlabContainerRunner(self, "runner-instance",
gitlabtoken="$GITLABTOKEN",
ec2type=InstanceType.of(InstanceClass.T3, InstanceSize.LARGE)
)
```
This is 
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_gitlab_runner import GitlabContainerRunner
# If want change instance type to t3.large .
GitlabContainerRunner(self, "runner-instance",
gitlabtoken="$GITLABTOKEN",
ec2type="t3.large"
)
```
## Wait about 6 mins , If success you will see your runner in that page .

#### you can use tag `gitlab` , `runner` , `awscdk` ,
## Example *`gitlab-ci.yaml`*
[gitlab docs see more ...](https://docs.gitlab.com/ee/ci/yaml/README.html)
```yaml
dockerjob:
image: docker:18.09-dind
variables:
tags:
- runner
- awscdk
- gitlab
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- docker info
script:
- docker info;
- echo 'test 123';
- echo 'hello world 1228'
```
### If your want to debug you can go to aws console
# `In your runner region !!!`
## AWS Systems Manager > Session Manager > Start a session

#### click your `runner` and click `start session`
#### in the brower console in put `bash`
```bash
# become to root
sudo -i
# list runner container .
root# docker ps -a
# modify gitlab-runner/config.toml
root# cd /home/ec2-user/.gitlab-runner/ && ls
config.toml
```
## :clap: Supporters
[](https://github.com/guan840912/cdk-gitlab-runner/stargazers)
Raw data
{
"_id": null,
"home_page": "https://github.com/guan840912/cdk-gitlab-runner.git",
"name": "cdk-gitlab-runner",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Neil Kuan<guan840912@gmail.com>",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/d8/c2/ec66564f249df893212d25bb96f8bc980f4b3511de8611fac51d6e3fc876/cdk-gitlab-runner-1.77.11.tar.gz",
"platform": "",
"description": "[](https://badge.fury.io/js/cdk-gitlab-runner)\n[](https://badge.fury.io/py/cdk-gitlab-runner)\n\n\n\n\n\n\n\n\n\n\n\n# Welcome to `cdk-gitlab-runner`\n\nThis repository template helps you create gitlab runner on your aws account via AWS CDK one line.\n\n## Note\n\n### Default will help you generate below services:\n\n* VPC\n\n * Public Subnet (2)\n* EC2 (1 T3.micro)\n\n## Before start you need gitlab runner token in your `gitlab project` or `gitlab group`\n\n### In Group\n\nGroup > Settings > CI/CD\n\n\n### In Group\n\nProject > Settings > CI/CD > Runners\n\n\n## Usage\n\nReplace your gitlab runner token in `$GITLABTOKEN`\n\n### Instance Type\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\n# If want change instance type to t3.large .\nGitlabContainerRunner(self, \"runner-instance\", gitlabtoken=\"$GITLABTOKEN\", ec2type=\"t3.large\")\n# OR\n# Just create a gitlab runner , by default instance type is t3.micro .\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\nGitlabContainerRunner(self, \"runner-instance\", gitlabtoken=\"$GITLABTOKEN\")\n```\n\n### Gitlab Server Customize Url .\n\nIf you want change what you want tag name .\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\n# If you want change what your self Gitlab Server Url .\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\nGitlabContainerRunner(self, \"runner-instance-change-tag\",\n gitlabtoken=\"$GITLABTOKEN\",\n gitlaburl=\"https://gitlab.my.com/\"\n)\n```\n\n### Tags\n\nIf you want change what you want tag name .\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\n# If you want change what you want tag name .\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\nGitlabContainerRunner(self, \"runner-instance-change-tag\",\n gitlabtoken=\"$GITLABTOKEN\",\n tags=[\"aa\", \"bb\", \"cc\"]\n)\n```\n\n### IAM Policy\n\nIf you want add runner other IAM Policy like s3-readonly-access.\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\n# If you want add runner other IAM Policy like s3-readonly-access.\nfrom cdk_gitlab_runner import GitlabContainerRunner\nfrom aws_cdk.aws_iam import ManagedPolicy\n\nrunner = GitlabContainerRunner(self, \"runner-instance-add-policy\",\n gitlabtoken=\"$GITLABTOKEN\",\n tags=[\"aa\", \"bb\", \"cc\"]\n)\nrunner.runner_role.add_managed_policy(\n ManagedPolicy.from_aws_managed_policy_name(\"AmazonS3ReadOnlyAccess\"))\n```\n\n### Security Group\n\nIf you want add runner other SG Ingress .\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\n# If you want add runner other SG Ingress .\nfrom cdk_gitlab_runner import GitlabContainerRunner\nfrom aws_cdk.aws_ec2 import Port, Peer\n\nrunner = GitlabContainerRunner(self, \"runner-add-SG-ingress\",\n gitlabtoken=\"GITLABTOKEN\",\n tags=[\"aa\", \"bb\", \"cc\"]\n)\n\n# you can add ingress in your runner SG .\nrunner.default_runner_sG.connections.allow_from(\n Peer.ipv4(\"0.0.0.0/0\"),\n Port.tcp(80))\n```\n\n### Use self VPC\n\n> 2020/06/27 , you can use your self exist VPC or new VPC , but please check your `vpc public Subnet` Auto-assign public IPv4 address must be Yes ,or `vpc private Subnet` route table associated `nat gateway` .\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner\nfrom aws_cdk.aws_ec2 import Port, Peer, Vpc, SubnetType\nfrom aws_cdk.aws_iam import ManagedPolicy\n\nnewvpc = Vpc(stack, \"VPC\",\n cidr=\"10.1.0.0/16\",\n max_azs=2,\n subnet_configuration=[SubnetConfiguration(\n cidr_mask=26,\n name=\"RunnerVPC\",\n subnet_type=SubnetType.PUBLIC\n )\n ],\n nat_gateways=0\n)\n\nrunner = GitlabContainerRunner(self, \"testing\",\n gitlabtoken=\"$GITLABTOKEN\",\n ec2type=\"t3.small\",\n selfvpc=newvpc\n)\n```\n\n### Use your self exist role\n\n> 2020/06/27 , you can use your self exist role assign to runner\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner\nfrom aws_cdk.aws_ec2 import Port, Peer\nfrom aws_cdk.aws_iam import ManagedPolicy, Role, ServicePrincipal\n\nrole = Role(self, \"runner-role\",\n assumed_by=ServicePrincipal(\"ec2.amazonaws.com\"),\n description=\"For Gitlab EC2 Runner Test Role\",\n role_name=\"TestRole\"\n)\n\nrunner = GitlabContainerRunner(stack, \"testing\",\n gitlabtoken=\"$GITLAB_TOKEN\",\n ec2iamrole=role\n)\nrunner.runner_role.add_managed_policy(\n ManagedPolicy.from_aws_managed_policy_name(\"AmazonS3ReadOnlyAccess\"))\n```\n\n### Custom Gitlab Runner EBS szie\n\n> 2020/08/22 , you can change you want ebs size.\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\nGitlabContainerRunner(stack, \"testing\",\n gitlabtoken=\"$GITLAB_TOKEN\",\n ebs_size=50\n)\n```\n\n### Control the number of runners with AutoScalingGroup\n\n> 2020/11/25 , you can set the number of runners.\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabRunnerAutoscaling\n\nGitlabRunnerAutoscaling(stack, \"testing\",\n gitlab_token=\"$GITLAB_TOKEN\",\n min_capacity=2,\n max_capacity=2\n)\n```\n\n### Support Spotfleet Gitlab Runner\n\n> 2020/08/27 , you can use spotfleet instance be your gitlab runner,\n> after create spotfleet instance will auto output instance id .thank [@pahud](https://github.com/pahud/cdk-spot-one) again ~~~\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner, BlockDuration\n\nrunner = GitlabContainerRunner(stack, \"testing\",\n gitlabtoken=\"GITLAB_TOKEN\",\n ec2type=\"t3.large\",\n block_duration=BlockDuration.ONE_HOUR,\n spot_fleet=True\n)\n# configure the expiration after 1 hours\nrunner.expire_after(Duration.hours(1))\n```\n\n> 2020/11/19, you setting job runtime bind host volumes.\n> see more https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersdocker-section\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner, BlockDuration\n\nrunner = GitlabContainerRunner(stack, \"testing\",\n gitlabtoken=\"GITLAB_TOKEN\",\n ec2type=\"t3.large\",\n docker_volumes=[{\n \"host_path\": \"/tmp/cahce\",\n \"container_path\": \"/tmp/cahce\"\n }\n ]\n)\n```\n\n> 2020/11/19, support runner auto unregister runner when cdk app destroy.\n\n# Note\n\n vs \n\n> About change instance type\n\nThis is before  ( included  )\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom aws_cdk.aws_ec2 import InstanceType, InstanceClass, InstanceSize\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\n# If want change instance type to t3.large .\nGitlabContainerRunner(self, \"runner-instance\",\n gitlabtoken=\"$GITLABTOKEN\",\n ec2type=InstanceType.of(InstanceClass.T3, InstanceSize.LARGE)\n)\n```\n\nThis is \n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nfrom cdk_gitlab_runner import GitlabContainerRunner\n\n# If want change instance type to t3.large .\nGitlabContainerRunner(self, \"runner-instance\",\n gitlabtoken=\"$GITLABTOKEN\",\n ec2type=\"t3.large\"\n)\n```\n\n## Wait about 6 mins , If success you will see your runner in that page .\n\n\n\n#### you can use tag `gitlab` , `runner` , `awscdk` ,\n\n## Example *`gitlab-ci.yaml`*\n\n[gitlab docs see more ...](https://docs.gitlab.com/ee/ci/yaml/README.html)\n\n```yaml\ndockerjob:\n image: docker:18.09-dind\n variables:\n tags:\n - runner\n - awscdk\n - gitlab\n variables:\n DOCKER_TLS_CERTDIR: \"\"\n before_script:\n - docker info\n script:\n - docker info;\n - echo 'test 123';\n - echo 'hello world 1228'\n```\n\n### If your want to debug you can go to aws console\n\n# `In your runner region !!!`\n\n## AWS Systems Manager > Session Manager > Start a session\n\n\n\n#### click your `runner` and click `start session`\n\n#### in the brower console in put `bash`\n\n```bash\n# become to root\nsudo -i\n\n# list runner container .\nroot# docker ps -a\n\n# modify gitlab-runner/config.toml\n\nroot# cd /home/ec2-user/.gitlab-runner/ && ls\nconfig.toml\n\n```\n\n## :clap: Supporters\n\n[](https://github.com/guan840912/cdk-gitlab-runner/stargazers)\n\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A Gitlab Runner JSII construct lib for AWS CDK",
"version": "1.77.11",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "c95c04dea4184d296f1250a9170de7d7",
"sha256": "94edd0be9d07dd2acbfb19a4492e4867d107d2a03d9dbd38bd63d9124df35643"
},
"downloads": -1,
"filename": "cdk_gitlab_runner-1.77.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c95c04dea4184d296f1250a9170de7d7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 69212,
"upload_time": "2021-01-18T02:05:58",
"upload_time_iso_8601": "2021-01-18T02:05:58.782786Z",
"url": "https://files.pythonhosted.org/packages/6e/82/44aaa60342645e8f4801ea19dfac358f823767de0db21e7c9e89101ee25d/cdk_gitlab_runner-1.77.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "6efacb92551dead95d9bea84b9cf7976",
"sha256": "0935af865d3d95aa49d2fe6b138fb4e1ce4078c8579a9504f1e51cd66d9a5ec4"
},
"downloads": -1,
"filename": "cdk-gitlab-runner-1.77.11.tar.gz",
"has_sig": false,
"md5_digest": "6efacb92551dead95d9bea84b9cf7976",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 72062,
"upload_time": "2021-01-18T02:06:00",
"upload_time_iso_8601": "2021-01-18T02:06:00.359160Z",
"url": "https://files.pythonhosted.org/packages/d8/c2/ec66564f249df893212d25bb96f8bc980f4b3511de8611fac51d6e3fc876/cdk-gitlab-runner-1.77.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-01-18 02:06:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": null,
"github_project": "guan840912",
"error": "Could not fetch GitHub repository",
"lcname": "cdk-gitlab-runner"
}