{"id":18623602,"url":"https://github.com/codica2/gitlab-aws-ecr","last_synced_at":"2026-04-16T08:38:27.735Z","repository":{"id":98303154,"uuid":"232597981","full_name":"codica2/gitlab-aws-ecr","owner":"codica2","description":"Autoscaling GitLab Runner on AWS with ECR authentication","archived":false,"fork":false,"pushed_at":"2020-01-08T15:45:32.000Z","size":198,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T05:24:53.835Z","etag":null,"topics":["aws","docker","docker-machine","ecr","gitlab","gitlab-runner"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codica2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-01-08T15:45:19.000Z","updated_at":"2020-01-09T07:05:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"198e8ec7-4e99-40ae-b9ea-aef7c90f3998","html_url":"https://github.com/codica2/gitlab-aws-ecr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fgitlab-aws-ecr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fgitlab-aws-ecr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fgitlab-aws-ecr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fgitlab-aws-ecr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codica2","download_url":"https://codeload.github.com/codica2/gitlab-aws-ecr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239418574,"owners_count":19635208,"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":["aws","docker","docker-machine","ecr","gitlab","gitlab-runner"],"created_at":"2024-11-07T04:25:18.120Z","updated_at":"2025-11-03T18:30:26.445Z","avatar_url":"https://github.com/codica2.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eAutoscaling GitLab Runner on AWS with ECR authentication\u003c/h1\u003e\n\n![](gitlab-docker-aws.png)\n\nIf you want to have a cost-effective and scalable solution for your CI/CD, it can be useful to use Gitlab Runner with its autoscaling feature.\nIn this example, we'll configure Gitlab Runner in AWS that will serve as the bastion host with docker-machine spawning spot instances. Also there is ECR authentication stage (in this case we can pull our images from ECR).\n\n## Prerequisites\n\nWe will use such tools as:\n* [Gitlab Runner](https://docs.gitlab.com/runner/)\n* [Amazon’s EC2 Spot Instances](https://aws.amazon.com/ec2/spot/)\n* [Docker Machine](https://docs.docker.com/machine/drivers/aws/)\n\n## Prepare the bastion instance\n\nThe first step is to install GitLab Runner in an EC2 instance that will serve as the bastion that spawns new machines. This doesn’t have to be a powerful machine since it will not run any jobs itself, but a t2.micro instance will do. This machine will be a dedicated host since we need it always up and running, thus it will be the only standard cost.\n\nSecurity Group for Bastion host must contain ingress rule for 2376 port\n\nTo create EC2 instance (Ubuntu HVM) with all depencies installed - paste this into User Data\n\n```bash\n#!/bin/bash\nsudo apt-get update\nsudo apt-get upgrade\n\n#installing docker depencies\nsudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -\nadd-apt-repository \\\n   \"deb [arch=amd64] https://download.docker.com/linux/ubuntu \\\n   $(lsb_release -cs) \\\n   stable\"\nsudo apt-get update\n\n#installing docker with user rights\nsudo apt-get install -y docker-ce\nsudo usermod -aG docker ubuntu\n\n#installing awsutils with Go laguage\nsudo apt-get install awscli\nsudo apt-get install golang-go\n\n#export Go $PATH\nexport GOPATH=$HOME/go\nexport PATH=$PATH:$GOPATH/bin\n\n#installing docker-compose + machine\ncurl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose\nchmod +x /usr/local/bin/docker-compose\nbase=https://github.com/docker/machine/releases/download/v0.16.0 \u0026\u0026\n  curl -L $base/docker-machine-$(uname -s)-$(uname -m) \u003e/tmp/docker-machine \u0026\u0026\n  sudo mv /tmp/docker-machine /usr/local/bin/docker-machine \u0026\u0026\n  chmod +x /usr/local/bin/docker-machine\n\n#installing gitlab-runner\ncurl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash\nsudo apt-get install gitlab-runner\n```\n\n## Configure GitLab Runner\n\nNow go to your bastion host and run `sudo gitlab-runner register`\n\nThis command will generate example `config.toml` file with token we needed for our runner.\n\nThen run `sudo vim /etc/gitlab-runner/config.toml` and copy generated token to buffer. Then paste it into your new config which is given below.\n\n```toml\nconcurrent = 10\ncheck_interval = 0\n\n[[runners]]\n  name = \"%PROJECT_NAME% Runner\"\n  limit = 3\n  url = \"https://gitlab.codica.com/\"\n  token = \"__TOKEN FROM PREVIOUS config.toml__\"\n  executor = \"docker+machine\"\n  [runners.docker]\n    tls_verify = false\n    image = \"alpine\"\n    privileged = true\n    disable_cache = true\n    volumes = [\"/var/run/docker.sock:/var/run/docker.sock\", \"/cache\"]\n    shm_size = 0\n  [runners.cache]\n    Type = \"s3\"\n    Path = \"cache\"\n    [runners.cache.s3]\n      ServerAddress = \"s3.amazonaws.com\"\n      AccessKey = \"XXXXXXXXX\"\n      SecretKey = \"XXXXXXXXX\"\n      BucketName = \"XXXXXXXXX\"\n      BucketLocation = \"eu-central-1\"\n  [runners.machine]\n    IdleCount = 2\n    IdleTime = 300\n    MaxBuilds = 10\n    MachineDriver = \"amazonec2\"\n    MachineName = \"gitlab-docker-machine-%s\"\n    MachineOptions = [\"amazonec2-access-key=XXXXXXXXX\", \"amazonec2-secret-key=XXXXXXXXX\", \"amazonec2-region=eu-central-1\", \"amazonec2-vpc-id=XXXXXXXXX\", \"amazonec2-subnet-id=XXXXXXXXX\", \"amazonec2-zone=%bastion host zone%\", \"amazonec2-tags=runner-manager-name,gitlab-aws-autoscaler,gitlab,true,gitlab-runner-autoscale,true\", \"amazonec2-security-group=%Your SG name%\", \"amazonec2-instance-type=t3.medium\", \"amazonec2-request-spot-instance=true\", \"amazonec2-spot-price=0.05\"]\n    OffPeakPeriods = [\"* * 0-8,22-23 * * mon-fri *\", \"* * * * * sat,sun *\"]\n    OffPeakTimezone = \"Europe/Kiev\"\n    OffPeakIdleCount = 0\n    OffPeakIdleTime = 1200\n```\n\n## ECR login stage\n\nMake sure you are under root user:  `sudo su`\n\nThe next step is to configure your AWS account: `aws configure`\n\nThen type: `crontab -e` and paste next string to the end of crontab:\n\n```bash\n0 */6 * * * RESULT=$(aws ecr get-login --no-include-email --region eu-central-1) \u0026\u0026 $RESULT \u003e/dev/null 2\u003e\u00261\n```\n\nBy default ECR Credential Helper is used for ECR authorization. [Here](https://github.com/awslabs/amazon-ecr-credential-helper) you can find detailed instructions for authorization in ECR.\n\n## License\n\nCopyright © 2015-2020 Codica. It is released under the [MIT License](https://opensource.org/licenses/MIT).\n\n## About Codica\n\n[![Codica logo](https://www.codica.com/assets/images/logo/logo.svg)](https://www.codica.com)\n\nThe names and logos for Codica are trademarks of Codica.\n\nWe love open source software! See [our other projects](https://github.com/codica2) or [hire us](https://www.codica.com/) to design, develop, and grow your product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fgitlab-aws-ecr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodica2%2Fgitlab-aws-ecr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fgitlab-aws-ecr/lists"}